Merge branch 'krille/update_api' into 'main'
refactor: Update matrix_api_lite and use SyncUpdate constructors See merge request famedly/company/frontend/famedlysdk!887
This commit is contained in:
commit
be617ee974
|
|
@ -122,12 +122,20 @@ class Event extends MatrixEvent {
|
|||
final json = toJson();
|
||||
json['unsigned'] ??= <String, dynamic>{};
|
||||
json['unsigned'][messageSendingStatusKey] = EventStatus.error.intValue;
|
||||
room.client.handleSync(SyncUpdate(nextBatch: '')
|
||||
..rooms = (RoomsUpdate()
|
||||
..join = (<String, JoinedRoomUpdate>{}..[room.id] =
|
||||
(JoinedRoomUpdate()
|
||||
..timeline = (TimelineUpdate()
|
||||
..events = [MatrixEvent.fromJson(json)])))));
|
||||
room.client.handleSync(
|
||||
SyncUpdate(
|
||||
nextBatch: '',
|
||||
rooms: RoomsUpdate(
|
||||
join: {
|
||||
room.id: JoinedRoomUpdate(
|
||||
timeline: TimelineUpdate(
|
||||
events: [MatrixEvent.fromJson(json)],
|
||||
),
|
||||
)
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -517,16 +517,24 @@ class Room {
|
|||
/// set a read marker!
|
||||
Future<void> markUnread(bool unread) async {
|
||||
final content = MarkedUnread(unread).toJson();
|
||||
await _handleFakeSync(SyncUpdate(nextBatch: '')
|
||||
..rooms = (RoomsUpdate()
|
||||
..join = (({}..[id] = (JoinedRoomUpdate()
|
||||
..accountData = [
|
||||
BasicRoomEvent(
|
||||
content: content,
|
||||
roomId: id,
|
||||
type: EventType.markedUnread,
|
||||
await _handleFakeSync(
|
||||
SyncUpdate(
|
||||
nextBatch: '',
|
||||
rooms: RoomsUpdate(
|
||||
join: {
|
||||
id: JoinedRoomUpdate(
|
||||
accountData: [
|
||||
BasicRoomEvent(
|
||||
content: content,
|
||||
roomId: id,
|
||||
type: EventType.markedUnread,
|
||||
),
|
||||
],
|
||||
)
|
||||
])))));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await client.setAccountDataPerRoom(
|
||||
client.userID!,
|
||||
id,
|
||||
|
|
@ -795,23 +803,30 @@ class Room {
|
|||
}
|
||||
}
|
||||
final sentDate = DateTime.now();
|
||||
final syncUpdate = SyncUpdate(nextBatch: '')
|
||||
..rooms = (RoomsUpdate()
|
||||
..join = (<String, JoinedRoomUpdate>{}..[id] = (JoinedRoomUpdate()
|
||||
..timeline = (TimelineUpdate()
|
||||
..events = [
|
||||
MatrixEvent(
|
||||
content: content,
|
||||
type: type,
|
||||
eventId: messageID,
|
||||
senderId: client.userID!,
|
||||
originServerTs: sentDate,
|
||||
unsigned: {
|
||||
messageSendingStatusKey: EventStatus.sending.intValue,
|
||||
'transaction_id': messageID,
|
||||
},
|
||||
)
|
||||
]))));
|
||||
final syncUpdate = SyncUpdate(
|
||||
nextBatch: '',
|
||||
rooms: RoomsUpdate(
|
||||
join: {
|
||||
id: JoinedRoomUpdate(
|
||||
timeline: TimelineUpdate(
|
||||
events: [
|
||||
MatrixEvent(
|
||||
content: content,
|
||||
type: type,
|
||||
eventId: messageID,
|
||||
senderId: client.userID!,
|
||||
originServerTs: sentDate,
|
||||
unsigned: {
|
||||
messageSendingStatusKey: EventStatus.sending.intValue,
|
||||
'transaction_id': messageID,
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
await _handleFakeSync(syncUpdate);
|
||||
|
||||
// Send the text and on success, store and display a *sent* event.
|
||||
|
|
@ -881,11 +896,14 @@ class Room {
|
|||
if ([MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN]
|
||||
.contains(exception.error)) {
|
||||
await _handleFakeSync(
|
||||
SyncUpdate(nextBatch: '')
|
||||
..rooms = (RoomsUpdate()
|
||||
..leave = {
|
||||
'$id': (LeftRoomUpdate()),
|
||||
}),
|
||||
SyncUpdate(
|
||||
nextBatch: '',
|
||||
rooms: RoomsUpdate(
|
||||
leave: {
|
||||
id: LeftRoomUpdate(),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
rethrow;
|
||||
|
|
@ -955,24 +973,34 @@ class Room {
|
|||
if (!((resp.chunk?.isNotEmpty ?? false) && resp.end != null)) return;
|
||||
|
||||
await client.handleSync(
|
||||
SyncUpdate(nextBatch: '')
|
||||
..rooms = (RoomsUpdate()
|
||||
..join = membership == Membership.join
|
||||
? ({}..[id] = ((JoinedRoomUpdate()
|
||||
..state = resp.state
|
||||
..timeline = (TimelineUpdate()
|
||||
..limited = false
|
||||
..events = resp.chunk
|
||||
..prevBatch = resp.end))))
|
||||
: null
|
||||
..leave = membership != Membership.join
|
||||
? ({}..[id] = ((LeftRoomUpdate()
|
||||
..state = resp.state
|
||||
..timeline = (TimelineUpdate()
|
||||
..limited = false
|
||||
..events = resp.chunk
|
||||
..prevBatch = resp.end))))
|
||||
: null),
|
||||
SyncUpdate(
|
||||
nextBatch: '',
|
||||
rooms: RoomsUpdate(
|
||||
join: membership == Membership.join
|
||||
? {
|
||||
id: JoinedRoomUpdate(
|
||||
state: resp.state,
|
||||
timeline: TimelineUpdate(
|
||||
limited: false,
|
||||
events: resp.chunk,
|
||||
prevBatch: resp.end,
|
||||
),
|
||||
)
|
||||
}
|
||||
: null,
|
||||
leave: membership != Membership.join
|
||||
? {
|
||||
id: LeftRoomUpdate(
|
||||
state: resp.state,
|
||||
timeline: TimelineUpdate(
|
||||
limited: false,
|
||||
events: resp.chunk,
|
||||
prevBatch: resp.end,
|
||||
),
|
||||
),
|
||||
}
|
||||
: null),
|
||||
),
|
||||
sortAtTheEnd: true);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ dependencies:
|
|||
crypto: ^3.0.0
|
||||
base58check: ^2.0.0
|
||||
olm: ^2.0.0
|
||||
matrix_api_lite: ^0.4.3
|
||||
matrix_api_lite: ^0.5.1
|
||||
hive: ^2.0.4
|
||||
ffi: ^1.0.0
|
||||
js: ^0.6.3
|
||||
|
|
|
|||
|
|
@ -122,10 +122,12 @@ class FakeMatrixApi extends MockClient {
|
|||
action.contains('/account_data/') &&
|
||||
!action.contains('/room/')) {
|
||||
final type = Uri.decodeComponent(action.split('/').last);
|
||||
final syncUpdate = sdk.SyncUpdate(nextBatch: '')
|
||||
..accountData = [
|
||||
final syncUpdate = sdk.SyncUpdate(
|
||||
nextBatch: '',
|
||||
accountData: [
|
||||
sdk.BasicEvent(content: decodeJson(data), type: type)
|
||||
];
|
||||
],
|
||||
);
|
||||
if (client?.database != null) {
|
||||
await client?.database?.transaction(() async {
|
||||
await client?.handleSync(syncUpdate);
|
||||
|
|
|
|||
|
|
@ -306,18 +306,25 @@ void main() {
|
|||
});
|
||||
|
||||
test('Clear cache on limited timeline', () async {
|
||||
client.onSync.add(SyncUpdate(nextBatch: '1234')
|
||||
..rooms = (RoomsUpdate()
|
||||
..join = {
|
||||
roomID: (JoinedRoomUpdate()
|
||||
..timeline = (TimelineUpdate()
|
||||
..limited = true
|
||||
..prevBatch = 'blah')
|
||||
..unreadNotifications = UnreadNotificationCounts.fromJson({
|
||||
'highlight_count': 0,
|
||||
'notification_count': 0,
|
||||
}))
|
||||
}));
|
||||
client.onSync.add(
|
||||
SyncUpdate(
|
||||
nextBatch: '1234',
|
||||
rooms: RoomsUpdate(
|
||||
join: {
|
||||
roomID: JoinedRoomUpdate(
|
||||
timeline: TimelineUpdate(
|
||||
limited: true,
|
||||
prevBatch: 'blah',
|
||||
),
|
||||
unreadNotifications: UnreadNotificationCounts(
|
||||
highlightCount: 0,
|
||||
notificationCount: 0,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
expect(timeline.events.isEmpty, true);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue