Fix up missing avatars

This commit is contained in:
Ben Visness 2022-05-21 16:44:39 -05:00
parent 6dd11aa970
commit 475716322f
2 changed files with 26 additions and 5 deletions

View File

@ -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_message_content AS content ON content.message_id = message.id
LEFT JOIN discord_user AS duser ON duser.userid = message.user_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 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 WHERE message.id = $1
`, `,
msgId, msgId,

View File

@ -141,6 +141,8 @@ func FetchThreads(
type resultRow struct { type resultRow struct {
ThreadAndStuff ThreadAndStuff
FirstPostAuthorAvatar *models.Asset `db:"first_author_avatar"`
LastPostAuthorAvatar *models.Asset `db:"last_author_avatar"`
ThreadLastReadTime *time.Time `db:"tlri.lastread"` ThreadLastReadTime *time.Time `db:"tlri.lastread"`
ForumLastReadTime *time.Time `db:"slri.lastread"` ForumLastReadTime *time.Time `db:"slri.lastread"`
} }
@ -152,6 +154,13 @@ func FetchThreads(
result := make([]ThreadAndStuff, len(rows)) result := make([]ThreadAndStuff, len(rows))
for i, row := range 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 hasRead := false
if currentUser != nil && currentUser.MarkedAllReadAt.After(row.LastPost.PostDate) { if currentUser != nil && currentUser.MarkedAllReadAt.After(row.LastPost.PostDate) {
hasRead = true hasRead = true
@ -320,6 +329,9 @@ func FetchPosts(
type resultRow struct { type resultRow struct {
PostAndStuff PostAndStuff
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"` ThreadLastReadTime *time.Time `db:"tlri.lastread"`
ForumLastReadTime *time.Time `db:"slri.lastread"` ForumLastReadTime *time.Time `db:"slri.lastread"`
} }
@ -410,6 +422,16 @@ func FetchPosts(
result := make([]PostAndStuff, len(rows)) result := make([]PostAndStuff, len(rows))
for i, row := range 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 hasRead := false
if currentUser != nil && currentUser.MarkedAllReadAt.After(row.Post.PostDate) { if currentUser != nil && currentUser.MarkedAllReadAt.After(row.Post.PostDate) {
hasRead = true hasRead = true