added inbox property for followers

This commit is contained in:
Nicolas Constant 2020-07-07 18:39:35 -04:00
parent 5cd6279da8
commit 34bf9ff140
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
5 changed files with 27 additions and 14 deletions

View file

@ -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);

View file

@ -20,7 +20,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
}
#endregion
public async Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary<int, long> followingSyncStatus)
public async Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary<int, long> 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<Dictionary<int,long>>(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; }
}
}

View file

@ -7,7 +7,7 @@ namespace BirdsiteLive.DAL.Contracts
public interface IFollowersDal
{
Task<Follower> GetFollowerAsync(string acct, string host);
Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary<int, long> followingSyncStatus);
Task CreateFollowerAsync(string acct, string host, int[] followings, Dictionary<int, long> followingSyncStatus, string inboxUrl);
Task<Follower[]> GetFollowersAsync(int followedUserId);
Task UpdateFollowerAsync(int id, int[] followings, Dictionary<int, long> followingSyncStatus);
Task DeleteFollowerAsync(int id);

View file

@ -11,5 +11,6 @@ namespace BirdsiteLive.DAL.Models
public string Acct { get; set; }
public string Host { get; set; }
public string InboxUrl { get; set; }
}
}

View file

@ -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<int, long>();
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);