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,
|
joinedRoomIDs []string,
|
||||||
res *types.Response,
|
res *types.Response,
|
||||||
) error {
|
) error {
|
||||||
var jr types.JoinResponse
|
|
||||||
var ok bool
|
var ok bool
|
||||||
var err error
|
var err error
|
||||||
for _, roomID := range joinedRoomIDs {
|
for _, roomID := range joinedRoomIDs {
|
||||||
|
var jr types.JoinResponse
|
||||||
if typingUsers, updated := d.EDUCache.GetTypingUsersIfUpdatedAfter(
|
if typingUsers, updated := d.EDUCache.GetTypingUsersIfUpdatedAfter(
|
||||||
roomID, int64(since.EDUPosition()),
|
roomID, int64(since.EDUPosition()),
|
||||||
); updated {
|
); updated {
|
||||||
|
@ -574,9 +574,16 @@ func (d *Database) addReceiptDeltaToResponse(
|
||||||
joinedRoomIDs []string,
|
joinedRoomIDs []string,
|
||||||
res *types.Response,
|
res *types.Response,
|
||||||
) error {
|
) error {
|
||||||
var jr types.JoinResponse
|
// TODO: pass joinedRoomIDs to SelectRoomReceiptsAfter instead of iterating over every room
|
||||||
// check all joinedRooms for receipts
|
// check all joinedRooms for receipts
|
||||||
for _, roomID := range joinedRoomIDs {
|
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())
|
receipts, err := d.Receipts.SelectRoomReceiptsAfter(context.TODO(), roomID, since.EDUPosition())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -605,6 +612,11 @@ func (d *Database) addReceiptDeltaToResponse(
|
||||||
jr.Ephemeral.Events = append(jr.Ephemeral.Events, ev)
|
jr.Ephemeral.Events = append(jr.Ephemeral.Events, ev)
|
||||||
res.Rooms.Join[roomID] = jr
|
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
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue