From 34bf9ff140969e4b7b994793d00ad9fe555a0640 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Tue, 7 Jul 2020 18:39:35 -0400 Subject: [PATCH] added inbox property for followers --- .../DbInitializerPostgresDal.cs | 5 ++-- .../DataAccessLayers/FollowersPostgresDal.cs | 8 +++--- .../Contracts/IFollowersDal.cs | 2 +- .../BirdsiteLive.DAL/Models/Follower.cs | 1 + .../FollowersPostgresDalTests.cs | 25 +++++++++++++------ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs index 7b36644..832eaf4 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs @@ -106,8 +106,9 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers followings INTEGER[], followingsSyncStatus JSONB, - acct VARCHAR(50), - host VARCHAR(253), + acct VARCHAR(50) NOT NULL, + host VARCHAR(253) NOT NULL, + inboxUrl VARCHAR(2048) NOT NULL, UNIQUE (acct, host) );"; await _tools.ExecuteRequestAsync(createFollowers); diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs index 7e6c2ac..fdfd7e7 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs @@ -20,7 +20,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers } #endregion - public async Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary followingSyncStatus) + public async Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary followingSyncStatus, string inboxUrl) { var serializedDic = JsonConvert.SerializeObject(followingSyncStatus); @@ -32,8 +32,8 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers dbConnection.Open(); await dbConnection.ExecuteAsync( - $"INSERT INTO {_settings.FollowersTableName} (acct,host,followings,followingsSyncStatus) VALUES(@acct,@host,@followings, CAST(@followingsSyncStatus as json))", - new { acct, host, followings, followingsSyncStatus = serializedDic }); + $"INSERT INTO {_settings.FollowersTableName} (acct,host,inboxUrl,followings,followingsSyncStatus) VALUES(@acct,@host,@inboxUrl,@followings,CAST(@followingsSyncStatus as json))", + new { acct, host, inboxUrl, followings, followingsSyncStatus = serializedDic }); } } @@ -124,6 +124,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers Id = follower.Id, Acct = follower.Acct, Host = follower.Host, + InboxUrl = follower.InboxUrl, Followings = follower.Followings, FollowingsSyncStatus = JsonConvert.DeserializeObject>(follower.FollowingsSyncStatus) }; @@ -138,5 +139,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers public string Acct { get; set; } public string Host { get; set; } + public string InboxUrl { get; set; } } } \ No newline at end of file diff --git a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs index 92e0cb3..19b3dbc 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs @@ -7,7 +7,7 @@ namespace BirdsiteLive.DAL.Contracts public interface IFollowersDal { Task GetFollowerAsync(string acct, string host); - Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary followingSyncStatus); + Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary followingSyncStatus, string inboxUrl); Task GetFollowersAsync(int followedUserId); Task UpdateFollowerAsync(int id, int[] followings, Dictionary followingSyncStatus); Task DeleteFollowerAsync(int id); diff --git a/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs b/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs index 5eedafb..32ee22b 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs @@ -11,5 +11,6 @@ namespace BirdsiteLive.DAL.Models public string Acct { get; set; } public string Host { get; set; } + public string InboxUrl { get; set; } } } \ No newline at end of file diff --git a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs index f359f06..fed68ed 100644 --- a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs +++ b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs @@ -45,15 +45,17 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {19, 166L}, {23, 167L} }; + var inboxUrl = "https://domain.ext/myhandle/inbox"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, following, followingSync); + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); var result = await dal.GetFollowerAsync(acct, host); Assert.IsNotNull(result); Assert.AreEqual(acct, result.Acct); Assert.AreEqual(host, result.Host); + Assert.AreEqual(inboxUrl, result.InboxUrl); Assert.AreEqual(following.Length, result.Followings.Length); Assert.AreEqual(following[0], result.Followings[0]); Assert.AreEqual(followingSync.Count, result.FollowingsSyncStatus.Count); @@ -71,19 +73,22 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var host = "domain.ext"; var following = new[] { 1,2,3 }; var followingSync = new Dictionary(); - await dal.CreateFollowerAsync(acct, host, following, followingSync); + var inboxUrl = "https://domain.ext/myhandle1/inbox"; + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); //User 2 acct = "myhandle2"; host = "domain.ext"; following = new[] { 2, 4, 5 }; - await dal.CreateFollowerAsync(acct, host, following, followingSync); + inboxUrl = "https://domain.ext/myhandle2/inbox"; + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); //User 2 acct = "myhandle3"; host = "domain.ext"; following = new[] { 1 }; - await dal.CreateFollowerAsync(acct, host, following, followingSync); + inboxUrl = "https://domain.ext/myhandle3/inbox"; + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); var result = await dal.GetFollowersAsync(2); Assert.AreEqual(2, result.Length); @@ -107,9 +112,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {19, 166L}, {23, 167L} }; + var inboxUrl = "https://domain.ext/myhandle/inbox"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, following, followingSync); + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); var result = await dal.GetFollowerAsync(acct, host); var updatedFollowing = new[] { 12, 19, 23, 24 }; @@ -143,9 +149,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {19, 166L}, {23, 167L} }; + var inboxUrl = "https://domain.ext/myhandle/inbox"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, following, followingSync); + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); var result = await dal.GetFollowerAsync(acct, host); var updatedFollowing = new[] { 12, 19 }; @@ -177,9 +184,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {19, 166L}, {23, 167L} }; + var inboxUrl = "https://domain.ext/myhandle/inbox"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, following, followingSync); + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); var result = await dal.GetFollowerAsync(acct, host); Assert.IsNotNull(result); @@ -201,9 +209,10 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {19, 166L}, {23, 167L} }; + var inboxUrl = "https://domain.ext/myhandle/inbox"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, following, followingSync); + await dal.CreateFollowerAsync(acct, host, following, followingSync, inboxUrl); var result = await dal.GetFollowerAsync(acct, host); Assert.IsNotNull(result);