Merge pull request #545 from ikkerens/patch-1

Added copy of previous Message state to MessageUpdate
This commit is contained in:
Skippy 2019-04-19 10:37:06 -05:00 committed by GitHub
commit 2748413597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 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

@ -882,6 +882,13 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
} }
case *MessageUpdate: case *MessageUpdate:
if s.MaxMessageCount != 0 { if s.MaxMessageCount != 0 {
var old *Message
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: