mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2024-11-25 23:52:48 +00:00
Joining a channel now marks it as read
This commit is contained in:
parent
6e52197039
commit
50ba10bf61
10
channel.go
10
channel.go
|
@ -237,17 +237,21 @@ func (ch *Channel) JoinServer(ctx context.Context, ct cchat.MessagesContainer) (
|
|||
}
|
||||
}
|
||||
|
||||
// Only do all this if we even have any messages.
|
||||
if len(m) > 0 {
|
||||
// Sort messages chronologically using the ID so that the oldest messages
|
||||
// (ones with the smallest snowflake) is in front.
|
||||
sort.Slice(m, func(i, j int) bool {
|
||||
return m[i].ID < m[j].ID
|
||||
})
|
||||
sort.Slice(m, func(i, j int) bool { return m[i].ID < m[j].ID })
|
||||
|
||||
// Iterate from the earliest messages to the latest messages.
|
||||
for _, m := range m {
|
||||
ct.CreateMessage(constructor(m))
|
||||
}
|
||||
|
||||
// Mark this channel as read.
|
||||
ch.session.ReadState.MarkRead(ch.id, m[len(m)-1].ID)
|
||||
}
|
||||
|
||||
// Bind the handler.
|
||||
addcancel(
|
||||
ch.session.AddHandler(func(m *gateway.MessageCreateEvent) {
|
||||
|
|
Loading…
Reference in a new issue