mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-12-02 11:11:56 -06:00
Better creation/usage of JoinResponse
This commit is contained in:
parent
c428d52652
commit
9d480d58c9
|
@ -540,10 +540,10 @@ func (d *Database) addTypingDeltaToResponse(
|
|||
joinedRoomIDs []string,
|
||||
res *types.Response,
|
||||
) error {
|
||||
var jr types.JoinResponse
|
||||
var ok bool
|
||||
var err error
|
||||
for _, roomID := range joinedRoomIDs {
|
||||
var jr types.JoinResponse
|
||||
if typingUsers, updated := d.EDUCache.GetTypingUsersIfUpdatedAfter(
|
||||
roomID, int64(since.EDUPosition()),
|
||||
); updated {
|
||||
|
@ -574,9 +574,16 @@ func (d *Database) addReceiptDeltaToResponse(
|
|||
joinedRoomIDs []string,
|
||||
res *types.Response,
|
||||
) error {
|
||||
var jr types.JoinResponse
|
||||
// TODO: pass joinedRoomIDs to SelectRoomReceiptsAfter instead of iterating over every room
|
||||
// check all joinedRooms for receipts
|
||||
for _, roomID := range joinedRoomIDs {
|
||||
var jr types.JoinResponse
|
||||
var ok bool
|
||||
// Check if there's already a JoinResponse for this room,
|
||||
// otherwise use a new one
|
||||
if jr, ok = res.Rooms.Join[roomID]; !ok {
|
||||
jr = types.JoinResponse{}
|
||||
}
|
||||
receipts, err := d.Receipts.SelectRoomReceiptsAfter(context.TODO(), roomID, since.EDUPosition())
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -605,6 +612,11 @@ func (d *Database) addReceiptDeltaToResponse(
|
|||
jr.Ephemeral.Events = append(jr.Ephemeral.Events, ev)
|
||||
res.Rooms.Join[roomID] = jr
|
||||
}
|
||||
// Only add new events if we didn't find the room in the map.
|
||||
// If we found the room, they should already be added
|
||||
if !ok {
|
||||
res.Rooms.Join[roomID] = jr
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue