From 475716322f936302defbc3e1169769210040f6bc Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Sat, 21 May 2022 16:44:39 -0500 Subject: [PATCH] Fix up missing avatars --- src/discord/message_handling.go | 1 - src/hmndata/threads_and_posts_helper.go | 30 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/discord/message_handling.go b/src/discord/message_handling.go index 1fdf82d7..57f05684 100644 --- a/src/discord/message_handling.go +++ b/src/discord/message_handling.go @@ -227,7 +227,6 @@ func FetchInternedMessage(ctx context.Context, dbConn db.ConnOrTx, msgId string) LEFT JOIN discord_message_content AS content ON content.message_id = message.id LEFT JOIN discord_user AS duser ON duser.userid = message.user_id LEFT JOIN hmn_user AS hmnuser ON hmnuser.id = duser.hmn_user_id - LEFT JOIN asset AS hmnuser_avatar ON hmnuser_avatar.id = hmnuser.avatar_asset_id WHERE message.id = $1 `, msgId, diff --git a/src/hmndata/threads_and_posts_helper.go b/src/hmndata/threads_and_posts_helper.go index fe638b3c..49363c96 100644 --- a/src/hmndata/threads_and_posts_helper.go +++ b/src/hmndata/threads_and_posts_helper.go @@ -141,8 +141,10 @@ func FetchThreads( type resultRow struct { ThreadAndStuff - ThreadLastReadTime *time.Time `db:"tlri.lastread"` - ForumLastReadTime *time.Time `db:"slri.lastread"` + FirstPostAuthorAvatar *models.Asset `db:"first_author_avatar"` + LastPostAuthorAvatar *models.Asset `db:"last_author_avatar"` + ThreadLastReadTime *time.Time `db:"tlri.lastread"` + ForumLastReadTime *time.Time `db:"slri.lastread"` } rows, err := db.Query[resultRow](ctx, dbConn, qb.String(), qb.Args()...) @@ -152,6 +154,13 @@ func FetchThreads( result := make([]ThreadAndStuff, len(rows)) for i, row := range rows { + if row.FirstPostAuthor != nil { + row.FirstPostAuthor.AvatarAsset = row.FirstPostAuthorAvatar + } + if row.LastPostAuthor != nil { + row.LastPostAuthor.AvatarAsset = row.LastPostAuthorAvatar + } + hasRead := false if currentUser != nil && currentUser.MarkedAllReadAt.After(row.LastPost.PostDate) { hasRead = true @@ -320,8 +329,11 @@ func FetchPosts( type resultRow struct { PostAndStuff - ThreadLastReadTime *time.Time `db:"tlri.lastread"` - ForumLastReadTime *time.Time `db:"slri.lastread"` + AuthorAvatar *models.Asset `db:"author_avatar"` + EditorAvatar *models.Asset `db:"editor_avatar"` + ReplyAuthorAvatar *models.Asset `db:"reply_author_avatar"` + ThreadLastReadTime *time.Time `db:"tlri.lastread"` + ForumLastReadTime *time.Time `db:"slri.lastread"` } qb.Add( @@ -410,6 +422,16 @@ func FetchPosts( result := make([]PostAndStuff, len(rows)) for i, row := range rows { + if row.Author != nil { + row.Author.AvatarAsset = row.AuthorAvatar + } + if row.Editor != nil { + row.Editor.AvatarAsset = row.EditorAvatar + } + if row.ReplyAuthor != nil { + row.ReplyAuthor.AvatarAsset = row.ReplyAuthorAvatar + } + hasRead := false if currentUser != nil && currentUser.MarkedAllReadAt.After(row.Post.PostDate) { hasRead = true