added AP unfollow + tests + db update
This commit is contained in:
parent
4b1aa7aa5c
commit
eaae2f1f47
12 changed files with 126 additions and 35 deletions
|
@ -5,7 +5,7 @@ namespace BirdsiteLive.Domain.BusinessUseCases
|
||||||
{
|
{
|
||||||
public interface IProcessFollowUser
|
public interface IProcessFollowUser
|
||||||
{
|
{
|
||||||
Task ExecuteAsync(string followerUsername, string followerDomain, string twitterUsername, string followerInbox, string sharedInbox);
|
Task ExecuteAsync(string followerUsername, string followerDomain, string twitterUsername, string followerInbox, string sharedInbox, string followerActorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProcessFollowUser : IProcessFollowUser
|
public class ProcessFollowUser : IProcessFollowUser
|
||||||
|
@ -21,13 +21,13 @@ namespace BirdsiteLive.Domain.BusinessUseCases
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public async Task ExecuteAsync(string followerUsername, string followerDomain, string twitterUsername, string followerInbox, string sharedInbox)
|
public async Task ExecuteAsync(string followerUsername, string followerDomain, string twitterUsername, string followerInbox, string sharedInbox, string followerActorId)
|
||||||
{
|
{
|
||||||
// Get Follower and Twitter Users
|
// Get Follower and Twitter Users
|
||||||
var follower = await _followerDal.GetFollowerAsync(followerUsername, followerDomain);
|
var follower = await _followerDal.GetFollowerAsync(followerUsername, followerDomain);
|
||||||
if (follower == null)
|
if (follower == null)
|
||||||
{
|
{
|
||||||
await _followerDal.CreateFollowerAsync(followerUsername, followerDomain, followerInbox, sharedInbox);
|
await _followerDal.CreateFollowerAsync(followerUsername, followerDomain, followerInbox, sharedInbox, followerActorId);
|
||||||
follower = await _followerDal.GetFollowerAsync(followerUsername, followerDomain);
|
follower = await _followerDal.GetFollowerAsync(followerUsername, followerDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,7 @@ namespace BirdsiteLive.Domain
|
||||||
if (!user.Protected)
|
if (!user.Protected)
|
||||||
{
|
{
|
||||||
// Execute
|
// Execute
|
||||||
await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox);
|
await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox, activity.actor);
|
||||||
|
|
||||||
return await SendAcceptFollowAsync(activity, followerHost);
|
return await SendAcceptFollowAsync(activity, followerHost);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BirdsiteLive.ActivityPub;
|
||||||
|
using BirdsiteLive.ActivityPub.Converters;
|
||||||
|
using BirdsiteLive.Common.Settings;
|
||||||
using BirdsiteLive.DAL.Contracts;
|
using BirdsiteLive.DAL.Contracts;
|
||||||
using BirdsiteLive.DAL.Models;
|
using BirdsiteLive.DAL.Models;
|
||||||
|
using BirdsiteLive.Domain;
|
||||||
|
|
||||||
namespace BirdsiteLive.Moderation.Actions
|
namespace BirdsiteLive.Moderation.Actions
|
||||||
{
|
{
|
||||||
|
@ -14,19 +19,23 @@ namespace BirdsiteLive.Moderation.Actions
|
||||||
{
|
{
|
||||||
private readonly IFollowersDal _followersDal;
|
private readonly IFollowersDal _followersDal;
|
||||||
private readonly ITwitterUserDal _twitterUserDal;
|
private readonly ITwitterUserDal _twitterUserDal;
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
private readonly InstanceSettings _instanceSettings;
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
public RemoveFollowerAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal)
|
public RemoveFollowerAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal, IUserService userService, InstanceSettings instanceSettings)
|
||||||
{
|
{
|
||||||
_followersDal = followersDal;
|
_followersDal = followersDal;
|
||||||
_twitterUserDal = twitterUserDal;
|
_twitterUserDal = twitterUserDal;
|
||||||
|
_userService = userService;
|
||||||
|
_instanceSettings = instanceSettings;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public async Task ProcessAsync(Follower follower)
|
public async Task ProcessAsync(Follower follower)
|
||||||
{
|
{
|
||||||
// Perform undo following to user instance
|
// Perform undo following to user instance
|
||||||
// TODO: Insert ActivityPub magic here
|
await RejectAllFollowingsAsync(follower);
|
||||||
|
|
||||||
// Remove twitter users if no more followers
|
// Remove twitter users if no more followers
|
||||||
var followings = follower.Followings;
|
var followings = follower.Followings;
|
||||||
|
@ -40,5 +49,25 @@ namespace BirdsiteLive.Moderation.Actions
|
||||||
// Remove follower from DB
|
// Remove follower from DB
|
||||||
await _followersDal.DeleteFollowerAsync(follower.Id);
|
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) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,12 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BirdsiteLive.ActivityPub;
|
||||||
|
using BirdsiteLive.ActivityPub.Converters;
|
||||||
|
using BirdsiteLive.Common.Settings;
|
||||||
using BirdsiteLive.DAL.Contracts;
|
using BirdsiteLive.DAL.Contracts;
|
||||||
using BirdsiteLive.DAL.Models;
|
using BirdsiteLive.DAL.Models;
|
||||||
|
using BirdsiteLive.Domain;
|
||||||
|
|
||||||
namespace BirdsiteLive.Moderation.Actions
|
namespace BirdsiteLive.Moderation.Actions
|
||||||
{
|
{
|
||||||
|
@ -14,12 +19,16 @@ namespace BirdsiteLive.Moderation.Actions
|
||||||
{
|
{
|
||||||
private readonly IFollowersDal _followersDal;
|
private readonly IFollowersDal _followersDal;
|
||||||
private readonly ITwitterUserDal _twitterUserDal;
|
private readonly ITwitterUserDal _twitterUserDal;
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
private readonly InstanceSettings _instanceSettings;
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
public RemoveTwitterAccountAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal)
|
public RemoveTwitterAccountAction(IFollowersDal followersDal, ITwitterUserDal twitterUserDal, InstanceSettings instanceSettings, IUserService userService)
|
||||||
{
|
{
|
||||||
_followersDal = followersDal;
|
_followersDal = followersDal;
|
||||||
_twitterUserDal = twitterUserDal;
|
_twitterUserDal = twitterUserDal;
|
||||||
|
_instanceSettings = instanceSettings;
|
||||||
|
_userService = userService;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -33,7 +42,7 @@ namespace BirdsiteLive.Moderation.Actions
|
||||||
foreach (var follower in followers)
|
foreach (var follower in followers)
|
||||||
{
|
{
|
||||||
// Perform undo following to user instance
|
// Perform undo following to user instance
|
||||||
// TODO: Insert ActivityPub magic here
|
await RejectFollowingAsync(follower, twitterUser);
|
||||||
|
|
||||||
// Remove following from DB
|
// Remove following from DB
|
||||||
if (follower.Followings.Contains(twitterUserId))
|
if (follower.Followings.Contains(twitterUserId))
|
||||||
|
@ -51,5 +60,20 @@ namespace BirdsiteLive.Moderation.Actions
|
||||||
// Remove twitter user
|
// Remove twitter user
|
||||||
await _twitterUserDal.DeleteTwitterUserAsync(twitterUser.Acct);
|
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) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
||||||
public class DbInitializerPostgresDal : PostgresBase, IDbInitializerDal
|
public class DbInitializerPostgresDal : PostgresBase, IDbInitializerDal
|
||||||
{
|
{
|
||||||
private readonly PostgresTools _tools;
|
private readonly PostgresTools _tools;
|
||||||
private readonly Version _currentVersion = new Version(2, 0);
|
private readonly Version _currentVersion = new Version(2, 1);
|
||||||
private const string DbVersionType = "db-version";
|
private const string DbVersionType = "db-version";
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
|
@ -131,7 +131,8 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
||||||
{
|
{
|
||||||
return new[]
|
return new[]
|
||||||
{
|
{
|
||||||
new Tuple<Version, Version>(new Version(1,0), new Version(2,0))
|
new Tuple<Version, Version>(new Version(1,0), new Version(2,0)),
|
||||||
|
new Tuple<Version, Version>(new Version(2,0), new Version(2,1))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,14 +145,21 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
||||||
|
|
||||||
var addIndex = $@"CREATE INDEX IF NOT EXISTS lastsync_twitteruser ON {_settings.TwitterUserTableName}(lastSync)";
|
var addIndex = $@"CREATE INDEX IF NOT EXISTS lastsync_twitteruser ON {_settings.TwitterUserTableName}(lastSync)";
|
||||||
await _tools.ExecuteRequestAsync(addIndex);
|
await _tools.ExecuteRequestAsync(addIndex);
|
||||||
|
}
|
||||||
|
else if (from == new Version(2, 0) && to == new Version(2, 1))
|
||||||
|
{
|
||||||
|
var addActorId = $@"ALTER TABLE {_settings.FollowersTableName} ADD actorId VARCHAR(2048)";
|
||||||
|
await _tools.ExecuteRequestAsync(addActorId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
await UpdateDbVersionAsync(to);
|
await UpdateDbVersionAsync(to);
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task UpdateDbVersionAsync(Version newVersion)
|
private async Task UpdateDbVersionAsync(Version newVersion)
|
||||||
{
|
{
|
||||||
using (var dbConnection = Connection)
|
using (var dbConnection = Connection)
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public async Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, int[] followings = null, Dictionary<int, long> followingSyncStatus = null)
|
public async Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null, Dictionary<int, long> followingSyncStatus = null)
|
||||||
{
|
{
|
||||||
if(followings == null) followings = new int[0];
|
if(followings == null) followings = new int[0];
|
||||||
if(followingSyncStatus == null) followingSyncStatus = new Dictionary<int, long>();
|
if(followingSyncStatus == null) followingSyncStatus = new Dictionary<int, long>();
|
||||||
|
@ -35,8 +35,8 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
||||||
dbConnection.Open();
|
dbConnection.Open();
|
||||||
|
|
||||||
await dbConnection.ExecuteAsync(
|
await dbConnection.ExecuteAsync(
|
||||||
$"INSERT INTO {_settings.FollowersTableName} (acct,host,inboxRoute,sharedInboxRoute,followings,followingsSyncStatus) VALUES(@acct,@host,@inboxRoute,@sharedInboxRoute,@followings,CAST(@followingsSyncStatus as json))",
|
$"INSERT INTO {_settings.FollowersTableName} (acct,host,inboxRoute,sharedInboxRoute,followings,followingsSyncStatus,actorId) VALUES(@acct,@host,@inboxRoute,@sharedInboxRoute,@followings,CAST(@followingsSyncStatus as json),@actorId)",
|
||||||
new { acct, host, inboxRoute, sharedInboxRoute, followings, followingsSyncStatus = serializedDic });
|
new { acct, host, inboxRoute, sharedInboxRoute, followings, followingsSyncStatus = serializedDic, actorId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,19 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<SyncTwitterUser> GetTwitterUserAsync(int id)
|
||||||
|
{
|
||||||
|
var query = $"SELECT * FROM {_settings.TwitterUserTableName} WHERE id = @id";
|
||||||
|
|
||||||
|
using (var dbConnection = Connection)
|
||||||
|
{
|
||||||
|
dbConnection.Open();
|
||||||
|
|
||||||
|
var result = (await dbConnection.QueryAsync<SyncTwitterUser>(query, new { id })).FirstOrDefault();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task DeleteTwitterUserAsync(int id)
|
public async Task DeleteTwitterUserAsync(int id)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
|
@ -7,7 +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 CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, 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);
|
||||||
Task<Follower[]> GetAllFollowersAsync();
|
Task<Follower[]> GetAllFollowersAsync();
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace BirdsiteLive.DAL.Contracts
|
||||||
{
|
{
|
||||||
Task CreateTwitterUserAsync(string acct, long lastTweetPostedId);
|
Task CreateTwitterUserAsync(string acct, long lastTweetPostedId);
|
||||||
Task<SyncTwitterUser> GetTwitterUserAsync(string acct);
|
Task<SyncTwitterUser> GetTwitterUserAsync(string acct);
|
||||||
|
Task<SyncTwitterUser> GetTwitterUserAsync(int id);
|
||||||
Task<SyncTwitterUser[]> GetAllTwitterUsersAsync(int maxNumber);
|
Task<SyncTwitterUser[]> GetAllTwitterUsersAsync(int maxNumber);
|
||||||
Task<SyncTwitterUser[]> GetAllTwitterUsersAsync();
|
Task<SyncTwitterUser[]> GetAllTwitterUsersAsync();
|
||||||
Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId, DateTime lastSync);
|
Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId, DateTime lastSync);
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace BirdsiteLive.DAL.Models
|
||||||
public List<int> Followings { get; set; }
|
public List<int> Followings { get; set; }
|
||||||
public Dictionary<int, long> FollowingsSyncStatus { get; set; }
|
public Dictionary<int, long> FollowingsSyncStatus { get; set; }
|
||||||
|
|
||||||
|
public string ActorId { get; set; }
|
||||||
public string Acct { get; set; }
|
public string Acct { get; set; }
|
||||||
public string Host { get; set; }
|
public string Host { get; set; }
|
||||||
public string InboxRoute { get; set; }
|
public string InboxRoute { get; set; }
|
||||||
|
|
|
@ -41,9 +41,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
};
|
};
|
||||||
var inboxRoute = "/myhandle/inbox";
|
var inboxRoute = "/myhandle/inbox";
|
||||||
var sharedInboxRoute = "/inbox";
|
var sharedInboxRoute = "/inbox";
|
||||||
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
|
||||||
var dal = new FollowersPostgresDal(_settings);
|
var dal = new FollowersPostgresDal(_settings);
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
var result = await dal.GetFollowerAsync(acct, host);
|
var result = await dal.GetFollowerAsync(acct, host);
|
||||||
|
|
||||||
|
@ -73,9 +74,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
};
|
};
|
||||||
var inboxRoute = "/myhandle/inbox";
|
var inboxRoute = "/myhandle/inbox";
|
||||||
string sharedInboxRoute = null;
|
string sharedInboxRoute = null;
|
||||||
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
|
||||||
var dal = new FollowersPostgresDal(_settings);
|
var dal = new FollowersPostgresDal(_settings);
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
var result = await dal.GetFollowerAsync(acct, host);
|
var result = await dal.GetFollowerAsync(acct, host);
|
||||||
|
|
||||||
|
@ -103,7 +105,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
var followingSync = new Dictionary<int, long>();
|
var followingSync = new Dictionary<int, long>();
|
||||||
var inboxRoute = "/myhandle1/inbox";
|
var inboxRoute = "/myhandle1/inbox";
|
||||||
var sharedInboxRoute = "/inbox";
|
var sharedInboxRoute = "/inbox";
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
//User 2
|
//User 2
|
||||||
acct = "myhandle2";
|
acct = "myhandle2";
|
||||||
|
@ -111,7 +114,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
following = new[] { 2, 4, 5 };
|
following = new[] { 2, 4, 5 };
|
||||||
inboxRoute = "/myhandle2/inbox";
|
inboxRoute = "/myhandle2/inbox";
|
||||||
sharedInboxRoute = "/inbox2";
|
sharedInboxRoute = "/inbox2";
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
actorId = $"https://{host}/{acct}";
|
||||||
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
//User 2
|
//User 2
|
||||||
acct = "myhandle3";
|
acct = "myhandle3";
|
||||||
|
@ -119,7 +123,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
following = new[] { 1 };
|
following = new[] { 1 };
|
||||||
inboxRoute = "/myhandle3/inbox";
|
inboxRoute = "/myhandle3/inbox";
|
||||||
sharedInboxRoute = "/inbox3";
|
sharedInboxRoute = "/inbox3";
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
actorId = $"https://{host}/{acct}";
|
||||||
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
var result = await dal.GetFollowersAsync(2);
|
var result = await dal.GetFollowersAsync(2);
|
||||||
Assert.AreEqual(2, result.Length);
|
Assert.AreEqual(2, result.Length);
|
||||||
|
@ -146,7 +151,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
var followingSync = new Dictionary<int, long>();
|
var followingSync = new Dictionary<int, long>();
|
||||||
var inboxRoute = "/myhandle1/inbox";
|
var inboxRoute = "/myhandle1/inbox";
|
||||||
var sharedInboxRoute = "/inbox";
|
var sharedInboxRoute = "/inbox";
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
//User 2
|
//User 2
|
||||||
acct = "myhandle2";
|
acct = "myhandle2";
|
||||||
|
@ -154,7 +160,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
following = new[] { 2, 4, 5 };
|
following = new[] { 2, 4, 5 };
|
||||||
inboxRoute = "/myhandle2/inbox";
|
inboxRoute = "/myhandle2/inbox";
|
||||||
sharedInboxRoute = "/inbox2";
|
sharedInboxRoute = "/inbox2";
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
actorId = $"https://{host}/{acct}";
|
||||||
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
//User 2
|
//User 2
|
||||||
acct = "myhandle3";
|
acct = "myhandle3";
|
||||||
|
@ -162,7 +169,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
following = new[] { 1 };
|
following = new[] { 1 };
|
||||||
inboxRoute = "/myhandle3/inbox";
|
inboxRoute = "/myhandle3/inbox";
|
||||||
sharedInboxRoute = "/inbox3";
|
sharedInboxRoute = "/inbox3";
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
actorId = $"https://{host}/{acct}";
|
||||||
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
|
|
||||||
result = await dal.GetFollowersCountAsync();
|
result = await dal.GetFollowersCountAsync();
|
||||||
Assert.AreEqual(3, result);
|
Assert.AreEqual(3, result);
|
||||||
|
@ -182,9 +190,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
};
|
};
|
||||||
var inboxRoute = "/myhandle/inbox";
|
var inboxRoute = "/myhandle/inbox";
|
||||||
var sharedInboxRoute = "/inbox";
|
var sharedInboxRoute = "/inbox";
|
||||||
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
|
||||||
var dal = new FollowersPostgresDal(_settings);
|
var dal = new FollowersPostgresDal(_settings);
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
var result = await dal.GetFollowerAsync(acct, host);
|
var result = await dal.GetFollowerAsync(acct, host);
|
||||||
|
|
||||||
var updatedFollowing = new List<int> { 12, 19, 23, 24 };
|
var updatedFollowing = new List<int> { 12, 19, 23, 24 };
|
||||||
|
@ -222,9 +231,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
};
|
};
|
||||||
var inboxRoute = "/myhandle/inbox";
|
var inboxRoute = "/myhandle/inbox";
|
||||||
var sharedInboxRoute = "/inbox";
|
var sharedInboxRoute = "/inbox";
|
||||||
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
|
||||||
var dal = new FollowersPostgresDal(_settings);
|
var dal = new FollowersPostgresDal(_settings);
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
var result = await dal.GetFollowerAsync(acct, host);
|
var result = await dal.GetFollowerAsync(acct, host);
|
||||||
|
|
||||||
var updatedFollowing = new[] { 12, 19 };
|
var updatedFollowing = new[] { 12, 19 };
|
||||||
|
@ -260,9 +270,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
};
|
};
|
||||||
var inboxRoute = "/myhandle/inbox";
|
var inboxRoute = "/myhandle/inbox";
|
||||||
var sharedInboxRoute = "/inbox";
|
var sharedInboxRoute = "/inbox";
|
||||||
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
|
||||||
var dal = new FollowersPostgresDal(_settings);
|
var dal = new FollowersPostgresDal(_settings);
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
var result = await dal.GetFollowerAsync(acct, host);
|
var result = await dal.GetFollowerAsync(acct, host);
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
|
|
||||||
|
@ -286,9 +297,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
||||||
};
|
};
|
||||||
var inboxRoute = "/myhandle/inbox";
|
var inboxRoute = "/myhandle/inbox";
|
||||||
var sharedInboxRoute = "/inbox";
|
var sharedInboxRoute = "/inbox";
|
||||||
|
var actorId = $"https://{host}/{acct}";
|
||||||
|
|
||||||
var dal = new FollowersPostgresDal(_settings);
|
var dal = new FollowersPostgresDal(_settings);
|
||||||
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, following, followingSync);
|
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
|
||||||
var result = await dal.GetFollowerAsync(acct, host);
|
var result = await dal.GetFollowerAsync(acct, host);
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases
|
||||||
var twitterName = "handle";
|
var twitterName = "handle";
|
||||||
var followerInbox = "/user/testest";
|
var followerInbox = "/user/testest";
|
||||||
var inbox = "/inbox";
|
var inbox = "/inbox";
|
||||||
|
var actorId = "actorUrl";
|
||||||
|
|
||||||
var follower = new Follower
|
var follower = new Follower
|
||||||
{
|
{
|
||||||
|
@ -55,6 +56,7 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases
|
||||||
It.Is<string>(y => y == domain),
|
It.Is<string>(y => y == domain),
|
||||||
It.Is<string>(y => y == followerInbox),
|
It.Is<string>(y => y == followerInbox),
|
||||||
It.Is<string>(y => y == inbox),
|
It.Is<string>(y => y == inbox),
|
||||||
|
It.Is<string>(y => y == actorId),
|
||||||
null,
|
null,
|
||||||
null))
|
null))
|
||||||
.Returns(Task.CompletedTask);
|
.Returns(Task.CompletedTask);
|
||||||
|
@ -80,7 +82,7 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
var action = new ProcessFollowUser(followersDalMock.Object, twitterUserDalMock.Object);
|
var action = new ProcessFollowUser(followersDalMock.Object, twitterUserDalMock.Object);
|
||||||
await action.ExecuteAsync(username, domain, twitterName, followerInbox, inbox);
|
await action.ExecuteAsync(username, domain, twitterName, followerInbox, inbox, actorId);
|
||||||
|
|
||||||
#region Validations
|
#region Validations
|
||||||
followersDalMock.VerifyAll();
|
followersDalMock.VerifyAll();
|
||||||
|
@ -97,6 +99,7 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases
|
||||||
var twitterName = "handle";
|
var twitterName = "handle";
|
||||||
var followerInbox = "/user/testest";
|
var followerInbox = "/user/testest";
|
||||||
var inbox = "/inbox";
|
var inbox = "/inbox";
|
||||||
|
var actorId = "actorUrl";
|
||||||
|
|
||||||
var follower = new Follower
|
var follower = new Follower
|
||||||
{
|
{
|
||||||
|
@ -138,7 +141,7 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
var action = new ProcessFollowUser(followersDalMock.Object, twitterUserDalMock.Object);
|
var action = new ProcessFollowUser(followersDalMock.Object, twitterUserDalMock.Object);
|
||||||
await action.ExecuteAsync(username, domain, twitterName, followerInbox, inbox);
|
await action.ExecuteAsync(username, domain, twitterName, followerInbox, inbox, actorId);
|
||||||
|
|
||||||
#region Validations
|
#region Validations
|
||||||
followersDalMock.VerifyAll();
|
followersDalMock.VerifyAll();
|
||||||
|
|
Loading…
Add table
Reference in a new issue