Merge pull request #137 from NicolasConstant/topic_handle-gone-followers
added user is gone exception
This commit is contained in:
commit
d0dd317723
3 changed files with 35 additions and 14 deletions
|
@ -11,7 +11,6 @@ using BirdsiteLive.ActivityPub.Models;
|
|||
using BirdsiteLive.Common.Settings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Org.BouncyCastle.Bcpg;
|
||||
|
||||
namespace BirdsiteLive.Domain
|
||||
{
|
||||
|
@ -45,6 +44,12 @@ namespace BirdsiteLive.Domain
|
|||
var httpClient = _httpClientFactory.CreateClient();
|
||||
httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json");
|
||||
var result = await httpClient.GetAsync(objectId);
|
||||
|
||||
if (result.StatusCode == HttpStatusCode.Gone)
|
||||
throw new UserIsGoneException();
|
||||
|
||||
result.EnsureSuccessStatusCode();
|
||||
|
||||
var content = await result.Content.ReadAsStringAsync();
|
||||
|
||||
var actor = JsonConvert.DeserializeObject<Actor>(content);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
using System;
|
||||
|
||||
namespace BirdsiteLive.Domain
|
||||
{
|
||||
public class UserIsGoneException : Exception
|
||||
{
|
||||
}
|
||||
}
|
|
@ -183,33 +183,41 @@ namespace BirdsiteLive.Controllers
|
|||
switch (activity?.type)
|
||||
{
|
||||
case "Follow":
|
||||
{
|
||||
var succeeded = await _userService.FollowRequestedAsync(signature, r.Method, r.Path,
|
||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers), activity as ActivityFollow, body);
|
||||
if (succeeded) return Accepted();
|
||||
else return Unauthorized();
|
||||
}
|
||||
{
|
||||
var succeeded = await _userService.FollowRequestedAsync(signature, r.Method, r.Path,
|
||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers),
|
||||
activity as ActivityFollow, body);
|
||||
if (succeeded) return Accepted();
|
||||
else return Unauthorized();
|
||||
}
|
||||
case "Undo":
|
||||
if (activity is ActivityUndoFollow)
|
||||
{
|
||||
var succeeded = await _userService.UndoFollowRequestedAsync(signature, r.Method, r.Path,
|
||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers), activity as ActivityUndoFollow, body);
|
||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers),
|
||||
activity as ActivityUndoFollow, body);
|
||||
if (succeeded) return Accepted();
|
||||
else return Unauthorized();
|
||||
}
|
||||
|
||||
return Accepted();
|
||||
case "Delete":
|
||||
{
|
||||
var succeeded = await _userService.DeleteRequestedAsync(signature, r.Method, r.Path,
|
||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers), activity as ActivityDelete, body);
|
||||
if (succeeded) return Accepted();
|
||||
else return Unauthorized();
|
||||
}
|
||||
{
|
||||
var succeeded = await _userService.DeleteRequestedAsync(signature, r.Method, r.Path,
|
||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers),
|
||||
activity as ActivityDelete, body);
|
||||
if (succeeded) return Accepted();
|
||||
else return Unauthorized();
|
||||
}
|
||||
default:
|
||||
return Accepted();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (UserIsGoneException)
|
||||
{
|
||||
return Accepted();
|
||||
}
|
||||
catch (UserNotFoundException)
|
||||
{
|
||||
return NotFound();
|
||||
|
|
Reference in a new issue