aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-10-21 10:26:22 +0200
committerGitHub <noreply@github.com>2022-10-21 09:26:22 +0100
commit40cfb9a4ea23f1c9214553255feb296c2578b213 (patch)
treeb13101f9a52be52755720f3b1e6d14a6eb43bed5 /syncapi
parent73e02463cf6e267fdba950d0d231f98f95bc7994 (diff)
Fix `invite -> leave -> join` dance when accepting invites (#2817)
As mentioned in https://github.com/matrix-org/dendrite/issues/2361#issuecomment-1139394565 and observed by ourselves, this should fix the odd `invite -> leave -> join` dance when accepting invites.
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/consumers/roomserver.go7
-rw-r--r--syncapi/streams/stream_invite.go33
2 files changed, 26 insertions, 14 deletions
diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go
index cfbb0532..f767615c 100644
--- a/syncapi/consumers/roomserver.go
+++ b/syncapi/consumers/roomserver.go
@@ -428,6 +428,13 @@ func (s *OutputRoomEventConsumer) onRetireInviteEvent(
return
}
+ // Only notify clients about retired invite events, if the user didn't accept the invite.
+ // The PDU stream will also receive an event about accepting the invitation, so there should
+ // be a "smooth" transition from invite -> join, and not invite -> leave -> join
+ if msg.Membership == gomatrixserverlib.Join {
+ return
+ }
+
// Notify any active sync requests that the invite has been retired.
s.inviteStream.Advance(pduPos)
s.notifier.OnNewInvite(types.StreamingToken{InvitePosition: pduPos}, msg.TargetUserID)
diff --git a/syncapi/streams/stream_invite.go b/syncapi/streams/stream_invite.go
index 7875ffa3..700f25c1 100644
--- a/syncapi/streams/stream_invite.go
+++ b/syncapi/streams/stream_invite.go
@@ -74,21 +74,26 @@ func (p *InviteStreamProvider) IncrementalSync(
return to
}
for roomID := range retiredInvites {
- if _, ok := req.Response.Rooms.Join[roomID]; !ok {
- lr := types.NewLeaveResponse()
- h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
- lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{
- // fake event ID which muxes in the to position
- EventID: "$" + base64.RawURLEncoding.EncodeToString(h[:]),
- OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
- RoomID: roomID,
- Sender: req.Device.UserID,
- StateKey: &req.Device.UserID,
- Type: "m.room.member",
- Content: gomatrixserverlib.RawJSON(`{"membership":"leave"}`),
- })
- req.Response.Rooms.Leave[roomID] = lr
+ if _, ok := req.Response.Rooms.Invite[roomID]; ok {
+ continue
+ }
+ if _, ok := req.Response.Rooms.Join[roomID]; ok {
+ continue
}
+ lr := types.NewLeaveResponse()
+ h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
+ lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{
+ // fake event ID which muxes in the to position
+ EventID: "$" + base64.RawURLEncoding.EncodeToString(h[:]),
+ OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
+ RoomID: roomID,
+ Sender: req.Device.UserID,
+ StateKey: &req.Device.UserID,
+ Type: "m.room.member",
+ Content: gomatrixserverlib.RawJSON(`{"membership":"leave"}`),
+ })
+ req.Response.Rooms.Leave[roomID] = lr
+
}
return maxID