fix stream_invite regression (#50)

This commit is contained in:
Tak Wai Wong 2022-10-28 16:13:17 -07:00 committed by GitHub
parent ed8b5d09eb
commit bcf4ac9c9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,10 +7,9 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib"
) )
type InviteStreamProvider struct { type InviteStreamProvider struct {
@ -74,27 +73,43 @@ func (p *InviteStreamProvider) IncrementalSync(
return to return to
} }
for roomID := range retiredInvites { for roomID := range retiredInvites {
if _, ok := req.Response.Rooms.Invite[roomID]; ok { if req.Response.Rooms.Invite[roomID] != nil {
continue continue
} }
if _, ok := req.Response.Rooms.Join[roomID]; ok { if req.Response.Rooms.Join[roomID] != nil {
continue 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
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{
// 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 return maxID
} }
func contains(values []string, findVal string) bool {
for _, v := range values {
if v == findVal {
return true
}
}
return false
}