diff --git a/src/BirdsiteLive.Moderation/Actions/RejectAllFollowingsAction.cs b/src/BirdsiteLive.Moderation/Actions/RejectAllFollowingsAction.cs new file mode 100644 index 0000000..9a1b1bc --- /dev/null +++ b/src/BirdsiteLive.Moderation/Actions/RejectAllFollowingsAction.cs @@ -0,0 +1,52 @@ +using System; +using System.Threading.Tasks; +using BirdsiteLive.ActivityPub; +using BirdsiteLive.ActivityPub.Converters; +using BirdsiteLive.Common.Settings; +using BirdsiteLive.DAL.Contracts; +using BirdsiteLive.DAL.Models; +using BirdsiteLive.Domain; + +namespace BirdsiteLive.Moderation.Actions +{ + public interface IRejectAllFollowingsAction + { + Task ProcessAsync(Follower follower); + } + + public class RejectAllFollowingsAction : IRejectAllFollowingsAction + { + private readonly ITwitterUserDal _twitterUserDal; + private readonly IUserService _userService; + private readonly InstanceSettings _instanceSettings; + + #region Ctor + public RejectAllFollowingsAction(ITwitterUserDal twitterUserDal, IUserService userService, InstanceSettings instanceSettings) + { + _twitterUserDal = twitterUserDal; + _userService = userService; + _instanceSettings = instanceSettings; + } + #endregion + + public async Task ProcessAsync(Follower follower) + { + foreach (var following in follower.Followings) + { + try + { + var f = await _twitterUserDal.GetTwitterUserAsync(following); + var activityFollowing = new ActivityFollow + { + type = "Follow", + actor = follower.ActorId, + apObject = UrlFactory.GetActorUrl(_instanceSettings.Domain, f.Acct) + }; + + await _userService.SendRejectFollowAsync(activityFollowing, follower.Host); + } + catch (Exception) { } + } + } + } +} \ No newline at end of file diff --git a/src/BirdsiteLive.Moderation/Actions/RejectFollowingAction.cs b/src/BirdsiteLive.Moderation/Actions/RejectFollowingAction.cs new file mode 100644 index 0000000..c5963eb --- /dev/null +++ b/src/BirdsiteLive.Moderation/Actions/RejectFollowingAction.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading.Tasks; +using BirdsiteLive.ActivityPub; +using BirdsiteLive.ActivityPub.Converters; +using BirdsiteLive.Common.Settings; +using BirdsiteLive.DAL.Models; +using BirdsiteLive.Domain; + +namespace BirdsiteLive.Moderation.Actions +{ + public interface IRejectFollowingAction + { + Task ProcessAsync(Follower follower, SyncTwitterUser twitterUser); + } + + public class RejectFollowingAction : IRejectFollowingAction + { + private readonly IUserService _userService; + private readonly InstanceSettings _instanceSettings; + + #region Ctor + public RejectFollowingAction(IUserService userService, InstanceSettings instanceSettings) + { + _userService = userService; + _instanceSettings = instanceSettings; + } + #endregion + + public async Task ProcessAsync(Follower follower, SyncTwitterUser twitterUser) + { + try + { + var activityFollowing = new ActivityFollow + { + type = "Follow", + actor = follower.ActorId, + apObject = UrlFactory.GetActorUrl(_instanceSettings.Domain, twitterUser.Acct) + }; + await _userService.SendRejectFollowAsync(activityFollowing, follower.Host); + } + catch (Exception) { } + } + } +} \ No newline at end of file diff --git a/src/BirdsiteLive.Moderation/Actions/RemoveFollowerAction.cs b/src/BirdsiteLive.Moderation/Actions/RemoveFollowerAction.cs index cf1d454..8ab3132 100644 --- a/src/BirdsiteLive.Moderation/Actions/RemoveFollowerAction.cs +++ b/src/BirdsiteLive.Moderation/Actions/RemoveFollowerAction.cs @@ -19,23 +19,21 @@ namespace BirdsiteLive.Moderation.Actions { private readonly IFollowersDal _followersDal; private readonly ITwitterUserDal _twitterUserDal; - private readonly IUserService _userService; - private readonly InstanceSettings _instanceSettings; + private readonly IRejectAllFollowingsAction _rejectAllFollowingsAction; #region Ctor - public RemoveFollowerAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal, IUserService userService, InstanceSettings instanceSettings) + public RemoveFollowerAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal, IRejectAllFollowingsAction rejectAllFollowingsAction) { _followersDal = followersDal; _twitterUserDal = twitterUserDal; - _userService = userService; - _instanceSettings = instanceSettings; + _rejectAllFollowingsAction = rejectAllFollowingsAction; } #endregion public async Task ProcessAsync(Follower follower) { // Perform undo following to user instance - await RejectAllFollowingsAsync(follower); + await _rejectAllFollowingsAction.ProcessAsync(follower); // Remove twitter users if no more followers var followings = follower.Followings; @@ -49,25 +47,5 @@ namespace BirdsiteLive.Moderation.Actions // Remove follower from DB await _followersDal.DeleteFollowerAsync(follower.Id); } - - private async Task RejectAllFollowingsAsync(Follower follower) - { - foreach (var following in follower.Followings) - { - try - { - var f = await _twitterUserDal.GetTwitterUserAsync(following); - var activityFollowing = new ActivityFollow - { - type = "Follow", - actor = follower.ActorId, - apObject = UrlFactory.GetActorUrl(_instanceSettings.Domain, f.Acct) - }; - - await _userService.SendRejectFollowAsync(activityFollowing, follower.Host); - } - catch (Exception) { } - } - } } } \ No newline at end of file diff --git a/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs b/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs index a689401..1babf23 100644 --- a/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs +++ b/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs @@ -19,16 +19,14 @@ namespace BirdsiteLive.Moderation.Actions { private readonly IFollowersDal _followersDal; private readonly ITwitterUserDal _twitterUserDal; - private readonly IUserService _userService; - private readonly InstanceSettings _instanceSettings; + private readonly IRejectFollowingAction _rejectFollowingAction; #region Ctor - public RemoveTwitterAccountAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal, InstanceSettings instanceSettings, IUserService userService) + public RemoveTwitterAccountAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal, IRejectFollowingAction rejectFollowingAction) { _followersDal = followersDal; _twitterUserDal = twitterUserDal; - _instanceSettings = instanceSettings; - _userService = userService; + _rejectFollowingAction = rejectFollowingAction; } #endregion @@ -42,7 +40,7 @@ namespace BirdsiteLive.Moderation.Actions foreach (var follower in followers) { // Perform undo following to user instance - await RejectFollowingAsync(follower, twitterUser); + await _rejectFollowingAction.ProcessAsync(follower, twitterUser); // Remove following from DB if (follower.Followings.Contains(twitterUserId)) @@ -60,20 +58,5 @@ namespace BirdsiteLive.Moderation.Actions // Remove twitter user await _twitterUserDal.DeleteTwitterUserAsync(twitterUser.Acct); } - - private async Task RejectFollowingAsync(Follower follower, SyncTwitterUser twitterUser) - { - try - { - var activityFollowing = new ActivityFollow - { - type = "Follow", - actor = follower.ActorId, - apObject = UrlFactory.GetActorUrl(_instanceSettings.Domain, twitterUser.Acct) - }; - await _userService.SendRejectFollowAsync(activityFollowing, follower.Host); - } - catch (Exception) { } - } } } \ No newline at end of file