Include current user "likes" information when building notifications feed

This commit is contained in:
Alessio 2025-02-15 12:51:07 -08:00
parent ff1f70f035
commit 5be812e96e
3 changed files with 14 additions and 7 deletions

View File

@ -25,6 +25,8 @@ const TWEETS_ALL_SQL_FIELDS = `
// - spaces
// - users
// - images, videos, urls, polls
//
// `current_user_id` is used to fetch likes on quoted tweets
func (p Profile) fill_content(trove *TweetTrove, current_user_id UserID) {
if len(trove.Tweets) == 0 {
// Empty trove, nothing to fetch
@ -453,15 +455,15 @@ func (p Profile) GetNotificationsForUser(u_id UserID, cursor int64, count int64)
tweet_ids = append(tweet_ids, r.TweetID)
}
}
// Get tweets, if there are any
var tweets []Tweet
if len(tweet_ids) != 0 {
sql_str, vals, err := sqlx.In(`select `+TWEETS_ALL_SQL_FIELDS+`
sql_str, vals, err := sqlx.In(`
select `+TWEETS_ALL_SQL_FIELDS+`
from tweets
left join tombstone_types on tweets.tombstone_type = tombstone_types.rowid
left join likes on tweets.id = likes.tweet_id and likes.user_id = -1
where id in (?)`, tweet_ids)
left join likes on tweets.id = likes.tweet_id and likes.user_id = ?
where id in (?)`, u_id, tweet_ids)
if err != nil {
panic(err)
}
@ -496,8 +498,7 @@ func (p Profile) GetNotificationsForUser(u_id UserID, cursor int64, count int64)
ret.Items = append(ret.Items, feed_item)
}
// TODO: proper user id
p.fill_content(&ret.TweetTrove, UserID(0))
p.fill_content(&ret.TweetTrove, u_id)
// Set the bottom cursor value
ret.CursorBottom = Cursor{}

View File

@ -352,6 +352,11 @@ 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"
liked_tweet, is_ok := feed.TweetTrove.Tweets[1826778617705115869]
require.True(is_ok)
assert.True(liked_tweet.IsLikedByCurrentUser)
assert.Equal(feed.CursorBottom.CursorPosition, CURSOR_MIDDLE)
assert.Equal(feed.CursorBottom.CursorValue, 1723494244885)

View File

@ -359,7 +359,8 @@ insert into likes values
(2, 2, 1178839081222115328, 1513313535480287235),
(3, 3, 1178839081222115328, 1343633011364016128),
(4, 4, 1178839081222115328, 1426669666928414720),
(5, 5, 1178839081222115328, 1698765208393576891);
(5, 5, 1178839081222115328, 1698765208393576891),
(6, 6, 1488963321701171204, 1826778617705115869);
create table bookmarks(rowid integer primary key,