fix models

This commit is contained in:
Salvatore Giordano
2021-04-13 15:48:05 +02:00
parent fe07b8dbb0
commit 97c35371af
29 changed files with 193 additions and 308 deletions
+1 -2
View File
@@ -4,5 +4,4 @@ targets:
json_serializable: json_serializable:
options: options:
explicit_to_json: true explicit_to_json: true
field_rename: snake field_rename: snake
any_map: true
@@ -1830,7 +1830,7 @@ class ChannelClientState {
final now = DateTime.now(); final now = DateTime.now();
var expiredMessages = channelState!.pinnedMessages var expiredMessages = channelState!.pinnedMessages
.where((m) => m.pinExpires?.isBefore(now) == true) .where((m) => m.pinExpires?.isBefore(now) == true)
.toList(); .toList();
if (expiredMessages.isNotEmpty) { if (expiredMessages.isNotEmpty) {
expiredMessages = expiredMessages expiredMessages = expiredMessages
.map((m) => m.copyWith( .map((m) => m.copyWith(
@@ -106,6 +106,7 @@ class PaginationParams {
); );
@override @override
@JsonKey(ignore: true)
int get hashCode => int get hashCode =>
runtimeType.hashCode ^ runtimeType.hashCode ^
limit.hashCode ^ limit.hashCode ^
@@ -28,6 +28,5 @@ Map<String, dynamic> _$PaginationParamsToJson(PaginationParams instance) {
writeNotNull('id_gte', instance.greaterThanOrEqual); writeNotNull('id_gte', instance.greaterThanOrEqual);
writeNotNull('id_lt', instance.lessThan); writeNotNull('id_lt', instance.lessThan);
writeNotNull('id_lte', instance.lessThanOrEqual); writeNotNull('id_lte', instance.lessThanOrEqual);
val['hash_code'] = instance.hashCode;
return val; return val;
} }
+81 -132
View File
@@ -6,17 +6,16 @@ part of 'responses.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
SyncResponse _$SyncResponseFromJson(Map json) { SyncResponse _$SyncResponseFromJson(Map<String, dynamic> json) {
return SyncResponse() return SyncResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..events = (json['events'] as List<dynamic>?) ..events = (json['events'] as List<dynamic>?)
?.map((e) => Event.fromJson((e as Map?)?.map( ?.map((e) => Event.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(); .toList();
} }
QueryChannelsResponse _$QueryChannelsResponseFromJson(Map json) { QueryChannelsResponse _$QueryChannelsResponseFromJson(
Map<String, dynamic> json) {
return QueryChannelsResponse() return QueryChannelsResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channels = (json['channels'] as List<dynamic>?) ..channels = (json['channels'] as List<dynamic>?)
@@ -24,148 +23,127 @@ QueryChannelsResponse _$QueryChannelsResponseFromJson(Map json) {
.toList(); .toList();
} }
TranslateMessageResponse _$TranslateMessageResponseFromJson(Map json) { TranslateMessageResponse _$TranslateMessageResponseFromJson(
Map<String, dynamic> json) {
return TranslateMessageResponse() return TranslateMessageResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: TranslatedMessage.fromJson((json['message'] as Map?)?.map( : TranslatedMessage.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
QueryMembersResponse _$QueryMembersResponseFromJson(Map json) { QueryMembersResponse _$QueryMembersResponseFromJson(Map<String, dynamic> json) {
return QueryMembersResponse() return QueryMembersResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList(); .toList();
} }
QueryUsersResponse _$QueryUsersResponseFromJson(Map json) { QueryUsersResponse _$QueryUsersResponseFromJson(Map<String, dynamic> json) {
return QueryUsersResponse() return QueryUsersResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..users = (json['users'] as List<dynamic>?) ..users = (json['users'] as List<dynamic>?)
?.map((e) => User.fromJson((e as Map?)?.map( ?.map((e) => User.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(); .toList();
} }
QueryReactionsResponse _$QueryReactionsResponseFromJson(Map json) { QueryReactionsResponse _$QueryReactionsResponseFromJson(
Map<String, dynamic> json) {
return QueryReactionsResponse() return QueryReactionsResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..reactions = (json['reactions'] as List<dynamic>?) ..reactions = (json['reactions'] as List<dynamic>?)
?.map((e) => Reaction.fromJson((e as Map?)?.map( ?.map((e) => Reaction.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(); .toList();
} }
QueryRepliesResponse _$QueryRepliesResponseFromJson(Map json) { QueryRepliesResponse _$QueryRepliesResponseFromJson(Map<String, dynamic> json) {
return QueryRepliesResponse() return QueryRepliesResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..messages = (json['messages'] as List<dynamic>?) ..messages = (json['messages'] as List<dynamic>?)
?.map((e) => Message.fromJson((e as Map?)?.map( ?.map((e) => Message.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(); .toList();
} }
ListDevicesResponse _$ListDevicesResponseFromJson(Map json) { ListDevicesResponse _$ListDevicesResponseFromJson(Map<String, dynamic> json) {
return ListDevicesResponse() return ListDevicesResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..devices = (json['devices'] as List<dynamic>?) ..devices = (json['devices'] as List<dynamic>?)
?.map((e) => Device.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Device.fromJson(e as Map<String, dynamic>))
.toList(); .toList();
} }
SendFileResponse _$SendFileResponseFromJson(Map json) { SendFileResponse _$SendFileResponseFromJson(Map<String, dynamic> json) {
return SendFileResponse() return SendFileResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..file = json['file'] as String?; ..file = json['file'] as String?;
} }
SendImageResponse _$SendImageResponseFromJson(Map json) { SendImageResponse _$SendImageResponseFromJson(Map<String, dynamic> json) {
return SendImageResponse() return SendImageResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..file = json['file'] as String?; ..file = json['file'] as String?;
} }
SendReactionResponse _$SendReactionResponseFromJson(Map json) { SendReactionResponse _$SendReactionResponseFromJson(Map<String, dynamic> json) {
return SendReactionResponse() return SendReactionResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..reaction = json['reaction'] == null ..reaction = json['reaction'] == null
? null ? null
: Reaction.fromJson((json['reaction'] as Map?)?.map( : Reaction.fromJson(json['reaction'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
ConnectGuestUserResponse _$ConnectGuestUserResponseFromJson(Map json) { ConnectGuestUserResponse _$ConnectGuestUserResponseFromJson(
Map<String, dynamic> json) {
return ConnectGuestUserResponse() return ConnectGuestUserResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..accessToken = json['access_token'] as String? ..accessToken = json['access_token'] as String?
..user = json['user'] == null ..user = json['user'] == null
? null ? null
: User.fromJson((json['user'] as Map?)?.map( : User.fromJson(json['user'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
UpdateUsersResponse _$UpdateUsersResponseFromJson(Map json) { UpdateUsersResponse _$UpdateUsersResponseFromJson(Map<String, dynamic> json) {
return UpdateUsersResponse() return UpdateUsersResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..users = (json['users'] as Map?)?.map( ..users = (json['users'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry( (k, e) => MapEntry(k, User.fromJson(e as Map<String, dynamic>?)),
k as String,
User.fromJson((e as Map?)?.map(
(k, e) => MapEntry(k as String, e),
))),
); );
} }
UpdateMessageResponse _$UpdateMessageResponseFromJson(Map json) { UpdateMessageResponse _$UpdateMessageResponseFromJson(
Map<String, dynamic> json) {
return UpdateMessageResponse() return UpdateMessageResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
SendMessageResponse _$SendMessageResponseFromJson(Map json) { SendMessageResponse _$SendMessageResponseFromJson(Map<String, dynamic> json) {
return SendMessageResponse() return SendMessageResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
GetMessageResponse _$GetMessageResponseFromJson(Map json) { GetMessageResponse _$GetMessageResponseFromJson(Map<String, dynamic> json) {
return GetMessageResponse() return GetMessageResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
SearchMessagesResponse _$SearchMessagesResponseFromJson(Map json) { SearchMessagesResponse _$SearchMessagesResponseFromJson(
Map<String, dynamic> json) {
return SearchMessagesResponse() return SearchMessagesResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..results = (json['results'] as List<dynamic>?) ..results = (json['results'] as List<dynamic>?)
@@ -173,169 +151,140 @@ SearchMessagesResponse _$SearchMessagesResponseFromJson(Map json) {
.toList(); .toList();
} }
GetMessagesByIdResponse _$GetMessagesByIdResponseFromJson(Map json) { GetMessagesByIdResponse _$GetMessagesByIdResponseFromJson(
Map<String, dynamic> json) {
return GetMessagesByIdResponse() return GetMessagesByIdResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..messages = (json['messages'] as List<dynamic>?) ..messages = (json['messages'] as List<dynamic>?)
?.map((e) => Message.fromJson((e as Map?)?.map( ?.map((e) => Message.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(); .toList();
} }
UpdateChannelResponse _$UpdateChannelResponseFromJson(Map json) { UpdateChannelResponse _$UpdateChannelResponseFromJson(
Map<String, dynamic> json) {
return UpdateChannelResponse() return UpdateChannelResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() .toList()
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
PartialUpdateChannelResponse _$PartialUpdateChannelResponseFromJson(Map json) { PartialUpdateChannelResponse _$PartialUpdateChannelResponseFromJson(
Map<String, dynamic> json) {
return PartialUpdateChannelResponse() return PartialUpdateChannelResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList(); .toList();
} }
InviteMembersResponse _$InviteMembersResponseFromJson(Map json) { InviteMembersResponse _$InviteMembersResponseFromJson(
Map<String, dynamic> json) {
return InviteMembersResponse() return InviteMembersResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() .toList()
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
RemoveMembersResponse _$RemoveMembersResponseFromJson(Map json) { RemoveMembersResponse _$RemoveMembersResponseFromJson(
Map<String, dynamic> json) {
return RemoveMembersResponse() return RemoveMembersResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() .toList()
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
SendActionResponse _$SendActionResponseFromJson(Map json) { SendActionResponse _$SendActionResponseFromJson(Map<String, dynamic> json) {
return SendActionResponse() return SendActionResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
AddMembersResponse _$AddMembersResponseFromJson(Map json) { AddMembersResponse _$AddMembersResponseFromJson(Map<String, dynamic> json) {
return AddMembersResponse() return AddMembersResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() .toList()
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
AcceptInviteResponse _$AcceptInviteResponseFromJson(Map json) { AcceptInviteResponse _$AcceptInviteResponseFromJson(Map<String, dynamic> json) {
return AcceptInviteResponse() return AcceptInviteResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() .toList()
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
RejectInviteResponse _$RejectInviteResponseFromJson(Map json) { RejectInviteResponse _$RejectInviteResponseFromJson(Map<String, dynamic> json) {
return RejectInviteResponse() return RejectInviteResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() .toList()
..message = json['message'] == null ..message = json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?);
(k, e) => MapEntry(k as String, e),
));
} }
EmptyResponse _$EmptyResponseFromJson(Map json) { EmptyResponse _$EmptyResponseFromJson(Map<String, dynamic> json) {
return EmptyResponse()..duration = json['duration'] as String?; return EmptyResponse()..duration = json['duration'] as String?;
} }
ChannelStateResponse _$ChannelStateResponseFromJson(Map json) { ChannelStateResponse _$ChannelStateResponseFromJson(Map<String, dynamic> json) {
return ChannelStateResponse() return ChannelStateResponse()
..duration = json['duration'] as String? ..duration = json['duration'] as String?
..channel = json['channel'] == null ..channel = json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?)
(k, e) => MapEntry(k as String, e),
))
..messages = (json['messages'] as List<dynamic>?) ..messages = (json['messages'] as List<dynamic>?)
?.map((e) => Message.fromJson((e as Map?)?.map( ?.map((e) => Message.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList() .toList()
..members = (json['members'] as List<dynamic>?) ..members = (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() .toList()
..watcherCount = json['watcher_count'] as int? ..watcherCount = json['watcher_count'] as int?
..read = (json['read'] as List<dynamic>?) ..read = (json['read'] as List<dynamic>?)
?.map((e) => Read.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Read.fromJson(e as Map<String, dynamic>))
.toList(); .toList();
} }
@@ -124,10 +124,10 @@ class WebSocket {
Event _decodeEvent(String source) => Event.fromJson(json.decode(source)); Event _decodeEvent(String source) => Event.fromJson(json.decode(source));
Completer<Event> _connectionCompleter = Completer<Event>(); Completer<Event?> _connectionCompleter = Completer<Event?>();
/// Connect the WS using the parameters passed in the constructor /// Connect the WS using the parameters passed in the constructor
Future<Event>? connect() { Future<Event?> connect() async {
_manuallyDisconnected = false; _manuallyDisconnected = false;
if (_connecting) { if (_connecting) {
+6 -4
View File
@@ -573,9 +573,11 @@ class StreamChatClient {
var event = await _chatPersistenceClient?.getConnectionInfo(); var event = await _chatPersistenceClient?.getConnectionInfo();
await _ws.connect()!.then((e) async { await _ws.connect().then((e) async {
await _chatPersistenceClient?.updateConnectionInfo(e); if (e != null) {
event = e; await _chatPersistenceClient?.updateConnectionInfo(e);
event = e;
}
await resync(); await resync();
}).catchError((err, stacktrace) { }).catchError((err, stacktrace) {
logger.severe('error connecting ws', err, stacktrace); logger.severe('error connecting ws', err, stacktrace);
@@ -737,7 +739,7 @@ class StreamChatClient {
QueryChannelsResponse.fromJson, QueryChannelsResponse.fromJson,
)!; )!;
if ((res.channels ?? []).isEmpty && (paginationParams.offset) == 0) { if ((res.channels ?? []).isEmpty && paginationParams.offset == 0) {
logger.warning( logger.warning(
''' '''
We could not find any channel for this query. We could not find any channel for this query.
@@ -192,14 +192,12 @@ abstract class ChatPersistenceClient {
final channels = final channels =
channelStates.map((it) => it.channel).where((it) => it != null); channelStates.map((it) => it.channel).where((it) => it != null);
final reactions = channelStates final reactions = channelStates.expand((it) => it.messages).expand((it) => [
.expand((it) => it.messages) if (it.ownReactions != null)
.expand((it) => [ ...it.ownReactions!.where((r) => r.userId != null),
if (it.ownReactions != null) if (it.latestReactions != null)
...it.ownReactions!.where((r) => r.userId != null), ...it.latestReactions!.where((r) => r.userId != null)
if (it.latestReactions != null) ]);
...it.latestReactions!.where((r) => r.userId != null)
]);
final users = channelStates final users = channelStates
.map((cs) => [ .map((cs) => [
@@ -6,7 +6,7 @@ part of 'action.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Action _$ActionFromJson(Map json) { Action _$ActionFromJson(Map<String, dynamic> json) {
return Action( return Action(
name: json['name'] as String?, name: json['name'] as String?,
style: json['style'] as String?, style: json['style'] as String?,
@@ -6,7 +6,7 @@ part of 'attachment.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Attachment _$AttachmentFromJson(Map json) { Attachment _$AttachmentFromJson(Map<String, dynamic> json) {
return Attachment( return Attachment(
id: json['id'] as String?, id: json['id'] as String?,
type: json['type'] as String, type: json['type'] as String,
@@ -27,19 +27,15 @@ Attachment _$AttachmentFromJson(Map json) {
authorIcon: json['author_icon'] as String?, authorIcon: json['author_icon'] as String?,
assetUrl: json['asset_url'] as String?, assetUrl: json['asset_url'] as String?,
actions: (json['actions'] as List<dynamic>?) actions: (json['actions'] as List<dynamic>?)
?.map((e) => Action.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Action.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
extraData: (json['extra_data'] as Map?)?.map( extraData: json['extra_data'] as Map<String, dynamic>?,
(k, e) => MapEntry(k as String, e),
),
file: json['file'] == null file: json['file'] == null
? null ? null
: AttachmentFile.fromJson( : AttachmentFile.fromJson(json['file'] as Map<String, dynamic>),
Map<String, dynamic>.from(json['file'] as Map)),
uploadState: json['upload_state'] == null uploadState: json['upload_state'] == null
? null ? null
: UploadState.fromJson( : UploadState.fromJson(json['upload_state'] as Map<String, dynamic>),
Map<String, dynamic>.from(json['upload_state'] as Map)),
); );
} }
@@ -6,7 +6,7 @@ part of 'attachment_file.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
AttachmentFile _$AttachmentFileFromJson(Map json) { AttachmentFile _$AttachmentFileFromJson(Map<String, dynamic> json) {
return AttachmentFile( return AttachmentFile(
path: json['path'] as String?, path: json['path'] as String?,
name: json['name'] as String?, name: json['name'] as String?,
@@ -23,14 +23,14 @@ Map<String, dynamic> _$AttachmentFileToJson(AttachmentFile instance) =>
'size': instance.size, 'size': instance.size,
}; };
_$Preparing _$_$PreparingFromJson(Map json) { _$Preparing _$_$PreparingFromJson(Map<String, dynamic> json) {
return _$Preparing(); return _$Preparing();
} }
Map<String, dynamic> _$_$PreparingToJson(_$Preparing instance) => Map<String, dynamic> _$_$PreparingToJson(_$Preparing instance) =>
<String, dynamic>{}; <String, dynamic>{};
_$InProgress _$_$InProgressFromJson(Map json) { _$InProgress _$_$InProgressFromJson(Map<String, dynamic> json) {
return _$InProgress( return _$InProgress(
uploaded: json['uploaded'] as int, uploaded: json['uploaded'] as int,
total: json['total'] as int, total: json['total'] as int,
@@ -43,14 +43,14 @@ Map<String, dynamic> _$_$InProgressToJson(_$InProgress instance) =>
'total': instance.total, 'total': instance.total,
}; };
_$Success _$_$SuccessFromJson(Map json) { _$Success _$_$SuccessFromJson(Map<String, dynamic> json) {
return _$Success(); return _$Success();
} }
Map<String, dynamic> _$_$SuccessToJson(_$Success instance) => Map<String, dynamic> _$_$SuccessToJson(_$Success instance) =>
<String, dynamic>{}; <String, dynamic>{};
_$Failed _$_$FailedFromJson(Map json) { _$Failed _$_$FailedFromJson(Map<String, dynamic> json) {
return _$Failed( return _$Failed(
error: json['error'] as String, error: json['error'] as String,
); );
@@ -6,11 +6,11 @@ part of 'channel_config.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
ChannelConfig _$ChannelConfigFromJson(Map json) { ChannelConfig _$ChannelConfigFromJson(Map<String, dynamic> json) {
return ChannelConfig( return ChannelConfig(
automod: json['automod'] as String?, automod: json['automod'] as String?,
commands: (json['commands'] as List<dynamic>?) commands: (json['commands'] as List<dynamic>?)
?.map((e) => Command.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Command.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
connectEvents: json['connect_events'] as bool?, connectEvents: json['connect_events'] as bool?,
createdAt: json['created_at'] == null createdAt: json['created_at'] == null
@@ -6,18 +6,15 @@ part of 'channel_model.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
ChannelModel _$ChannelModelFromJson(Map json) { ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) {
return ChannelModel( return ChannelModel(
id: json['id'] as String?, id: json['id'] as String?,
type: json['type'] as String?, type: json['type'] as String?,
cid: json['cid'] as String, cid: json['cid'] as String,
config: ChannelConfig.fromJson( config: ChannelConfig.fromJson(json['config'] as Map<String, dynamic>),
Map<String, dynamic>.from(json['config'] as Map)),
createdBy: json['created_by'] == null createdBy: json['created_by'] == null
? null ? null
: User.fromJson((json['created_by'] as Map?)?.map( : User.fromJson(json['created_by'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
frozen: json['frozen'] as bool, frozen: json['frozen'] as bool,
lastMessageAt: json['last_message_at'] == null lastMessageAt: json['last_message_at'] == null
? null ? null
@@ -28,9 +25,7 @@ ChannelModel _$ChannelModelFromJson(Map json) {
? null ? null
: DateTime.parse(json['deleted_at'] as String), : DateTime.parse(json['deleted_at'] as String),
memberCount: json['member_count'] as int, memberCount: json['member_count'] as int,
extraData: (json['extra_data'] as Map?)?.map( extraData: json['extra_data'] as Map<String, dynamic>?,
(k, e) => MapEntry(k as String, e),
),
team: json['team'] as String?, team: json['team'] as String?,
); );
} }
@@ -6,36 +6,27 @@ part of 'channel_state.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
ChannelState _$ChannelStateFromJson(Map json) { ChannelState _$ChannelStateFromJson(Map<String, dynamic> json) {
return ChannelState( return ChannelState(
channel: json['channel'] == null channel: json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
messages: (json['messages'] as List<dynamic>) messages: (json['messages'] as List<dynamic>)
.map((e) => Message.fromJson((e as Map?)?.map( .map((e) => Message.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(), .toList(),
members: (json['members'] as List<dynamic>) members: (json['members'] as List<dynamic>)
.map((e) => e == null .map((e) =>
? null e == null ? null : Member.fromJson(e as Map<String, dynamic>))
: Member.fromJson(Map<String, dynamic>.from(e as Map)))
.toList(), .toList(),
pinnedMessages: (json['pinned_messages'] as List<dynamic>) pinnedMessages: (json['pinned_messages'] as List<dynamic>)
.map((e) => Message.fromJson((e as Map?)?.map( .map((e) => Message.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(), .toList(),
watcherCount: json['watcher_count'] as int?, watcherCount: json['watcher_count'] as int?,
watchers: (json['watchers'] as List<dynamic>) watchers: (json['watchers'] as List<dynamic>)
.map((e) => User.fromJson((e as Map?)?.map( .map((e) => User.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(), .toList(),
read: (json['read'] as List<dynamic>) read: (json['read'] as List<dynamic>)
.map((e) => Read.fromJson(Map<String, dynamic>.from(e as Map))) .map((e) => Read.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
); );
} }
@@ -6,7 +6,7 @@ part of 'command.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Command _$CommandFromJson(Map json) { Command _$CommandFromJson(Map<String, dynamic> json) {
return Command( return Command(
name: json['name'] as String?, name: json['name'] as String?,
description: json['description'] as String?, description: json['description'] as String?,
@@ -6,7 +6,7 @@ part of 'device.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Device _$DeviceFromJson(Map json) { Device _$DeviceFromJson(Map<String, dynamic> json) {
return Device( return Device(
id: json['id'] as String, id: json['id'] as String,
pushProvider: json['push_provider'] as String?, pushProvider: json['push_provider'] as String?,
@@ -6,7 +6,7 @@ part of 'event.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Event _$EventFromJson(Map json) { Event _$EventFromJson(Map<String, dynamic> json) {
return Event( return Event(
type: json['type'] as String?, type: json['type'] as String?,
cid: json['cid'] as String?, cid: json['cid'] as String?,
@@ -16,41 +16,29 @@ Event _$EventFromJson(Map json) {
: DateTime.parse(json['created_at'] as String), : DateTime.parse(json['created_at'] as String),
me: json['me'] == null me: json['me'] == null
? null ? null
: OwnUser.fromJson((json['me'] as Map?)?.map( : OwnUser.fromJson(json['me'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
user: json['user'] == null user: json['user'] == null
? null ? null
: User.fromJson((json['user'] as Map?)?.map( : User.fromJson(json['user'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
message: json['message'] == null message: json['message'] == null
? null ? null
: Message.fromJson((json['message'] as Map?)?.map( : Message.fromJson(json['message'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
totalUnreadCount: json['total_unread_count'] as int?, totalUnreadCount: json['total_unread_count'] as int?,
unreadChannels: json['unread_channels'] as int?, unreadChannels: json['unread_channels'] as int?,
reaction: json['reaction'] == null reaction: json['reaction'] == null
? null ? null
: Reaction.fromJson((json['reaction'] as Map?)?.map( : Reaction.fromJson(json['reaction'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
online: json['online'] as bool?, online: json['online'] as bool?,
channel: json['channel'] == null channel: json['channel'] == null
? null ? null
: EventChannel.fromJson((json['channel'] as Map?)?.map( : EventChannel.fromJson(json['channel'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
member: json['member'] == null member: json['member'] == null
? null ? null
: Member.fromJson(Map<String, dynamic>.from(json['member'] as Map)), : Member.fromJson(json['member'] as Map<String, dynamic>),
channelId: json['channel_id'] as String?, channelId: json['channel_id'] as String?,
channelType: json['channel_type'] as String?, channelType: json['channel_type'] as String?,
parentId: json['parent_id'] as String?, parentId: json['parent_id'] as String?,
extraData: (json['extra_data'] as Map?)?.map( extraData: json['extra_data'] as Map<String, dynamic>?,
(k, e) => MapEntry(k as String, e),
),
)..isLocal = json['is_local'] as bool?; )..isLocal = json['is_local'] as bool?;
} }
@@ -85,21 +73,18 @@ Map<String, dynamic> _$EventToJson(Event instance) {
return val; return val;
} }
EventChannel _$EventChannelFromJson(Map json) { EventChannel _$EventChannelFromJson(Map<String, dynamic> json) {
return EventChannel( return EventChannel(
members: (json['members'] as List<dynamic>?) members: (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
id: json['id'] as String?, id: json['id'] as String?,
type: json['type'] as String?, type: json['type'] as String?,
cid: json['cid'] as String, cid: json['cid'] as String,
config: ChannelConfig.fromJson( config: ChannelConfig.fromJson(json['config'] as Map<String, dynamic>),
Map<String, dynamic>.from(json['config'] as Map)),
createdBy: json['created_by'] == null createdBy: json['created_by'] == null
? null ? null
: User.fromJson((json['created_by'] as Map?)?.map( : User.fromJson(json['created_by'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
frozen: json['frozen'] as bool, frozen: json['frozen'] as bool,
lastMessageAt: json['last_message_at'] == null lastMessageAt: json['last_message_at'] == null
? null ? null
@@ -110,9 +95,7 @@ EventChannel _$EventChannelFromJson(Map json) {
? null ? null
: DateTime.parse(json['deleted_at'] as String), : DateTime.parse(json['deleted_at'] as String),
memberCount: json['member_count'] as int, memberCount: json['member_count'] as int,
extraData: (json['extra_data'] as Map?)?.map( extraData: json['extra_data'] as Map<String, dynamic>?,
(k, e) => MapEntry(k as String, e),
),
); );
} }
@@ -6,13 +6,11 @@ part of 'member.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Member _$MemberFromJson(Map json) { Member _$MemberFromJson(Map<String, dynamic> json) {
return Member( return Member(
user: json['user'] == null user: json['user'] == null
? null ? null
: User.fromJson((json['user'] as Map?)?.map( : User.fromJson(json['user'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
inviteAcceptedAt: json['invite_accepted_at'] == null inviteAcceptedAt: json['invite_accepted_at'] == null
? null ? null
: DateTime.parse(json['invite_accepted_at'] as String), : DateTime.parse(json['invite_accepted_at'] as String),
@@ -6,49 +6,39 @@ part of 'message.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Message _$MessageFromJson(Map json) { Message _$MessageFromJson(Map<String, dynamic> json) {
return Message( return Message(
id: json['id'] as String?, id: json['id'] as String?,
text: json['text'] as String, text: json['text'] as String,
type: json['type'] as String, type: json['type'] as String,
attachments: (json['attachments'] as List<dynamic>?) attachments: (json['attachments'] as List<dynamic>?)
?.map((e) => Attachment.fromJson(Map<String, dynamic>.from(e as Map))) ?.map((e) => Attachment.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
mentionedUsers: (json['mentioned_users'] as List<dynamic>?) mentionedUsers: (json['mentioned_users'] as List<dynamic>?)
?.map((e) => User.fromJson((e as Map?)?.map( ?.map((e) => User.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(), .toList(),
silent: json['silent'] as bool?, silent: json['silent'] as bool?,
shadowed: json['shadowed'] as bool?, shadowed: json['shadowed'] as bool?,
reactionCounts: (json['reaction_counts'] as Map?)?.map( reactionCounts: (json['reaction_counts'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k as String, e as int), (k, e) => MapEntry(k, e as int),
), ),
reactionScores: (json['reaction_scores'] as Map?)?.map( reactionScores: (json['reaction_scores'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k as String, e as int), (k, e) => MapEntry(k, e as int),
), ),
latestReactions: (json['latest_reactions'] as List<dynamic>?) latestReactions: (json['latest_reactions'] as List<dynamic>?)
?.map((e) => Reaction.fromJson((e as Map?)?.map( ?.map((e) => Reaction.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(), .toList(),
ownReactions: (json['own_reactions'] as List<dynamic>?) ownReactions: (json['own_reactions'] as List<dynamic>?)
?.map((e) => Reaction.fromJson((e as Map?)?.map( ?.map((e) => Reaction.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(), .toList(),
parentId: json['parent_id'] as String?, parentId: json['parent_id'] as String?,
quotedMessage: json['quoted_message'] == null quotedMessage: json['quoted_message'] == null
? null ? null
: Message.fromJson((json['quoted_message'] as Map?)?.map( : Message.fromJson(json['quoted_message'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
quotedMessageId: json['quoted_message_id'] as String?, quotedMessageId: json['quoted_message_id'] as String?,
replyCount: json['reply_count'] as int?, replyCount: json['reply_count'] as int?,
threadParticipants: (json['thread_participants'] as List<dynamic>?) threadParticipants: (json['thread_participants'] as List<dynamic>?)
?.map((e) => User.fromJson((e as Map?)?.map( ?.map((e) => User.fromJson(e as Map<String, dynamic>?))
(k, e) => MapEntry(k as String, e),
)))
.toList(), .toList(),
showInChannel: json['show_in_channel'] as bool?, showInChannel: json['show_in_channel'] as bool?,
command: json['command'] as String?, command: json['command'] as String?,
@@ -56,9 +46,7 @@ Message _$MessageFromJson(Map json) {
updatedAt: DateTime.parse(json['updated_at'] as String), updatedAt: DateTime.parse(json['updated_at'] as String),
user: json['user'] == null user: json['user'] == null
? null ? null
: User.fromJson((json['user'] as Map?)?.map( : User.fromJson(json['user'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
pinned: json['pinned'] as bool?, pinned: json['pinned'] as bool?,
pinnedAt: json['pinned_at'] == null pinnedAt: json['pinned_at'] == null
? null ? null
@@ -68,12 +56,8 @@ Message _$MessageFromJson(Map json) {
: DateTime.parse(json['pin_expires'] as String), : DateTime.parse(json['pin_expires'] as String),
pinnedBy: json['pinned_by'] == null pinnedBy: json['pinned_by'] == null
? null ? null
: User.fromJson((json['pinned_by'] as Map?)?.map( : User.fromJson(json['pinned_by'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e), extraData: json['extra_data'] as Map<String, dynamic>?,
)),
extraData: (json['extra_data'] as Map?)?.map(
(k, e) => MapEntry(k as String, e),
),
deletedAt: json['deleted_at'] == null deletedAt: json['deleted_at'] == null
? null ? null
: DateTime.parse(json['deleted_at'] as String), : DateTime.parse(json['deleted_at'] as String),
@@ -123,10 +107,10 @@ Map<String, dynamic> _$MessageToJson(Message instance) {
return val; return val;
} }
TranslatedMessage _$TranslatedMessageFromJson(Map json) { TranslatedMessage _$TranslatedMessageFromJson(Map<String, dynamic> json) {
return TranslatedMessage( return TranslatedMessage(
(json['i18n'] as Map?)?.map( (json['i18n'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k as String, e as String), (k, e) => MapEntry(k, e as String),
), ),
); );
} }
@@ -6,18 +6,14 @@ part of 'mute.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Mute _$MuteFromJson(Map json) { Mute _$MuteFromJson(Map<String, dynamic> json) {
return Mute( return Mute(
user: json['user'] == null user: json['user'] == null
? null ? null
: User.fromJson((json['user'] as Map?)?.map( : User.fromJson(json['user'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
channel: json['channel'] == null channel: json['channel'] == null
? null ? null
: ChannelModel.fromJson((json['channel'] as Map?)?.map( : ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
createdAt: json['created_at'] == null createdAt: json['created_at'] == null
? null ? null
: DateTime.parse(json['created_at'] as String), : DateTime.parse(json['created_at'] as String),
@@ -6,19 +6,18 @@ part of 'own_user.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
OwnUser _$OwnUserFromJson(Map json) { OwnUser _$OwnUserFromJson(Map<String, dynamic> json) {
print(json);
return OwnUser( return OwnUser(
devices: (json['devices'] as List<dynamic>) devices: (json['devices'] as List<dynamic>)
.map((e) => Device.fromJson(Map<String, dynamic>.from(e as Map))) .map((e) => Device.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
mutes: (json['mutes'] as List<dynamic>) mutes: (json['mutes'] as List<dynamic>)
.map((e) => Mute.fromJson(Map<String, dynamic>.from(e as Map))) .map((e) => Mute.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
totalUnreadCount: json['total_unread_count'] as int, totalUnreadCount: json['total_unread_count'] as int,
unreadChannels: json['unread_channels'] as int?, unreadChannels: json['unread_channels'] as int?,
channelMutes: (json['channel_mutes'] as List<dynamic>) channelMutes: (json['channel_mutes'] as List<dynamic>)
.map((e) => Mute.fromJson(Map<String, dynamic>.from(e as Map))) .map((e) => Mute.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
id: json['id'] as String, id: json['id'] as String,
role: json['role'] as String, role: json['role'] as String,
@@ -28,7 +27,7 @@ OwnUser _$OwnUserFromJson(Map json) {
? null ? null
: DateTime.parse(json['last_active'] as String), : DateTime.parse(json['last_active'] as String),
online: json['online'] as bool, online: json['online'] as bool,
extraData: Map<String, dynamic>.from(json['extra_data'] as Map), extraData: json['extra_data'] as Map<String, dynamic>,
banned: json['banned'] as bool, banned: json['banned'] as bool,
); );
} }
@@ -6,19 +6,15 @@ part of 'reaction.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Reaction _$ReactionFromJson(Map json) { Reaction _$ReactionFromJson(Map<String, dynamic> json) {
return Reaction( return Reaction(
messageId: json['message_id'] as String?, messageId: json['message_id'] as String?,
createdAt: DateTime.parse(json['created_at'] as String), createdAt: DateTime.parse(json['created_at'] as String),
type: json['type'] as String, type: json['type'] as String,
user: User.fromJson((json['user'] as Map?)?.map( user: User.fromJson(json['user'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
userId: json['user_id'] as String?, userId: json['user_id'] as String?,
score: json['score'] as int, score: json['score'] as int,
extraData: (json['extra_data'] as Map?)?.map( extraData: json['extra_data'] as Map<String, dynamic>?,
(k, e) => MapEntry(k as String, e),
),
); );
} }
@@ -6,12 +6,10 @@ part of 'read.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
Read _$ReadFromJson(Map json) { Read _$ReadFromJson(Map<String, dynamic> json) {
return Read( return Read(
lastRead: DateTime.parse(json['last_read'] as String), lastRead: DateTime.parse(json['last_read'] as String),
user: User.fromJson((json['user'] as Map?)?.map( user: User.fromJson(json['user'] as Map<String, dynamic>?),
(k, e) => MapEntry(k as String, e),
)),
unreadMessages: json['unread_messages'] as int, unreadMessages: json['unread_messages'] as int,
); );
} }
@@ -6,7 +6,7 @@ part of 'user.dart';
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
User _$UserFromJson(Map json) { User _$UserFromJson(Map<String, dynamic> json) {
return User( return User(
id: json['id'] as String, id: json['id'] as String,
role: json['role'] as String, role: json['role'] as String,
@@ -16,7 +16,7 @@ User _$UserFromJson(Map json) {
? null ? null
: DateTime.parse(json['last_active'] as String), : DateTime.parse(json['last_active'] as String),
online: json['online'] as bool, online: json['online'] as bool,
extraData: Map<String, dynamic>.from(json['extra_data'] as Map), extraData: json['extra_data'] as Map<String, dynamic>,
banned: json['banned'] as bool, banned: json['banned'] as bool,
teams: (json['teams'] as List<dynamic>).map((e) => e as String).toList(), teams: (json['teams'] as List<dynamic>).map((e) => e as String).toList(),
); );
@@ -168,7 +168,8 @@ void main() {
requestOptions: FakeRequestOptions(), requestOptions: FakeRequestOptions(),
)); ));
await channelClient.sendAction(Message.temp(id: 'messageid', text: ''), data); await channelClient.sendAction(
Message.temp(id: 'messageid', text: ''), data);
verify(() => mockDio.post<String>('/messages/messageid/action', data: { verify(() => mockDio.post<String>('/messages/messageid/action', data: {
'id': 'testid', 'id': 'testid',
@@ -1,5 +1,5 @@
import 'package:test/test.dart';
import 'package:stream_chat/stream_chat.dart'; import 'package:stream_chat/stream_chat.dart';
import 'package:test/test.dart';
void main() { void main() {
group('src/api/requests', () { group('src/api/requests', () {
@@ -14,7 +14,6 @@ void main() {
final j = option.toJson(); final j = option.toJson();
expect(j, containsPair('limit', 10)); expect(j, containsPair('limit', 10));
expect(j, containsPair('offset', 0)); expect(j, containsPair('offset', 0));
expect(j, contains('hash_code'));
}); });
}); });
} }
@@ -35,7 +35,7 @@ void main() {
}); });
test('should connect with correct parameters', () async { test('should connect with correct parameters', () async {
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
user: User.temp(id: 'testid'), user: User.temp(id: 'testid'),
@@ -73,7 +73,7 @@ void main() {
test('should connect with correct parameters and handle events', () async { test('should connect with correct parameters and handle events', () async {
final handleFunc = MockFunctions().handleFunc; final handleFunc = MockFunctions().handleFunc;
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
user: User.temp(id: 'testid'), user: User.temp(id: 'testid'),
@@ -92,7 +92,7 @@ void main() {
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink()); when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
final connect = ws.connect()?.then((_) { final connect = ws.connect().then((_) {
streamController.sink.add('{}'); streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200)); return Future.delayed(const Duration(milliseconds: 200));
}).then((value) { }).then((value) {
@@ -109,7 +109,7 @@ void main() {
test('should close correctly the controller', () async { test('should close correctly the controller', () async {
final handleFunc = MockFunctions().handleFunc; final handleFunc = MockFunctions().handleFunc;
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
user: User.temp(id: 'testid'), user: User.temp(id: 'testid'),
@@ -128,7 +128,7 @@ void main() {
when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink()); when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink());
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
final connect = ws.connect()?.then((_) { final connect = ws.connect().then((_) {
streamController.sink.add('{}'); streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200)); return Future.delayed(const Duration(milliseconds: 200));
}).then((value) { }).then((value) {
@@ -146,7 +146,7 @@ void main() {
test('should close correctly the controller while connecting', () async { test('should close correctly the controller while connecting', () async {
final handleFunc = MockFunctions().handleFunc; final handleFunc = MockFunctions().handleFunc;
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
@@ -181,7 +181,7 @@ void main() {
test('should run correctly health check', () async { test('should run correctly health check', () async {
final handleFunc = MockFunctions().handleFunc; final handleFunc = MockFunctions().handleFunc;
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
user: User.temp(id: 'testid'), user: User.temp(id: 'testid'),
@@ -206,7 +206,7 @@ void main() {
(_) => streamController.sink.add('{}'), (_) => streamController.sink.add('{}'),
); );
final connect = ws.connect()?.then((_) { final connect = ws.connect().then((_) {
streamController.sink.add('{}'); streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200)); return Future.delayed(const Duration(milliseconds: 200));
}).then((value) async { }).then((value) async {
@@ -225,7 +225,7 @@ void main() {
test('should run correctly reconnection check', () async { test('should run correctly reconnection check', () async {
final handleFunc = MockFunctions().handleFunc; final handleFunc = MockFunctions().handleFunc;
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
Logger.root.level = Level.ALL; Logger.root.level = Level.ALL;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
@@ -247,7 +247,7 @@ void main() {
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
when(() => mockWSChannel.sink).thenReturn(mockWSSink); when(() => mockWSChannel.sink).thenReturn(mockWSSink);
final connect = ws.connect()?.then((_) { final connect = ws.connect().then((_) {
streamController.sink.add('{}'); streamController.sink.add('{}');
streamController.close(); streamController.close();
streamController = StreamController<String>.broadcast(); streamController = StreamController<String>.broadcast();
@@ -270,7 +270,7 @@ void main() {
test('should close correctly the controller', () async { test('should close correctly the controller', () async {
final handleFunc = MockFunctions().handleFunc; final handleFunc = MockFunctions().handleFunc;
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
user: User.temp(id: 'testid'), user: User.temp(id: 'testid'),
@@ -290,7 +290,7 @@ void main() {
when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream);
when(() => mockWSChannel.sink).thenReturn(mockWSSink); when(() => mockWSChannel.sink).thenReturn(mockWSSink);
final connect = ws.connect()?.then((_) { final connect = ws.connect().then((_) {
streamController.sink.add('{}'); streamController.sink.add('{}');
return Future.delayed(const Duration(milliseconds: 200)); return Future.delayed(const Duration(milliseconds: 200));
}).then((value) async { }).then((value) async {
@@ -307,7 +307,7 @@ void main() {
}); });
test('should throw an error', () async { test('should throw an error', () async {
final ConnectWebSocket connectFunc = MockFunctions().connectFunc; final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket( final ws = WebSocket(
baseUrl: 'baseurl', baseUrl: 'baseurl',
user: User.temp(id: 'testid'), user: User.temp(id: 'testid'),
@@ -34,7 +34,7 @@ void main() {
expect(reaction.type, 'wow'); expect(reaction.type, 'wow');
expect( expect(
reaction.user.toJson(), reaction.user.toJson(),
User.temp(id:'2de0297c-f3f2-489d-b930-ef77342edccf', extraData: { User.temp(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: {
'image': 'https://randomuser.me/api/portraits/women/45.jpg', 'image': 'https://randomuser.me/api/portraits/women/45.jpg',
'name': 'Daisy Morgan' 'name': 'Daisy Morgan'
}).toJson(), }).toJson(),
@@ -49,7 +49,7 @@ void main() {
messageId: '76cd8c82-b557-4e48-9d12-87995d3a0e04', messageId: '76cd8c82-b557-4e48-9d12-87995d3a0e04',
createdAt: DateTime.parse('2020-01-28T22:17:31.108742Z'), createdAt: DateTime.parse('2020-01-28T22:17:31.108742Z'),
type: 'wow', type: 'wow',
user: User.temp(id:'2de0297c-f3f2-489d-b930-ef77342edccf', extraData: { user: User.temp(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: {
'image': 'https://randomuser.me/api/portraits/women/45.jpg', 'image': 'https://randomuser.me/api/portraits/women/45.jpg',
'name': 'Daisy Morgan' 'name': 'Daisy Morgan'
}), }),
@@ -1,13 +1,14 @@
import 'dart:convert'; import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/user.dart'; import 'package:stream_chat/src/models/user.dart';
import 'package:test/test.dart';
void main() { void main() {
group('src/models/user', () { group('src/models/user', () {
const jsonExample = ''' const jsonExample = '''
{ {
"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e" "id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e",
"role": "test-role"
} }
'''; ''';