Include current user "likes" information when building notifications feed
This commit is contained in:
parent
ff1f70f035
commit
5be812e96e
@ -25,6 +25,8 @@ const TWEETS_ALL_SQL_FIELDS = `
|
|||||||
// - spaces
|
// - spaces
|
||||||
// - users
|
// - users
|
||||||
// - images, videos, urls, polls
|
// - 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) {
|
func (p Profile) fill_content(trove *TweetTrove, current_user_id UserID) {
|
||||||
if len(trove.Tweets) == 0 {
|
if len(trove.Tweets) == 0 {
|
||||||
// Empty trove, nothing to fetch
|
// 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)
|
tweet_ids = append(tweet_ids, r.TweetID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get tweets, if there are any
|
// Get tweets, if there are any
|
||||||
var tweets []Tweet
|
var tweets []Tweet
|
||||||
if len(tweet_ids) != 0 {
|
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
|
from tweets
|
||||||
left join tombstone_types on tweets.tombstone_type = tombstone_types.rowid
|
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
|
left join likes on tweets.id = likes.tweet_id and likes.user_id = ?
|
||||||
where id in (?)`, tweet_ids)
|
where id in (?)`, u_id, tweet_ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -496,8 +498,7 @@ func (p Profile) GetNotificationsForUser(u_id UserID, cursor int64, count int64)
|
|||||||
ret.Items = append(ret.Items, feed_item)
|
ret.Items = append(ret.Items, feed_item)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: proper user id
|
p.fill_content(&ret.TweetTrove, u_id)
|
||||||
p.fill_content(&ret.TweetTrove, UserID(0))
|
|
||||||
|
|
||||||
// Set the bottom cursor value
|
// Set the bottom cursor value
|
||||||
ret.CursorBottom = Cursor{}
|
ret.CursorBottom = Cursor{}
|
||||||
|
@ -352,6 +352,11 @@ func TestNotificationsFeed(t *testing.T) {
|
|||||||
assert.Equal(feed.Items[5].NotificationID, NotificationID("FKncQJGVgAQAAAABSQ3bEaTgXL8f40e77r4"))
|
assert.Equal(feed.Items[5].NotificationID, NotificationID("FKncQJGVgAQAAAABSQ3bEaTgXL8f40e77r4"))
|
||||||
assert.Equal(feed.Items[5].TweetID, TweetID(1826778617705115868))
|
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.CursorPosition, CURSOR_MIDDLE)
|
||||||
assert.Equal(feed.CursorBottom.CursorValue, 1723494244885)
|
assert.Equal(feed.CursorBottom.CursorValue, 1723494244885)
|
||||||
|
|
||||||
|
@ -359,7 +359,8 @@ insert into likes values
|
|||||||
(2, 2, 1178839081222115328, 1513313535480287235),
|
(2, 2, 1178839081222115328, 1513313535480287235),
|
||||||
(3, 3, 1178839081222115328, 1343633011364016128),
|
(3, 3, 1178839081222115328, 1343633011364016128),
|
||||||
(4, 4, 1178839081222115328, 1426669666928414720),
|
(4, 4, 1178839081222115328, 1426669666928414720),
|
||||||
(5, 5, 1178839081222115328, 1698765208393576891);
|
(5, 5, 1178839081222115328, 1698765208393576891),
|
||||||
|
(6, 6, 1488963321701171204, 1826778617705115869);
|
||||||
|
|
||||||
|
|
||||||
create table bookmarks(rowid integer primary key,
|
create table bookmarks(rowid integer primary key,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user