Fix odd invite -> leave -> join dance when accepting invite

This commit is contained in:
Till Faelligen 2022-10-20 15:55:16 +02:00
parent 539c61b3db
commit 4c145af17c
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
2 changed files with 26 additions and 14 deletions

View file

@ -428,6 +428,13 @@ func (s *OutputRoomEventConsumer) onRetireInviteEvent(
return 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. // Notify any active sync requests that the invite has been retired.
s.inviteStream.Advance(pduPos) s.inviteStream.Advance(pduPos)
s.notifier.OnNewInvite(types.StreamingToken{InvitePosition: pduPos}, msg.TargetUserID) s.notifier.OnNewInvite(types.StreamingToken{InvitePosition: pduPos}, msg.TargetUserID)

View file

@ -74,7 +74,12 @@ func (p *InviteStreamProvider) IncrementalSync(
return to return to
} }
for roomID := range retiredInvites { for roomID := range retiredInvites {
if _, ok := req.Response.Rooms.Join[roomID]; !ok { if _, ok := req.Response.Rooms.Invite[roomID]; ok {
continue
}
if _, ok := req.Response.Rooms.Join[roomID]; ok {
continue
}
lr := types.NewLeaveResponse() lr := types.NewLeaveResponse()
h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...)) h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{ lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{
@ -88,7 +93,7 @@ func (p *InviteStreamProvider) IncrementalSync(
Content: gomatrixserverlib.RawJSON(`{"membership":"leave"}`), Content: gomatrixserverlib.RawJSON(`{"membership":"leave"}`),
}) })
req.Response.Rooms.Leave[roomID] = lr req.Response.Rooms.Leave[roomID] = lr
}
} }
return maxID return maxID