mirror of https://github.com/matrix-org/gomatrix
Check that event is a state event.
This commit is contained in:
parent
7e21d59dca
commit
06ec893403
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
// Event represents a single Matrix event.
|
// Event represents a single Matrix event.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
StateKey string `json:"state_key"` // The state key for the event. Only present on State Events.
|
StateKey *string `json:"state_key,omitempty"` // The state key for the event. Only present on State Events.
|
||||||
Sender string `json:"sender"` // The user ID of the sender of the event
|
Sender string `json:"sender"` // The user ID of the sender of the event
|
||||||
Type string `json:"type"` // The event type
|
Type string `json:"type"` // The event type
|
||||||
Timestamp int `json:"origin_server_ts"` // The unix timestamp when this message was sent by the origin server
|
Timestamp int `json:"origin_server_ts"` // The unix timestamp when this message was sent by the origin server
|
||||||
|
|
2
room.go
2
room.go
|
@ -13,7 +13,7 @@ func (room Room) UpdateState(event *Event) {
|
||||||
if !exists {
|
if !exists {
|
||||||
room.State[event.Type] = make(map[string]*Event)
|
room.State[event.Type] = make(map[string]*Event)
|
||||||
}
|
}
|
||||||
room.State[event.Type][event.StateKey] = event
|
room.State[event.Type][*event.StateKey] = event
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStateEvent returns the state event for the given type/state_key combo, or nil.
|
// GetStateEvent returns the state event for the given type/state_key combo, or nil.
|
||||||
|
|
4
sync.go
4
sync.go
|
@ -76,11 +76,13 @@ func (s *DefaultSyncer) ProcessResponse(res *RespSync, since string) (err error)
|
||||||
for roomID, roomData := range res.Rooms.Leave {
|
for roomID, roomData := range res.Rooms.Leave {
|
||||||
room := s.getOrCreateRoom(roomID)
|
room := s.getOrCreateRoom(roomID)
|
||||||
for _, event := range roomData.Timeline.Events {
|
for _, event := range roomData.Timeline.Events {
|
||||||
|
if event.StateKey != nil {
|
||||||
event.RoomID = roomID
|
event.RoomID = roomID
|
||||||
room.UpdateState(&event)
|
room.UpdateState(&event)
|
||||||
s.notifyListeners(&event)
|
s.notifyListeners(&event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +112,7 @@ func (s *DefaultSyncer) shouldProcessResponse(resp *RespSync, since string) bool
|
||||||
for roomID, roomData := range resp.Rooms.Join {
|
for roomID, roomData := range resp.Rooms.Join {
|
||||||
for i := len(roomData.Timeline.Events) - 1; i >= 0; i-- {
|
for i := len(roomData.Timeline.Events) - 1; i >= 0; i-- {
|
||||||
e := roomData.Timeline.Events[i]
|
e := roomData.Timeline.Events[i]
|
||||||
if e.Type == "m.room.member" && e.StateKey == s.UserID {
|
if e.Type == "m.room.member" && *e.StateKey == s.UserID {
|
||||||
m := e.Content["membership"]
|
m := e.Content["membership"]
|
||||||
mship, ok := m.(string)
|
mship, ok := m.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue