mirror of
https://github.com/NicolasConstant/BirdsiteLive
synced 2025-06-05 21:49:16 +02:00
better Delete Actor logic
This commit is contained in:
@@ -9,6 +9,7 @@ namespace BirdsiteLive.Domain.BusinessUseCases
|
|||||||
{
|
{
|
||||||
Task ExecuteAsync(Follower follower);
|
Task ExecuteAsync(Follower follower);
|
||||||
Task ExecuteAsync(string followerUsername, string followerDomain);
|
Task ExecuteAsync(string followerUsername, string followerDomain);
|
||||||
|
Task ExecuteAsync(string actorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProcessDeleteUser : IProcessDeleteUser
|
public class ProcessDeleteUser : IProcessDeleteUser
|
||||||
@@ -33,6 +34,15 @@ namespace BirdsiteLive.Domain.BusinessUseCases
|
|||||||
await ExecuteAsync(follower);
|
await ExecuteAsync(follower);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task ExecuteAsync(string actorId)
|
||||||
|
{
|
||||||
|
// Get Follower and Twitter Users
|
||||||
|
var follower = await _followersDal.GetFollowerAsync(actorId);
|
||||||
|
if (follower == null) return;
|
||||||
|
|
||||||
|
await ExecuteAsync(follower);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task ExecuteAsync(Follower follower)
|
public async Task ExecuteAsync(Follower follower)
|
||||||
{
|
{
|
||||||
// Remove twitter users if no more followers
|
// Remove twitter users if no more followers
|
||||||
|
@@ -280,15 +280,21 @@ namespace BirdsiteLive.Domain
|
|||||||
public async Task<bool> DeleteRequestedAsync(string signature, string method, string path, string queryString, Dictionary<string, string> requestHeaders,
|
public async Task<bool> DeleteRequestedAsync(string signature, string method, string path, string queryString, Dictionary<string, string> requestHeaders,
|
||||||
ActivityDelete activity, string body)
|
ActivityDelete activity, string body)
|
||||||
{
|
{
|
||||||
// Validate
|
if (activity.apObject is string apObject)
|
||||||
var sigValidation = await ValidateSignature(activity.actor, signature, method, path, queryString, requestHeaders, body);
|
{
|
||||||
if (!sigValidation.SignatureIsValidated) return false;
|
if (!string.Equals(activity.actor.Trim(), apObject.Trim(), StringComparison.InvariantCultureIgnoreCase)) return true;
|
||||||
|
|
||||||
// Remove user and followings
|
try
|
||||||
var followerUserName = SigValidationResultExtractor.GetUserName(sigValidation);
|
{
|
||||||
var followerHost = SigValidationResultExtractor.GetHost(sigValidation);
|
// Validate
|
||||||
|
var sigValidation = await ValidateSignature(activity.actor, signature, method, path, queryString, requestHeaders, body);
|
||||||
|
if (!sigValidation.SignatureIsValidated) return false;
|
||||||
|
}
|
||||||
|
catch (FollowerIsGoneException){}
|
||||||
|
|
||||||
await _processDeleteUser.ExecuteAsync(followerUserName, followerHost);
|
// Remove user and followings
|
||||||
|
await _processDeleteUser.ExecuteAsync(activity.actor.Trim());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -49,14 +49,15 @@ namespace BirdsiteLive.Controllers
|
|||||||
case "Delete":
|
case "Delete":
|
||||||
{
|
{
|
||||||
var succeeded = await _userService.DeleteRequestedAsync(signature, r.Method, r.Path,
|
var succeeded = await _userService.DeleteRequestedAsync(signature, r.Method, r.Path,
|
||||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers), activity as ActivityDelete, body);
|
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers),
|
||||||
|
activity as ActivityDelete, body);
|
||||||
if (succeeded) return Accepted();
|
if (succeeded) return Accepted();
|
||||||
else return Unauthorized();
|
else return Unauthorized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (FollowerIsGoneException) { } //TODO: check if user in DB
|
catch (FollowerIsGoneException) { }
|
||||||
|
|
||||||
return Accepted();
|
return Accepted();
|
||||||
}
|
}
|
||||||
|
@@ -82,6 +82,21 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Follower> GetFollowerAsync(string actorId)
|
||||||
|
{
|
||||||
|
var query = $"SELECT * FROM {_settings.FollowersTableName} WHERE actorid = @actorid";
|
||||||
|
|
||||||
|
actorId = actorId.ToLowerInvariant().Trim();
|
||||||
|
|
||||||
|
using (var dbConnection = Connection)
|
||||||
|
{
|
||||||
|
dbConnection.Open();
|
||||||
|
|
||||||
|
var result = (await dbConnection.QueryAsync<SerializedFollower>(query, new { actorId })).FirstOrDefault();
|
||||||
|
return Convert(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Follower[]> GetFollowersAsync(int followedUserId)
|
public async Task<Follower[]> GetFollowersAsync(int followedUserId)
|
||||||
{
|
{
|
||||||
if (followedUserId == default) throw new ArgumentException("followedUserId");
|
if (followedUserId == default) throw new ArgumentException("followedUserId");
|
||||||
|
@@ -7,6 +7,7 @@ namespace BirdsiteLive.DAL.Contracts
|
|||||||
public interface IFollowersDal
|
public interface IFollowersDal
|
||||||
{
|
{
|
||||||
Task<Follower> GetFollowerAsync(string acct, string host);
|
Task<Follower> GetFollowerAsync(string acct, string host);
|
||||||
|
Task<Follower> GetFollowerAsync(string actorId);
|
||||||
Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null,
|
Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null,
|
||||||
Dictionary<int, long> followingSyncStatus = null);
|
Dictionary<int, long> followingSyncStatus = null);
|
||||||
Task<Follower[]> GetFollowersAsync(int followedUserId);
|
Task<Follower[]> GetFollowersAsync(int followedUserId);
|
||||||
|
Reference in New Issue
Block a user