Browse Source

Added copy of previous Message state to MessageUpdate

Rens Rikkerink 6 years ago
parent
commit
4cc57c5070
2 changed files with 8 additions and 0 deletions
  1. 2 0
      events.go
  2. 6 0
      state.go

+ 2 - 0
events.go

@@ -162,6 +162,8 @@ type MessageCreate struct {
 // MessageUpdate is the data for a MessageUpdate event.
 type MessageUpdate struct {
 	*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.

+ 6 - 0
state.go

@@ -863,6 +863,12 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
 		}
 	case *MessageUpdate:
 		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)
 		}
 	case *MessageDelete: