mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-12-02 03:01:57 -06:00
add peeking to getResponseWithPDUsForCompleteSync
This commit is contained in:
parent
d1e4d66126
commit
f006b37bf0
|
@ -644,7 +644,7 @@ func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, reda
|
||||||
// nolint:nakedret
|
// nolint:nakedret
|
||||||
func (d *Database) getResponseWithPDUsForCompleteSync(
|
func (d *Database) getResponseWithPDUsForCompleteSync(
|
||||||
ctx context.Context, res *types.Response,
|
ctx context.Context, res *types.Response,
|
||||||
userID string,
|
userID string, deviceID string,
|
||||||
numRecentEventsPerRoom int,
|
numRecentEventsPerRoom int,
|
||||||
) (
|
) (
|
||||||
toPos types.StreamingToken,
|
toPos types.StreamingToken,
|
||||||
|
@ -684,8 +684,49 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
|
||||||
|
|
||||||
// Build up a /sync response. Add joined rooms.
|
// Build up a /sync response. Add joined rooms.
|
||||||
for _, roomID := range joinedRoomIDs {
|
for _, roomID := range joinedRoomIDs {
|
||||||
|
var jr *types.JoinResponse
|
||||||
|
jr, err = d.getJoinResponseForCompleteSync(
|
||||||
|
ctx, txn, roomID, r, &stateFilter, numRecentEventsPerRoom,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res.Rooms.Join[roomID] = *jr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add peeked rooms.
|
||||||
|
peeks, err := d.Peeks.SelectPeeks(ctx, txn, userID, deviceID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, peek := range peeks {
|
||||||
|
var jr *types.JoinResponse
|
||||||
|
jr, err = d.getJoinResponseForCompleteSync(
|
||||||
|
ctx, txn, peek.RoomID, r, &stateFilter, numRecentEventsPerRoom,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res.Rooms.Peek[peek.RoomID] = *jr
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = d.addInvitesToResponse(ctx, txn, userID, r, res); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
succeeded = true
|
||||||
|
return //res, toPos, joinedRoomIDs, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d* Database) getJoinResponseForCompleteSync(
|
||||||
|
ctx context.Context, txn *sql.Tx,
|
||||||
|
roomID string,
|
||||||
|
r types.Range,
|
||||||
|
stateFilter *gomatrixserverlib.StateFilter,
|
||||||
|
numRecentEventsPerRoom int,
|
||||||
|
) (jr *types.JoinResponse, err error) {
|
||||||
var stateEvents []gomatrixserverlib.HeaderedEvent
|
var stateEvents []gomatrixserverlib.HeaderedEvent
|
||||||
stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, txn, roomID, &stateFilter)
|
stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, txn, roomID, stateFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -718,20 +759,12 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
|
||||||
// transaction IDs for complete syncs
|
// transaction IDs for complete syncs
|
||||||
recentEvents := d.StreamEventsToEvents(nil, recentStreamEvents)
|
recentEvents := d.StreamEventsToEvents(nil, recentStreamEvents)
|
||||||
stateEvents = removeDuplicates(stateEvents, recentEvents)
|
stateEvents = removeDuplicates(stateEvents, recentEvents)
|
||||||
jr := types.NewJoinResponse()
|
jr = types.NewJoinResponse()
|
||||||
jr.Timeline.PrevBatch = prevBatchStr
|
jr.Timeline.PrevBatch = prevBatchStr
|
||||||
jr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
|
jr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
|
||||||
jr.Timeline.Limited = limited
|
jr.Timeline.Limited = limited
|
||||||
jr.State.Events = gomatrixserverlib.HeaderedToClientEvents(stateEvents, gomatrixserverlib.FormatSync)
|
jr.State.Events = gomatrixserverlib.HeaderedToClientEvents(stateEvents, gomatrixserverlib.FormatSync)
|
||||||
res.Rooms.Join[roomID] = *jr
|
return jr, nil
|
||||||
}
|
|
||||||
|
|
||||||
if err = d.addInvitesToResponse(ctx, txn, userID, r, res); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
succeeded = true
|
|
||||||
return //res, toPos, joinedRoomIDs, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) CompleteSync(
|
func (d *Database) CompleteSync(
|
||||||
|
@ -739,7 +772,7 @@ func (d *Database) CompleteSync(
|
||||||
device userapi.Device, numRecentEventsPerRoom int,
|
device userapi.Device, numRecentEventsPerRoom int,
|
||||||
) (*types.Response, error) {
|
) (*types.Response, error) {
|
||||||
toPos, joinedRoomIDs, err := d.getResponseWithPDUsForCompleteSync(
|
toPos, joinedRoomIDs, err := d.getResponseWithPDUsForCompleteSync(
|
||||||
ctx, res, device.UserID, numRecentEventsPerRoom,
|
ctx, res, device.UserID, device.ID, numRecentEventsPerRoom,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("d.getResponseWithPDUsForCompleteSync: %w", err)
|
return nil, fmt.Errorf("d.getResponseWithPDUsForCompleteSync: %w", err)
|
||||||
|
|
Loading…
Reference in a new issue