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