Joining a channel now marks it as read

This commit is contained in:
diamondburned 2020-07-16 20:12:42 -07:00
parent 6e52197039
commit 50ba10bf61
1 changed files with 12 additions and 8 deletions

View File

@ -237,15 +237,19 @@ func (ch *Channel) JoinServer(ctx context.Context, ct cchat.MessagesContainer) (
} }
} }
// Sort messages chronologically using the ID so that the oldest messages // Only do all this if we even have any messages.
// (ones with the smallest snowflake) is in front. if len(m) > 0 {
sort.Slice(m, func(i, j int) bool { // Sort messages chronologically using the ID so that the oldest messages
return m[i].ID < m[j].ID // (ones with the smallest snowflake) is in front.
}) sort.Slice(m, func(i, j int) bool { return m[i].ID < m[j].ID })
// Iterate from the earliest messages to the latest messages. // Iterate from the earliest messages to the latest messages.
for _, m := range m { for _, m := range m {
ct.CreateMessage(constructor(m)) ct.CreateMessage(constructor(m))
}
// Mark this channel as read.
ch.session.ReadState.MarkRead(ch.id, m[len(m)-1].ID)
} }
// Bind the handler. // Bind the handler.