Merge pull request #2054 from famedly/td/setPrevBatchWhenInSync

fix: set prev_batch when seen in sync
This commit is contained in:
td 2025-03-18 08:25:36 +01:00 committed by GitHub
commit 3f4c9da90b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 3 deletions

View File

@ -594,7 +594,7 @@ class FakeMatrixApi extends BaseClient {
}
],
'limited': true,
'prev_batch': 't34-23535_0_0',
'prev_batch': 't44-23535_0_0',
},
'ephemeral': {
'events': [
@ -711,7 +711,7 @@ class FakeMatrixApi extends BaseClient {
},
],
'limited': true,
'prev_batch': 't34-23535_0_0',
'prev_batch': 't34-23535_0_1',
},
'account_data': {
'events': [

View File

@ -2989,7 +2989,9 @@ class Client extends MatrixApi {
chatUpdate.unreadNotifications?.notificationCount ?? 0;
rooms[roomIndex].highlightCount =
chatUpdate.unreadNotifications?.highlightCount ?? 0;
if (chatUpdate.timeline?.prevBatch != null) {
rooms[roomIndex].prev_batch = chatUpdate.timeline?.prevBatch;
}
final summary = chatUpdate.summary;
if (summary != null) {
final roomSummaryJson = rooms[roomIndex].summary.toJson()

View File

@ -761,6 +761,31 @@ void main() {
expect(room.lastEvent!.content['body'], '* foxies');
});
test('set prev_batch if in sync', () async {
final roomId = '!726s6s6q:example.com';
final room = matrix.getRoomById(roomId)!;
expect(room.prev_batch, 't44-23535_0_0');
// put an important state event in-memory
await matrix.handleSync(
SyncUpdate.fromJson({
'next_batch': 'fakesync',
'rooms': {
'join': {
roomId: {
'timeline': {
'events': [],
'prev_batch': 'prev_batch_1',
},
},
},
},
}),
);
expect(room.prev_batch, 'prev_batch_1');
});
test('getProfileFromUserId', () async {
final cachedProfile = await matrix.getUserProfile('@getme:example.com');
expect(cachedProfile.outdated, false);