Fix bug that caused messages sent while a channel wasn't loaded yet to be lost
@@ -2279,7 +2279,9 @@ func (window *Window) LoadChannel(channel *discordgo.Channel) error {
}
var discordError error
- messages, discordError = window.session.ChannelMessages(channel.ID, 100-localMessageCount, beforeID, "", "")
+ messagesToGet := 100 - localMessageCount
+ if messagesToGet > 0 {
+ messages, discordError = window.session.ChannelMessages(channel.ID, messagesToGet, beforeID, "", "")
if discordError == nil {
if channel.GuildID != "" {
for _, message := range messages {
@@ -2294,10 +2296,10 @@ func (window *Window) LoadChannel(channel *discordgo.Channel) error {
channel.Messages = append(messages, channel.Messages...)
}
}
- } else {
- messages = channel.Messages
}
}
+ messages = channel.Messages
+ }
discordutil.SortMessagesByTimestamp(messages)
