diff options
author | devonh <devon.dmytro@gmail.com> | 2023-07-06 19:50:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 19:50:28 +0000 |
commit | 3a125fd8fab320b09457e575d2ae286db84bc108 (patch) | |
tree | 17519471150e083ae9b7b96c35a3c08de8cf111b /syncapi | |
parent | d507c5fc9534f2d9e994ce8706f5d51ff192dfdf (diff) |
Fix prev event lookup in syncapi (#3141)
The syncapi operates using userID's so when querying for the previous
state event we need to lookup the userID from the given senderID before
the state query.
Diffstat (limited to 'syncapi')
-rw-r--r-- | syncapi/consumers/roomserver.go | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go index e6b5ddbb..7ba3afc4 100644 --- a/syncapi/consumers/roomserver.go +++ b/syncapi/consumers/roomserver.go @@ -558,29 +558,28 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *rstypes.HeaderedEvent) var succeeded bool defer sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err) - prevEvent, err := snapshot.GetStateEvent( - s.ctx, event.RoomID(), event.Type(), stateKey, - ) - if err != nil { - return event, err - } - validRoomID, err := spec.NewRoomID(event.RoomID()) if err != nil { return event, err } - if event.StateKey() != nil { - if *event.StateKey() != "" { - var sku *spec.UserID - sku, err = s.rsAPI.QueryUserIDForSender(s.ctx, *validRoomID, spec.SenderID(stateKey)) - if err == nil && sku != nil { - sKey := sku.String() - event.StateKeyResolved = &sKey - } + sKeyUser := "" + if stateKey != "" { + var sku *spec.UserID + sku, err = s.rsAPI.QueryUserIDForSender(s.ctx, *validRoomID, spec.SenderID(stateKey)) + if err == nil && sku != nil { + sKeyUser = sku.String() + event.StateKeyResolved = &sKeyUser } } + prevEvent, err := snapshot.GetStateEvent( + s.ctx, event.RoomID(), event.Type(), sKeyUser, + ) + if err != nil { + return event, err + } + userID, err := s.rsAPI.QueryUserIDForSender(s.ctx, *validRoomID, event.SenderID()) if err != nil { return event, err |