cloutier--bird.makeup/src/BirdsiteLive.Moderation/Actions/RemoveFollowerAction.cs

51 lines
1.7 KiB
C#
Raw Normal View History

2021-02-12 00:31:00 -05:00
using System;
using System.Linq;
using System.Threading.Tasks;
2021-02-12 00:31:00 -05:00
using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Converters;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.DAL.Models;
2021-02-12 00:31:00 -05:00
using BirdsiteLive.Domain;
namespace BirdsiteLive.Moderation.Actions
{
public interface IRemoveFollowerAction
{
Task ProcessAsync(Follower follower);
}
public class RemoveFollowerAction : IRemoveFollowerAction
{
private readonly IFollowersDal _followersDal;
private readonly ITwitterUserDal _twitterUserDal;
2021-02-14 01:51:54 -05:00
private readonly IRejectAllFollowingsAction _rejectAllFollowingsAction;
#region Ctor
2021-02-14 01:51:54 -05:00
public RemoveFollowerAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal, IRejectAllFollowingsAction rejectAllFollowingsAction)
{
_followersDal = followersDal;
_twitterUserDal = twitterUserDal;
2021-02-14 01:51:54 -05:00
_rejectAllFollowingsAction = rejectAllFollowingsAction;
}
#endregion
public async Task ProcessAsync(Follower follower)
{
// Perform undo following to user instance
2021-02-14 01:51:54 -05:00
await _rejectAllFollowingsAction.ProcessAsync(follower);
// Remove twitter users if no more followers
var followings = follower.Followings;
foreach (var following in followings)
{
var followers = await _followersDal.GetFollowersAsync(following);
if (followers.Length == 1 && followers.First().Id == follower.Id)
await _twitterUserDal.DeleteTwitterUserAsync(following);
}
// Remove follower from DB
await _followersDal.DeleteFollowerAsync(follower.Id);
}
}
}