Fixed several bugs related to channel orders and message edits

This commit is contained in:
diamondburned 2020-07-09 16:15:58 -07:00
parent 1e137df6de
commit 5b88b577fb
3 changed files with 19 additions and 4 deletions

View File

@ -254,7 +254,7 @@ func (ch *Channel) JoinServer(ctx context.Context, ct cchat.MessagesContainer) (
ch.session.AddHandler(func(m *gateway.MessageUpdateEvent) {
// If the updated content is empty. TODO: add embed support.
if m.ChannelID == ch.id && m.Content != "" {
ct.UpdateMessage(NewMessageUpdateContent(m.Message))
ct.UpdateMessage(NewMessageUpdateContent(m.Message, ch.session))
}
}),
ch.session.AddHandler(func(m *gateway.MessageDeleteEvent) {

View File

@ -158,10 +158,16 @@ func (g *Guild) Servers(container cchat.ServersContainer) error {
// Only get top-level channels (those with category ID being null).
var toplevels = filterAccessible(g.session, filterCategory(c, discord.NullSnowflake))
sort.Slice(toplevels, func(i, j int) bool {
// Sort so that positions are correct.
sort.SliceStable(toplevels, func(i, j int) bool {
return toplevels[i].Position < toplevels[j].Position
})
// Sort so that channels are before categories.
sort.SliceStable(toplevels, func(i, _ int) bool {
return toplevels[i].Type != discord.GuildCategory
})
var chs = make([]cchat.Server, 0, len(toplevels))
for _, ch := range toplevels {

View File

@ -121,10 +121,19 @@ type Message struct {
mentioned bool
}
func NewMessageUpdateContent(msg discord.Message) Message {
func NewMessageUpdateContent(msg discord.Message, s *Session) Message {
// Check if content is empty.
if msg.Content == "" {
// Then grab the content from the state.
m, err := s.Store.Message(msg.ChannelID, msg.ID)
if err == nil {
msg.Content = m.Content
}
}
return Message{
messageHeader: newHeader(msg),
content: text.Rich{Content: msg.Content},
content: segments.ParseMessage(&msg, s.Store),
}
}