diff --git a/src/BirdsiteLive.Domain/BusinessUseCases/ProcessDeleteUser.cs b/src/BirdsiteLive.Domain/BusinessUseCases/ProcessDeleteUser.cs index a35b6c8..a36c963 100644 --- a/src/BirdsiteLive.Domain/BusinessUseCases/ProcessDeleteUser.cs +++ b/src/BirdsiteLive.Domain/BusinessUseCases/ProcessDeleteUser.cs @@ -9,6 +9,7 @@ namespace BirdsiteLive.Domain.BusinessUseCases { Task ExecuteAsync(Follower follower); Task ExecuteAsync(string followerUsername, string followerDomain); + Task ExecuteAsync(string actorId); } public class ProcessDeleteUser : IProcessDeleteUser @@ -33,6 +34,15 @@ namespace BirdsiteLive.Domain.BusinessUseCases 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) { // Remove twitter users if no more followers diff --git a/src/BirdsiteLive.Domain/UserService.cs b/src/BirdsiteLive.Domain/UserService.cs index 6f88543..ed31c62 100644 --- a/src/BirdsiteLive.Domain/UserService.cs +++ b/src/BirdsiteLive.Domain/UserService.cs @@ -280,15 +280,21 @@ namespace BirdsiteLive.Domain public async Task DeleteRequestedAsync(string signature, string method, string path, string queryString, Dictionary requestHeaders, ActivityDelete activity, string body) { - // Validate - var sigValidation = await ValidateSignature(activity.actor, signature, method, path, queryString, requestHeaders, body); - if (!sigValidation.SignatureIsValidated) return false; + if (activity.apObject is string apObject) + { + if (!string.Equals(activity.actor.Trim(), apObject.Trim(), StringComparison.InvariantCultureIgnoreCase)) return true; - // Remove user and followings - var followerUserName = SigValidationResultExtractor.GetUserName(sigValidation); - var followerHost = SigValidationResultExtractor.GetHost(sigValidation); + try + { + // 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; } diff --git a/src/BirdsiteLive/Controllers/InboxController.cs b/src/BirdsiteLive/Controllers/InboxController.cs index f92a0a6..57825af 100644 --- a/src/BirdsiteLive/Controllers/InboxController.cs +++ b/src/BirdsiteLive/Controllers/InboxController.cs @@ -49,14 +49,15 @@ namespace BirdsiteLive.Controllers case "Delete": { 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(); else return Unauthorized(); } } } } - catch (FollowerIsGoneException) { } //TODO: check if user in DB + catch (FollowerIsGoneException) { } return Accepted(); } diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs index db2f9f7..c93ad5e 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs @@ -82,6 +82,21 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers } } + public async Task 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(query, new { actorId })).FirstOrDefault(); + return Convert(result); + } + } + public async Task GetFollowersAsync(int followedUserId) { if (followedUserId == default) throw new ArgumentException("followedUserId"); diff --git a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs index fe87b28..cb97b8e 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs @@ -7,6 +7,7 @@ namespace BirdsiteLive.DAL.Contracts public interface IFollowersDal { Task GetFollowerAsync(string acct, string host); + Task GetFollowerAsync(string actorId); Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null, Dictionary followingSyncStatus = null); Task GetFollowersAsync(int followedUserId);