Added copy of previous Message state to MessageUpdate

This commit is contained in:
Rens Rikkerink 2018-05-09 14:18:30 +02:00
parent 82c8cf21b2
commit 4cc57c5070
No known key found for this signature in database
GPG key ID: 204C7F94FBEC05FC
2 changed files with 8 additions and 0 deletions

View file

@ -162,6 +162,8 @@ type MessageCreate struct {
// MessageUpdate is the data for a MessageUpdate event. // MessageUpdate is the data for a MessageUpdate event.
type MessageUpdate struct { type MessageUpdate struct {
*Message *Message
// BeforeUpdate will be nil if the Message was not previously cached in the state cache.
BeforeUpdate *Message `json:"-"`
} }
// MessageDelete is the data for a MessageDelete event. // MessageDelete is the data for a MessageDelete event.

View file

@ -863,6 +863,12 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
} }
case *MessageUpdate: case *MessageUpdate:
if s.MaxMessageCount != 0 { if s.MaxMessageCount != 0 {
old, err := s.Message(t.ChannelID, t.ID)
if err == nil {
oldCopy := *old
t.BeforeUpdate = &oldCopy
}
err = s.MessageAdd(t.Message) err = s.MessageAdd(t.Message)
} }
case *MessageDelete: case *MessageDelete: