From 238c5addb3d5db76699ff2a4d942c7f5f16dbd85 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Wed, 10 Nov 2021 09:31:02 +0100 Subject: [PATCH] feat: Add constructors to SyncUpdate classes In the SDK we have multiple points where we use fake syncs to update the data model. This constructors would make it much easier to work with them. --- lib/src/model/sync_update.dart | 46 ++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/src/model/sync_update.dart b/lib/src/model/sync_update.dart index 878b9343..09b015d9 100644 --- a/lib/src/model/sync_update.dart +++ b/lib/src/model/sync_update.dart @@ -39,7 +39,16 @@ class SyncUpdate { Map? deviceOneTimeKeysCount; List? deviceUnusedFallbackKeyTypes; - SyncUpdate({required this.nextBatch}); + SyncUpdate({ + required this.nextBatch, + this.rooms, + this.presence, + this.accountData, + this.toDevice, + this.deviceLists, + this.deviceOneTimeKeysCount, + this.deviceUnusedFallbackKeyTypes, + }); SyncUpdate.fromJson(Map json) : nextBatch = json['next_batch'], @@ -119,7 +128,7 @@ class RoomsUpdate { Map? invite; Map? leave; - RoomsUpdate(); + RoomsUpdate({this.join, this.invite, this.leave}); RoomsUpdate.fromJson(Map json) { join = json['join'] != null @@ -161,7 +170,14 @@ class JoinedRoomUpdate extends SyncRoomUpdate { List? accountData; UnreadNotificationCounts? unreadNotifications; - JoinedRoomUpdate(); + JoinedRoomUpdate({ + this.summary, + this.state, + this.timeline, + this.ephemeral, + this.accountData, + this.unreadNotifications, + }); JoinedRoomUpdate.fromJson(Map json) { summary = @@ -225,6 +241,8 @@ class JoinedRoomUpdate extends SyncRoomUpdate { class InvitedRoomUpdate extends SyncRoomUpdate { List? inviteState; + InvitedRoomUpdate({this.inviteState}); + InvitedRoomUpdate.fromJson(Map json) { inviteState = (json['invite_state'] != null && json['invite_state']['events'] != null) @@ -250,7 +268,11 @@ class LeftRoomUpdate extends SyncRoomUpdate { TimelineUpdate? timeline; List? accountData; - LeftRoomUpdate(); + LeftRoomUpdate({ + this.state, + this.timeline, + this.accountData, + }); LeftRoomUpdate.fromJson(Map json) { state = (json['state'] != null && json['state']['events'] != null) @@ -293,7 +315,11 @@ class TimelineUpdate { bool? limited; String? prevBatch; - TimelineUpdate(); + TimelineUpdate({ + this.events, + this.limited, + this.prevBatch, + }); TimelineUpdate.fromJson(Map json) { events = json['events'] != null @@ -322,6 +348,11 @@ class UnreadNotificationCounts { int? highlightCount; int? notificationCount; + UnreadNotificationCounts({ + this.notificationCount, + this.highlightCount, + }); + UnreadNotificationCounts.fromJson(Map json) { highlightCount = json['highlight_count']; notificationCount = json['notification_count']; @@ -343,6 +374,11 @@ class DeviceListsUpdate { List? changed; List? left; + DeviceListsUpdate({ + this.changed, + this.left, + }); + DeviceListsUpdate.fromJson(Map json) { changed = List.from(json['changed'] ?? []); left = List.from(json['left'] ?? []);