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.
This commit is contained in:
		
							parent
							
								
									a975c07ed4
								
							
						
					
					
						commit
						238c5addb3
					
				|  | @ -39,7 +39,16 @@ class SyncUpdate { | ||||||
|   Map<String, int>? deviceOneTimeKeysCount; |   Map<String, int>? deviceOneTimeKeysCount; | ||||||
|   List<String>? deviceUnusedFallbackKeyTypes; |   List<String>? 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<String, dynamic> json) |   SyncUpdate.fromJson(Map<String, dynamic> json) | ||||||
|       : nextBatch = json['next_batch'], |       : nextBatch = json['next_batch'], | ||||||
|  | @ -119,7 +128,7 @@ class RoomsUpdate { | ||||||
|   Map<String, InvitedRoomUpdate>? invite; |   Map<String, InvitedRoomUpdate>? invite; | ||||||
|   Map<String, LeftRoomUpdate>? leave; |   Map<String, LeftRoomUpdate>? leave; | ||||||
| 
 | 
 | ||||||
|   RoomsUpdate(); |   RoomsUpdate({this.join, this.invite, this.leave}); | ||||||
| 
 | 
 | ||||||
|   RoomsUpdate.fromJson(Map<String, dynamic> json) { |   RoomsUpdate.fromJson(Map<String, dynamic> json) { | ||||||
|     join = json['join'] != null |     join = json['join'] != null | ||||||
|  | @ -161,7 +170,14 @@ class JoinedRoomUpdate extends SyncRoomUpdate { | ||||||
|   List<BasicRoomEvent>? accountData; |   List<BasicRoomEvent>? accountData; | ||||||
|   UnreadNotificationCounts? unreadNotifications; |   UnreadNotificationCounts? unreadNotifications; | ||||||
| 
 | 
 | ||||||
|   JoinedRoomUpdate(); |   JoinedRoomUpdate({ | ||||||
|  |     this.summary, | ||||||
|  |     this.state, | ||||||
|  |     this.timeline, | ||||||
|  |     this.ephemeral, | ||||||
|  |     this.accountData, | ||||||
|  |     this.unreadNotifications, | ||||||
|  |   }); | ||||||
| 
 | 
 | ||||||
|   JoinedRoomUpdate.fromJson(Map<String, dynamic> json) { |   JoinedRoomUpdate.fromJson(Map<String, dynamic> json) { | ||||||
|     summary = |     summary = | ||||||
|  | @ -225,6 +241,8 @@ class JoinedRoomUpdate extends SyncRoomUpdate { | ||||||
| class InvitedRoomUpdate extends SyncRoomUpdate { | class InvitedRoomUpdate extends SyncRoomUpdate { | ||||||
|   List<StrippedStateEvent>? inviteState; |   List<StrippedStateEvent>? inviteState; | ||||||
| 
 | 
 | ||||||
|  |   InvitedRoomUpdate({this.inviteState}); | ||||||
|  | 
 | ||||||
|   InvitedRoomUpdate.fromJson(Map<String, dynamic> json) { |   InvitedRoomUpdate.fromJson(Map<String, dynamic> json) { | ||||||
|     inviteState = |     inviteState = | ||||||
|         (json['invite_state'] != null && json['invite_state']['events'] != null) |         (json['invite_state'] != null && json['invite_state']['events'] != null) | ||||||
|  | @ -250,7 +268,11 @@ class LeftRoomUpdate extends SyncRoomUpdate { | ||||||
|   TimelineUpdate? timeline; |   TimelineUpdate? timeline; | ||||||
|   List<BasicRoomEvent>? accountData; |   List<BasicRoomEvent>? accountData; | ||||||
| 
 | 
 | ||||||
|   LeftRoomUpdate(); |   LeftRoomUpdate({ | ||||||
|  |     this.state, | ||||||
|  |     this.timeline, | ||||||
|  |     this.accountData, | ||||||
|  |   }); | ||||||
| 
 | 
 | ||||||
|   LeftRoomUpdate.fromJson(Map<String, dynamic> json) { |   LeftRoomUpdate.fromJson(Map<String, dynamic> json) { | ||||||
|     state = (json['state'] != null && json['state']['events'] != null) |     state = (json['state'] != null && json['state']['events'] != null) | ||||||
|  | @ -293,7 +315,11 @@ class TimelineUpdate { | ||||||
|   bool? limited; |   bool? limited; | ||||||
|   String? prevBatch; |   String? prevBatch; | ||||||
| 
 | 
 | ||||||
|   TimelineUpdate(); |   TimelineUpdate({ | ||||||
|  |     this.events, | ||||||
|  |     this.limited, | ||||||
|  |     this.prevBatch, | ||||||
|  |   }); | ||||||
| 
 | 
 | ||||||
|   TimelineUpdate.fromJson(Map<String, dynamic> json) { |   TimelineUpdate.fromJson(Map<String, dynamic> json) { | ||||||
|     events = json['events'] != null |     events = json['events'] != null | ||||||
|  | @ -322,6 +348,11 @@ class UnreadNotificationCounts { | ||||||
|   int? highlightCount; |   int? highlightCount; | ||||||
|   int? notificationCount; |   int? notificationCount; | ||||||
| 
 | 
 | ||||||
|  |   UnreadNotificationCounts({ | ||||||
|  |     this.notificationCount, | ||||||
|  |     this.highlightCount, | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|   UnreadNotificationCounts.fromJson(Map<String, dynamic> json) { |   UnreadNotificationCounts.fromJson(Map<String, dynamic> json) { | ||||||
|     highlightCount = json['highlight_count']; |     highlightCount = json['highlight_count']; | ||||||
|     notificationCount = json['notification_count']; |     notificationCount = json['notification_count']; | ||||||
|  | @ -343,6 +374,11 @@ class DeviceListsUpdate { | ||||||
|   List<String>? changed; |   List<String>? changed; | ||||||
|   List<String>? left; |   List<String>? left; | ||||||
| 
 | 
 | ||||||
|  |   DeviceListsUpdate({ | ||||||
|  |     this.changed, | ||||||
|  |     this.left, | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|   DeviceListsUpdate.fromJson(Map<String, dynamic> json) { |   DeviceListsUpdate.fromJson(Map<String, dynamic> json) { | ||||||
|     changed = List<String>.from(json['changed'] ?? []); |     changed = List<String>.from(json['changed'] ?? []); | ||||||
|     left = List<String>.from(json['left'] ?? []); |     left = List<String>.from(json['left'] ?? []); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue