Notification feed should load tweet and retweet IDs in order to display 'liked N of your tweets', etc

This commit is contained in:
Alessio 2025-02-15 13:57:00 -08:00
parent 5be812e96e
commit 1af7fa3817
4 changed files with 46 additions and 12 deletions

View File

@ -107,6 +107,7 @@ func (p Profile) fill_content(trove *TweetTrove, current_user_id UserID) {
user_ids = append(user_ids, p)
}
}
// User detail is needed to render the notification properly (profile image, username)
for _, n := range trove.Notifications {
// Primary user
if n.ActionUserID != UserID(0) {
@ -408,8 +409,7 @@ func (p Profile) GetNotificationsForUser(u_id UserID, cursor int64, count int64)
panic(err)
}
// Get the user_ids list for each notification. Unlike tweet+retweet_ids, users are needed to render
// the notification properly.
// Get the user_ids, tweet_ids, and retweet_ids list for each notification
for i := range notifications {
err = p.DB.Select(&notifications[i].UserIDs,
`select user_id from notification_users where notification_id = ?`,
@ -419,8 +419,27 @@ func (p Profile) GetNotificationsForUser(u_id UserID, cursor int64, count int64)
panic(err)
}
}
for i := range notifications {
err = p.DB.Select(&notifications[i].TweetIDs,
`select tweet_id from notification_tweets where notification_id = ?`,
notifications[i].ID,
)
if err != nil {
panic(err)
}
}
for i := range notifications {
err = p.DB.Select(&notifications[i].RetweetIDs,
`select retweet_id from notification_retweets where notification_id = ?`,
notifications[i].ID,
)
if err != nil {
panic(err)
}
}
// Collect tweet and retweet IDs
// Collect tweet and retweet IDs.
// Users are fetched in `fill_content`
retweet_ids := []TweetID{}
tweet_ids := []TweetID{}
for _, n := range notifications {

View File

@ -352,11 +352,17 @@ func TestNotificationsFeed(t *testing.T) {
assert.Equal(feed.Items[5].NotificationID, NotificationID("FKncQJGVgAQAAAABSQ3bEaTgXL8f40e77r4"))
assert.Equal(feed.Items[5].TweetID, TweetID(1826778617705115868))
// Tweet should be "liked"
// This tweet should be "liked"
liked_tweet, is_ok := feed.TweetTrove.Tweets[1826778617705115869]
require.True(is_ok)
assert.True(liked_tweet.IsLikedByCurrentUser)
notif1, is_ok := feed.TweetTrove.Notifications["FDzeDIfVUAIAAAABiJONcqaBFAzeN-n-Luw"]
require.Len(notif1.TweetIDs, 1)
assert.Equal(notif1.TweetIDs[0], TweetID(1507883724615999488))
require.Len(notif1.RetweetIDs, 1)
assert.Equal(notif1.RetweetIDs[0], TweetID(1490135787124232223))
assert.Equal(feed.CursorBottom.CursorPosition, CURSOR_MIDDLE)
assert.Equal(feed.CursorBottom.CursorValue, 1723494244885)

View File

@ -99,19 +99,20 @@ func TestTimeline(t *testing.T) {
require.NoError(err)
c := NewTimelineCursor()
c.PageSize = 6
c.PageSize = 7
feed, err := profile.NextPage(c, UserID(0))
require.NoError(err)
assert.Len(feed.Items, 6)
assert.Len(feed.Items, 7)
assert.Len(feed.Retweets, 4)
assert.Equal(feed.Items[0].TweetID, TweetID(1826778617705115868))
assert.Equal(feed.Items[1].RetweetID, TweetID(1490135787144237058))
assert.Equal(feed.Items[2].RetweetID, TweetID(1490135787124232223))
assert.Equal(feed.Items[3].RetweetID, TweetID(1490119308692766723))
assert.Equal(feed.Items[4].RetweetID, TweetID(1490100255987171332))
assert.Equal(feed.Items[5].TweetID, TweetID(1453461248142495744))
assert.Equal(feed.Items[1].TweetID, TweetID(1507883724615999488))
assert.Equal(feed.Items[2].RetweetID, TweetID(1490135787144237058))
assert.Equal(feed.Items[3].RetweetID, TweetID(1490135787124232223))
assert.Equal(feed.Items[4].RetweetID, TweetID(1490119308692766723))
assert.Equal(feed.Items[5].RetweetID, TweetID(1490100255987171332))
assert.Equal(feed.Items[6].TweetID, TweetID(1453461248142495744))
next_cursor := feed.CursorBottom
assert.Equal(next_cursor.CursorPosition, CURSOR_MIDDLE)

View File

@ -196,7 +196,8 @@ INSERT INTO tweets VALUES
(1411566,1698848086880133147,1458284524761075714,'I have basically no experience with one and literally no experience with the other, and additionally I''ve never even used Haskell. So unfortunately I''m not really in a position to say.',1693871921000,1,0,1,0,1698802806096846909,0,'sol_plunder,ilyakooo0','sol_plunder,ilyakooo0','',NULL,NULL, 0,1,0,0,0),
(1169437,1665509126737129472,1458284524761075714,replace('Btw, to the extent this has happened, it''s partly thanks to the Golden One (@TheGloriousLion) who invented #fizeekfriday and the "post physique" rejoinder. Everyone should follow him if they don''t already.\n\nSince I forgot last week, and since it''s topical, here''s a leg poast','\n',char(10)),1685923294000,7,0,0,0,1665505986184900611,0,'TheGloriousLion','','fizeekfriday',NULL,NULL,0,1,0,0,0),
(2857438,1826778617705115868,1488963321701171204,'Conversations are trees, not sequences. They branch. They don''t flow in a perfectly linear way.',1724372937000,4,1,0,0,0,0,'','','',NULL,NULL,0,1,0,0,0),
(2857439,1826778617705115869,1178839081222115328,'Real tweet that is definitely real',1724372938000,4,1,0,0,1826778617705115868,0,'Offline_Twatter','Offline_Twatter','',NULL,NULL,0,1,0,0,0);
(2857439,1826778617705115869,1178839081222115328,'Real tweet that is definitely real',1724372938000,4,1,0,0,1826778617705115868,0,'Offline_Twatter','Offline_Twatter','',NULL,NULL,0,1,0,0,0),
(98105,1507883724615999488,1488963321701171204,'Apparently I am not allowed to call myself "Twitter"',1648342469000,5,1,0,1,0,0,'','','',NULL,NULL,0,1,1,1739654377321,0);
CREATE TABLE retweets(rowid integer primary key,
retweet_id integer not null unique,
@ -576,12 +577,19 @@ create table notification_tweets (rowid integer primary key,
tweet_id not null references tweets(id),
unique(notification_id, tweet_id)
);
insert into notification_tweets values
(1, 'FKncQJGVgAQAAAABSQ3bEaTgXL8f40e77r4', 1826778617705115868),
(2, 'FKncQJGVgAQAAAABSQ3bEaTgXL8VBxefepo', 1826778617705115868),
(3, 'FDzeDIfVUAIAAvsBiJONcqYgiLgXOolO9t0', 1826778617705115869),
(4, 'FDzeDIfVUAIAAAABiJONcqaBFAzeN-n-Luw', 1507883724615999488);
create table notification_retweets (rowid integer primary key,
notification_id not null references notifications(id),
retweet_id not null references retweets(retweet_id),
unique(notification_id, retweet_id)
);
insert into notification_retweets values
(1, 'FDzeDIfVUAIAAAABiJONcqaBFAzeN-n-Luw', 1490135787124232223);
create table notification_users (rowid integer primary key,
notification_id not null references notifications(id),