mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-22 05:23:09 -06:00
* fix #2838 by querying db directly for membership info * fix lint error * revert changes and use SelectMembershipForUser directly * Remove extra membership checks * Add a comment to explain why the membership check is necessary
This commit is contained in:
parent
f2d6888452
commit
86f9b5ca89
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
|
@ -73,19 +74,14 @@ func (p *InviteStreamProvider) IncrementalSync(
|
|||
return to
|
||||
}
|
||||
for roomID := range retiredInvites {
|
||||
if req.Response.Rooms.Invite[roomID] != nil {
|
||||
continue
|
||||
}
|
||||
if req.Response.Rooms.Join[roomID] != nil {
|
||||
membership, _, err := snapshot.SelectMembershipForUser(ctx, roomID, req.Device.UserID, math.MaxInt64)
|
||||
// Skip if the user is an existing member of the room.
|
||||
// Otherwise, the NewLeaveResponse will eject the user from the room unintentionally
|
||||
if membership == gomatrixserverlib.Join ||
|
||||
err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
joinedUsers, err := snapshot.AllJoinedUsersInRoom(ctx, []string{roomID})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if !contains(joinedUsers[roomID], req.Device.UserID) {
|
||||
lr := types.NewLeaveResponse()
|
||||
h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
|
||||
lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{
|
||||
|
|
@ -100,16 +96,6 @@ func (p *InviteStreamProvider) IncrementalSync(
|
|||
})
|
||||
req.Response.Rooms.Leave[roomID] = lr
|
||||
}
|
||||
}
|
||||
|
||||
return maxID
|
||||
}
|
||||
|
||||
func contains(values []string, findVal string) bool {
|
||||
for _, v := range values {
|
||||
if v == findVal {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue