feat: Converted to ios models part II

This commit is contained in:
Deven Joshi
2021-04-14 14:56:04 +05:30
parent 97c35371af
commit 88f9bcc80c
32 changed files with 217 additions and 253 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ Future<void> main() async {
/// Please see the following for more information:
/// https://getstream.io/chat/docs/ios_user_setup_and_tokens/
await client.connectUser(
User.temp(
User(
id: 'cool-shadow-7',
extraData: {
'image':
@@ -1312,7 +1312,7 @@ class ChannelClientState {
updateChannelState(channelState!.copyWith(
members: [
...channelState!.members,
member,
member!,
],
));
}));
@@ -1323,7 +1323,7 @@ class ChannelClientState {
final user = e.user;
updateChannelState(channelState!.copyWith(
members: List.from(
channelState!.members..removeWhere((m) => m!.userId == user!.id)),
channelState!.members..removeWhere((m) => m.userId == user!.id)),
));
}));
}
@@ -1549,7 +1549,7 @@ class ChannelClientState {
/// Channel members list
List<Member> get members => _channelState!.members
.map((e) => e!.copyWith(user: _channel.client.state!.users[e.user!.id]))
.map((e) => e.copyWith(user: _channel.client.state!.users[e.user!.id]))
.toList();
/// Channel members list as a stream
@@ -1664,7 +1664,7 @@ class ChannelClientState {
[],
];
final newMembers = <Member?>[
final newMembers = <Member>[
...updatedState.members,
];
+3 -3
View File
@@ -311,7 +311,7 @@ class StreamChatClient {
httpClient.unlock();
await connectUser(User.temp(id: userId), newToken);
await connectUser(User(id: userId), newToken);
try {
handler.resolve(
@@ -753,7 +753,7 @@ class StreamChatClient {
final users = channels
.expand((it) => it.members)
.map((it) => it!.user)
.map((it) => it.user)
.toList(growable: false);
state!._updateUsers(users);
@@ -956,7 +956,7 @@ class StreamChatClient {
_anonymous = true;
const uuid = Uuid();
state!.user = OwnUser.temp(id: uuid.v4());
state!.user = OwnUser(id: uuid.v4());
return connect().then((event) {
_connectCompleter!.complete(event);
@@ -76,7 +76,7 @@ abstract class ChatPersistenceClient {
getPinnedMessagesByCid(cid, messagePagination: pinnedMessagePagination),
]);
return ChannelState(
members: (data[0] as List<Member?>?)!,
members: (data[0] as List<Member>?)!,
read: (data[1] as List<Read>?)!,
channel: data[2] as ChannelModel?,
messages: (data[3] as List<Message>?)!,
@@ -212,7 +212,7 @@ abstract class ChatPersistenceClient {
])
.expand((v) => v),
...cs.read.map((r) => r.user),
...cs.members.map((m) => m!.user),
...cs.members.map((m) => m.user),
])
.expand((it) => it)
.where((it) => it != null);
@@ -15,7 +15,7 @@ class Attachment extends Equatable {
/// Constructor used for json serialization
Attachment({
String? id,
required this.type,
String? type,
this.titleLink,
String? title,
this.thumbUrl,
@@ -38,6 +38,7 @@ class Attachment extends Equatable {
UploadState? uploadState,
}) : id = id ?? const Uuid().v4(),
title = title ?? file?.name,
type = type ?? '',
localUri = file?.path != null ? Uri.parse(file!.path!) : null {
this.uploadState = uploadState ??
((assetUrl != null || imageUrl != null)
@@ -9,7 +9,7 @@ part of 'attachment.dart';
Attachment _$AttachmentFromJson(Map<String, dynamic> json) {
return Attachment(
id: json['id'] as String?,
type: json['type'] as String,
type: json['type'] as String?,
titleLink: json['title_link'] as String?,
title: json['title'] as String?,
thumbUrl: json['thumb_url'] as String?,
@@ -12,33 +12,20 @@ class ChannelModel {
ChannelModel({
this.id,
this.type,
required this.cid,
required this.config,
this.cid = '',
ChannelConfig? config,
this.createdBy,
this.frozen = false,
this.lastMessageAt,
required this.createdAt,
required this.updatedAt,
DateTime? createdAt,
DateTime? updatedAt,
this.deletedAt,
this.memberCount = 0,
this.extraData,
this.team,
});
ChannelModel.temp({
this.id,
this.type,
required this.cid,
this.createdBy,
this.frozen = false,
this.lastMessageAt,
this.deletedAt,
this.memberCount = 0,
this.extraData,
this.team,
}) : createdAt = DateTime.now(),
updatedAt = DateTime.now(),
config = ChannelConfig();
}) : config = config ?? ChannelConfig(),
createdAt = createdAt ?? DateTime.now(),
updatedAt = updatedAt ?? DateTime.now();
/// Create a new instance from a json
factory ChannelModel.fromJson(Map<String, dynamic>? json) =>
@@ -64,7 +51,7 @@ class ChannelModel {
final User? createdBy;
/// True if this channel is frozen
@JsonKey(includeIfNull: false)
@JsonKey(includeIfNull: false, defaultValue: false)
final bool frozen;
/// The date of the last message
@@ -84,7 +71,8 @@ class ChannelModel {
final DateTime? deletedAt;
/// The count of this channel members
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false, toJson: Serialization.readOnly, defaultValue: 0)
final int memberCount;
/// Map of custom channel extraData
@@ -11,20 +11,26 @@ ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) {
id: json['id'] as String?,
type: json['type'] as String?,
cid: json['cid'] as String,
config: ChannelConfig.fromJson(json['config'] as Map<String, dynamic>),
config: json['config'] == null
? null
: ChannelConfig.fromJson(json['config'] as Map<String, dynamic>),
createdBy: json['created_by'] == null
? null
: User.fromJson(json['created_by'] as Map<String, dynamic>?),
frozen: json['frozen'] as bool,
frozen: json['frozen'] as bool? ?? false,
lastMessageAt: json['last_message_at'] == null
? null
: DateTime.parse(json['last_message_at'] as String),
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
createdAt: json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt: json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
deletedAt: json['deleted_at'] == null
? null
: DateTime.parse(json['deleted_at'] as String),
memberCount: json['member_count'] as int,
memberCount: json['member_count'] as int? ?? 0,
extraData: json['extra_data'] as Map<String, dynamic>?,
team: json['team'] as String?,
);
@@ -25,21 +25,26 @@ class ChannelState {
final ChannelModel? channel;
/// A paginated list of channel messages
@JsonKey(defaultValue: <Message>[])
final List<Message> messages;
/// A paginated list of channel members
final List<Member?> members;
@JsonKey(defaultValue: <Member>[])
final List<Member> members;
/// A paginated list of pinned messages
@JsonKey(defaultValue: <Message>[])
final List<Message> pinnedMessages;
/// The count of users watching the channel
final int? watcherCount;
/// A paginated list of users watching the channel
@JsonKey(defaultValue: <User>[])
final List<User> watchers;
/// The list of channel reads
@JsonKey(defaultValue: <Read>[])
final List<Read> read;
/// Create a new instance from a json
@@ -53,7 +58,7 @@ class ChannelState {
ChannelState copyWith({
ChannelModel? channel,
List<Message>? messages,
List<Member?>? members,
List<Member>? members,
List<Message>? pinnedMessages,
int? watcherCount,
List<User>? watchers,
@@ -11,23 +11,27 @@ ChannelState _$ChannelStateFromJson(Map<String, dynamic> json) {
channel: json['channel'] == null
? null
: ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?),
messages: (json['messages'] as List<dynamic>)
.map((e) => Message.fromJson(e as Map<String, dynamic>?))
.toList(),
members: (json['members'] as List<dynamic>)
.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<String, dynamic>?))
.toList(),
messages: (json['messages'] as List<dynamic>?)
?.map((e) => Message.fromJson(e as Map<String, dynamic>?))
.toList() ??
[],
members: (json['members'] as List<dynamic>?)
?.map((e) => Member.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
pinnedMessages: (json['pinned_messages'] as List<dynamic>?)
?.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<String, dynamic>?))
.toList(),
read: (json['read'] as List<dynamic>)
.map((e) => Read.fromJson(e as Map<String, dynamic>))
.toList(),
watchers: (json['watchers'] as List<dynamic>?)
?.map((e) => User.fromJson(e as Map<String, dynamic>?))
.toList() ??
[],
read: (json['read'] as List<dynamic>?)
?.map((e) => Read.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
);
}
@@ -35,7 +39,7 @@ Map<String, dynamic> _$ChannelStateToJson(ChannelState instance) =>
<String, dynamic>{
'channel': instance.channel?.toJson(),
'messages': instance.messages.map((e) => e.toJson()).toList(),
'members': instance.members.map((e) => e?.toJson()).toList(),
'members': instance.members.map((e) => e.toJson()).toList(),
'pinned_messages':
instance.pinnedMessages.map((e) => e.toJson()).toList(),
'watcher_count': instance.watcherCount,
@@ -7,7 +7,7 @@ part 'device.g.dart';
class Device {
/// Constructor used for json serialization
Device({
required this.id,
this.id = '',
this.pushProvider,
});
@@ -85,7 +85,7 @@ EventChannel _$EventChannelFromJson(Map<String, dynamic> json) {
createdBy: json['created_by'] == null
? null
: User.fromJson(json['created_by'] as Map<String, dynamic>?),
frozen: json['frozen'] as bool,
frozen: json['frozen'] as bool? ?? false,
lastMessageAt: json['last_message_at'] == null
? null
: DateTime.parse(json['last_message_at'] as String),
@@ -94,7 +94,7 @@ EventChannel _$EventChannelFromJson(Map<String, dynamic> json) {
deletedAt: json['deleted_at'] == null
? null
: DateTime.parse(json['deleted_at'] as String),
memberCount: json['member_count'] as int,
memberCount: json['member_count'] as int? ?? 0,
extraData: json['extra_data'] as Map<String, dynamic>?,
);
}
@@ -13,14 +13,15 @@ class Member {
this.inviteAcceptedAt,
this.inviteRejectedAt,
this.invited = false,
required this.role,
this.role = '',
this.userId,
this.isModerator,
required this.createdAt,
required this.updatedAt,
DateTime? createdAt,
DateTime? updatedAt,
this.banned = false,
this.shadowBanned = false,
});
}) : createdAt = createdAt ?? DateTime.now(),
updatedAt = updatedAt ?? DateTime.now();
/// Create a new instance from a json
factory Member.fromJson(Map<String, dynamic> json) {
@@ -40,9 +41,11 @@ class Member {
final DateTime? inviteRejectedAt;
/// True if the user has been invited to the channel
@JsonKey(defaultValue: false)
final bool invited;
/// The role of the user in the channel
@JsonKey(defaultValue: '')
final String role;
/// The id of the interested user
@@ -52,9 +55,11 @@ class Member {
final bool? isModerator;
/// True if the member is banned from the channel
@JsonKey(defaultValue: false)
final bool banned;
/// True if the member is shadow banned from the channel
@JsonKey(defaultValue: false)
final bool shadowBanned;
/// The date of creation
@@ -17,14 +17,18 @@ Member _$MemberFromJson(Map<String, dynamic> json) {
inviteRejectedAt: json['invite_rejected_at'] == null
? null
: DateTime.parse(json['invite_rejected_at'] as String),
invited: json['invited'] as bool,
role: json['role'] as String,
invited: json['invited'] as bool? ?? false,
role: json['role'] as String? ?? '',
userId: json['user_id'] as String?,
isModerator: json['is_moderator'] as bool?,
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
banned: json['banned'] as bool,
shadowBanned: json['shadow_banned'] as bool,
createdAt: json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt: json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
banned: json['banned'] as bool? ?? false,
shadowBanned: json['shadow_banned'] as bool? ?? false,
);
}
@@ -46,41 +46,8 @@ class Message extends Equatable {
/// Constructor used for json serialization
Message({
String? id,
required this.text,
required this.type,
this.attachments,
this.mentionedUsers,
this.silent,
this.shadowed,
this.reactionCounts,
this.reactionScores,
this.latestReactions,
this.ownReactions,
this.parentId,
this.quotedMessage,
this.quotedMessageId,
this.replyCount = 0,
this.threadParticipants,
this.showInChannel,
this.command,
required this.createdAt,
required this.updatedAt,
this.user,
this.pinned = false,
this.pinnedAt,
DateTime? pinExpires,
this.pinnedBy,
this.extraData,
this.deletedAt,
this.status = MessageSendingStatus.sent,
this.skipPush,
}) : id = id ?? const Uuid().v4(),
pinExpires = pinExpires?.toUtc();
/// Constructor for creating temporary/throwaway message with id and text
Message.temp({
String? id,
required this.text,
this.text = '',
this.type = '',
this.attachments,
this.mentionedUsers,
this.silent,
@@ -96,6 +63,8 @@ class Message extends Equatable {
this.threadParticipants,
this.showInChannel,
this.command,
DateTime? createdAt,
DateTime? updatedAt,
this.user,
this.pinned = false,
this.pinnedAt,
@@ -107,9 +76,8 @@ class Message extends Equatable {
this.skipPush,
}) : id = id ?? const Uuid().v4(),
pinExpires = pinExpires?.toUtc(),
createdAt = DateTime.now(),
updatedAt = DateTime.now(),
type = '';
createdAt = createdAt ?? DateTime.now(),
updatedAt = updatedAt ?? DateTime.now();
/// Create a new instance from a json
factory Message.fromJson(Map<String, dynamic>? json) => _$MessageFromJson(
@@ -418,12 +386,7 @@ class Message extends Equatable {
@JsonSerializable()
class TranslatedMessage extends Message {
/// Constructor used for json serialization
TranslatedMessage(this.i18n)
: super(
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
text: '',
type: '');
TranslatedMessage(this.i18n) : super();
/// Create a new instance from a json
factory TranslatedMessage.fromJson(Map<String, dynamic>? json) =>
@@ -42,8 +42,12 @@ Message _$MessageFromJson(Map<String, dynamic> json) {
.toList(),
showInChannel: json['show_in_channel'] as bool?,
command: json['command'] as String?,
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
createdAt: json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt: json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
user: json['user'] == null
? null
: User.fromJson(json['user'] as Map<String, dynamic>?),
@@ -17,10 +17,10 @@ class OwnUser extends User {
this.totalUnreadCount = 0,
this.unreadChannels,
this.channelMutes = const [],
required String id,
required String role,
required DateTime createdAt,
required DateTime updatedAt,
String id = '',
String role = '',
DateTime? createdAt,
DateTime? updatedAt,
DateTime? lastActive,
bool online = false,
Map<String, dynamic> extraData = const {},
@@ -36,44 +36,34 @@ class OwnUser extends User {
banned: banned,
);
/// Create a temporary/throwaway user with an ID
OwnUser.temp({
required String id,
this.devices = const [],
this.mutes = const [],
this.totalUnreadCount = 0,
this.unreadChannels,
this.channelMutes = const [],
DateTime? lastActive,
bool online = false,
Map<String, dynamic> extraData = const {},
bool banned = false,
}) : super.temp(
id: id,
lastActive: lastActive,
online: online,
extraData: extraData,
banned: banned,
);
/// Create a new instance from a json
factory OwnUser.fromJson(Map<String, dynamic>? json) => _$OwnUserFromJson(
Serialization.moveToExtraDataFromRoot(json, topLevelFields)!);
/// List of user devices
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false,
toJson: Serialization.readOnly,
defaultValue: <Device>[])
final List<Device> devices;
/// List of users muted by the user
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false,
toJson: Serialization.readOnly,
defaultValue: <Mute>[])
final List<Mute> mutes;
/// List of users muted by the user
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false,
toJson: Serialization.readOnly,
defaultValue: <Mute>[])
final List<Mute> channelMutes;
/// Total unread messages by the user
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false, toJson: Serialization.readOnly, defaultValue: 0)
final int totalUnreadCount;
/// Total unread channels by the user
@@ -8,27 +8,34 @@ part of 'own_user.dart';
OwnUser _$OwnUserFromJson(Map<String, dynamic> json) {
return OwnUser(
devices: (json['devices'] as List<dynamic>)
.map((e) => Device.fromJson(e as Map<String, dynamic>))
.toList(),
mutes: (json['mutes'] as List<dynamic>)
.map((e) => Mute.fromJson(e as Map<String, dynamic>))
.toList(),
totalUnreadCount: json['total_unread_count'] as int,
devices: (json['devices'] as List<dynamic>?)
?.map((e) => Device.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
mutes: (json['mutes'] as List<dynamic>?)
?.map((e) => Mute.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
totalUnreadCount: json['total_unread_count'] as int? ?? 0,
unreadChannels: json['unread_channels'] as int?,
channelMutes: (json['channel_mutes'] as List<dynamic>)
.map((e) => Mute.fromJson(e as Map<String, dynamic>))
.toList(),
channelMutes: (json['channel_mutes'] as List<dynamic>?)
?.map((e) => Mute.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
id: json['id'] as String,
role: json['role'] as String,
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
role: json['role'] as String? ?? '',
createdAt: json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt: json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
lastActive: json['last_active'] == null
? null
: DateTime.parse(json['last_active'] as String),
online: json['online'] as bool,
online: json['online'] as bool? ?? false,
extraData: json['extra_data'] as Map<String, dynamic>,
banned: json['banned'] as bool,
banned: json['banned'] as bool? ?? false,
);
}
@@ -23,6 +23,7 @@ class Read {
final User user;
/// Number of unread messages
@JsonKey(defaultValue: 0)
final int unreadMessages;
/// Serialize to json
@@ -10,7 +10,7 @@ Read _$ReadFromJson(Map<String, dynamic> json) {
return Read(
lastRead: DateTime.parse(json['last_read'] as String),
user: User.fromJson(json['user'] as Map<String, dynamic>?),
unreadMessages: json['unread_messages'] as int,
unreadMessages: json['unread_messages'] as int? ?? 0,
);
}
+15 -20
View File
@@ -8,28 +8,17 @@ part 'user.g.dart';
class User {
/// Constructor used for json serialization
User({
required this.id,
required this.role,
required this.createdAt,
required this.updatedAt,
this.lastActive,
this.online = false,
this.extraData = const {},
this.banned = false,
this.teams = const [],
});
/// Use constructor for a temporary/throwaway user with an ID
User.temp({
required this.id,
this.id = '',
this.role = '',
DateTime? createdAt,
DateTime? updatedAt,
this.lastActive,
this.online = false,
this.extraData = const {},
this.banned = false,
this.teams = const [],
}) : createdAt = DateTime.now(),
updatedAt = DateTime.now();
}) : createdAt = createdAt ?? DateTime.now(),
updatedAt = updatedAt ?? DateTime.now();
/// Create a new instance from a json
factory User.fromJson(Map<String, dynamic>? json) => _$UserFromJson(
@@ -64,11 +53,15 @@ class User {
final String id;
/// User role
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false, toJson: Serialization.readOnly, defaultValue: '')
final String role;
/// User role
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false,
toJson: Serialization.readOnly,
defaultValue: <String>[])
final List<String> teams;
/// Date of user creation
@@ -84,11 +77,13 @@ class User {
final DateTime? lastActive;
/// True if user is online
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false, toJson: Serialization.readOnly, defaultValue: false)
final bool online;
/// True if user is banned from the chat
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@JsonKey(
includeIfNull: false, toJson: Serialization.readOnly, defaultValue: false)
final bool banned;
/// Map of custom user extraData
@@ -9,16 +9,22 @@ part of 'user.dart';
User _$UserFromJson(Map<String, dynamic> json) {
return User(
id: json['id'] as String,
role: json['role'] as String,
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
role: json['role'] as String? ?? '',
createdAt: json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt: json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
lastActive: json['last_active'] == null
? null
: DateTime.parse(json['last_active'] as String),
online: json['online'] as bool,
online: json['online'] as bool? ?? false,
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(),
banned: json['banned'] as bool? ?? false,
teams:
(json['teams'] as List<dynamic>?)?.map((e) => e as String).toList() ??
[],
);
}
@@ -35,7 +35,7 @@ void main() {
tokenProvider: (_) async => '',
);
final channelClient = client.channel('messaging', id: 'testid');
final message = Message.temp(text: 'hey', id: 'test');
final message = Message(text: 'hey', id: 'test');
when(
() => mockDio.post<String>(
@@ -168,8 +168,7 @@ void main() {
requestOptions: FakeRequestOptions(),
));
await channelClient.sendAction(
Message.temp(id: 'messageid', text: ''), data);
await channelClient.sendAction(Message(id: 'messageid'), data);
verify(() => mockDio.post<String>('/messages/messageid/action', data: {
'id': 'testid',
@@ -335,7 +334,7 @@ void main() {
final channelClient = client.channel('messaging', id: 'testid');
final message = Message.temp(text: 'Hello');
final message = Message(text: 'Hello');
expect(
() => channelClient.pinMessage(message, 'InvalidType'),
@@ -355,7 +354,7 @@ void main() {
tokenProvider: (_) async => '',
);
final channelClient = client.channel('messaging', id: 'testid');
final message = Message.temp(text: 'Hello', id: 'test');
final message = Message(text: 'Hello', id: 'test');
when(
() => mockDio.post<String>(
@@ -389,7 +388,7 @@ void main() {
tokenProvider: (_) async => '',
);
final channelClient = client.channel('messaging', id: 'testid');
final message = Message.temp(text: 'Hello', id: 'test');
final message = Message(text: 'Hello', id: 'test');
when(
() => mockDio.post<String>(
@@ -567,7 +566,7 @@ void main() {
tokenProvider: (_) async => '',
);
client.state?.user = OwnUser.temp(id: 'test-id');
client.state?.user = OwnUser(id: 'test-id');
final channelClient = client.channel('messaging', id: 'testid');
const reactionType = 'test';
@@ -591,13 +590,8 @@ void main() {
);
await channelClient.sendReaction(
Message.temp(
Message(
id: 'messageid',
text: '',
reactionCounts: const <String, int>{},
reactionScores: const <String, int>{},
latestReactions: const <Reaction>[],
ownReactions: const <Reaction>[],
),
reactionType,
);
@@ -623,7 +617,7 @@ void main() {
tokenProvider: (_) async => '',
);
client.state?.user = OwnUser.temp(id: 'test-id');
client.state?.user = OwnUser(id: 'test-id');
final channelClient = client.channel('messaging', id: 'testid');
@@ -638,19 +632,14 @@ void main() {
);
await channelClient.deleteReaction(
Message.temp(
Message(
id: 'messageid',
text: '',
reactionCounts: const <String, int>{},
reactionScores: const <String, int>{},
latestReactions: const <Reaction>[],
ownReactions: const <Reaction>[],
),
Reaction(
type: 'test',
createdAt: DateTime.now(),
score: 0,
user: User.temp(
user: User(
id: client.state?.user?.id ?? '',
),
),
@@ -709,7 +698,7 @@ void main() {
);
final channelClient = client.channel('messaging', id: 'testid');
final members = ['vishal'];
final message = Message.temp(text: 'test');
final message = Message(text: 'test');
when(
() => mockDio.post<String>(
@@ -743,7 +732,7 @@ void main() {
tokenProvider: (_) async => '',
);
final channelClient = client.channel('messaging', id: 'testid');
final message = Message.temp(text: 'test');
final message = Message(text: 'test');
when(
() => mockDio.post<String>(
@@ -2091,7 +2080,7 @@ void main() {
tokenProvider: (_) async => '',
);
final channelClient = client.channel('messaging', id: 'testid');
final message = Message.temp(text: 'test');
final message = Message(text: 'test');
when(
() => mockDio.post<String>(
@@ -2190,7 +2179,7 @@ void main() {
tokenProvider: (_) async => '',
);
final channelClient = client.channel('messaging', id: 'testid');
final message = Message.temp(text: 'test');
final message = Message(text: 'test');
when(
() => mockDio.post<String>(
@@ -2225,7 +2214,7 @@ void main() {
);
final channelClient = client.channel('messaging', id: 'testid');
final members = ['vishal'];
final message = Message.temp(text: 'test');
final message = Message(text: 'test');
when(
() => mockDio.post<String>(
@@ -2259,7 +2248,7 @@ void main() {
);
final channelClient = client.channel('messaging', id: 'testid');
final members = ['vishal'];
final message = Message.temp(text: 'test');
final message = Message(text: 'test');
when(
() => mockDio.post<String>(
@@ -38,7 +38,7 @@ void main() {
final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
@@ -76,7 +76,7 @@ void main() {
final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
@@ -112,7 +112,7 @@ void main() {
final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
@@ -150,7 +150,7 @@ void main() {
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
@@ -184,7 +184,7 @@ void main() {
final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
@@ -229,7 +229,7 @@ void main() {
Logger.root.level = Level.ALL;
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
@@ -273,7 +273,7 @@ void main() {
final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
@@ -310,7 +310,7 @@ void main() {
final connectFunc = MockFunctions().connectFunc;
final ws = WebSocket(
baseUrl: 'baseurl',
user: User.temp(id: 'testid'),
user: User(id: 'testid'),
logger: Logger('ws'),
connectParams: {'test': 'true'},
connectPayload: {'payload': 'test'},
+8 -12
View File
@@ -479,7 +479,7 @@ void main() {
final client = StreamChatClient('api-key', httpClient: mockDio);
expect(() => client.connectUserWithProvider(User.temp(id: 'test-id')),
expect(() => client.connectUserWithProvider(User(id: 'test-id')),
throwsA(isA<Exception>()));
});
@@ -517,7 +517,7 @@ void main() {
when(() => mockDio.interceptors).thenReturn(Interceptors());
final client = StreamChatClient('api-key', httpClient: mockDio);
final user = User.temp(id: 'test-id');
final user = User(id: 'test-id');
final data = {
'users': {user.id: user.toJson()},
};
@@ -542,8 +542,8 @@ void main() {
when(() => mockDio.interceptors).thenReturn(Interceptors());
final client = StreamChatClient('api-key', httpClient: mockDio);
final user = User.temp(id: 'test-id');
final user2 = User.temp(id: 'test-id2');
final user = User(id: 'test-id');
final user2 = User(id: 'test-id2');
final data = {
'users': {
@@ -739,10 +739,6 @@ void main() {
final client = StreamChatClient('api-key', httpClient: mockDio);
final message = Message(
id: 'test',
updatedAt: DateTime.now(),
createdAt: DateTime.now(),
text: '',
type: '',
);
when(
@@ -781,7 +777,7 @@ void main() {
),
);
await client.deleteMessage(Message.temp(id: messageId, text: ''));
await client.deleteMessage(Message(id: messageId, text: ''));
verify(() => mockDio.delete<String>('/messages/$messageId')).called(1);
});
@@ -1101,7 +1097,7 @@ void main() {
);
test('should throw argument error', () {
final message = Message.temp(text: 'Hello');
final message = Message(text: 'Hello');
expect(
() => client.pinMessage(message, 'InvalidType'),
throwsArgumentError,
@@ -1110,7 +1106,7 @@ void main() {
test('should complete successfully', () async {
const timeout = 30;
final message = Message.temp(text: 'Hello');
final message = Message(text: 'Hello');
when(
() => mockDio.post<String>(
@@ -1132,7 +1128,7 @@ void main() {
});
test('should unpin message successfully', () async {
final message = Message.temp(text: 'Hello');
final message = Message(text: 'Hello');
when(
() => mockDio.post<String>(
@@ -851,8 +851,8 @@ void main() {
expect(channelState.channel?.type, 'team');
expect(channelState.channel?.config, isA<ChannelConfig>());
expect(channelState.channel?.config, isNotNull);
expect(channelState.channel?.config?.commands, hasLength(1));
expect(channelState.channel?.config?.commands![0], isA<Command>());
expect(channelState.channel?.config.commands, hasLength(1));
expect(channelState.channel?.config.commands![0], isA<Command>());
expect(channelState.channel?.lastMessageAt,
DateTime.parse('2020-01-30T13:43:41.062362Z'));
expect(channelState.channel?.createdAt,
@@ -868,13 +868,13 @@ void main() {
'https://cdn.chrisshort.net/testing-certificate-chains-in-go/GOPHER_MIC_DROP.png',
);
expect(channelState.messages, hasLength(25));
expect(channelState.messages![0], isA<Message>());
expect(channelState.messages![0], isNotNull);
expect(channelState.messages[0], isA<Message>());
expect(channelState.messages[0], isNotNull);
expect(
channelState.messages![0].createdAt,
channelState.messages[0].createdAt,
DateTime.parse('2020-01-29T03:23:02.843948Z'),
);
expect(channelState.messages![0].user, isA<User>());
expect(channelState.messages[0].user, isA<User>());
expect(channelState.watcherCount, 5);
});
@@ -889,8 +889,8 @@ void main() {
"image": "https://cdn.chrisshort.net/testing-certificate-chains-in-go/GOPHER_MIC_DROP.png",
"example": 1
},
"watchers": null,
"read": null,
"watchers": [],
"read": [],
"messages": [
{
"id": "dry-meadow-0-2b73cc8b-cd86-4a01-8d40-bd82ad07a030",
@@ -25,7 +25,7 @@ void main() {
});
test('should serialize to json correctly', () {
final channel = ChannelModel.temp(
final channel = ChannelModel(
type: 'type',
id: 'id',
cid: 'a:a',
@@ -34,12 +34,12 @@ void main() {
expect(
channel.toJson(),
{'id': 'id', 'type': 'type', 'name': 'cool'},
{'id': 'id', 'type': 'type', 'frozen': false, 'name': 'cool'},
);
});
test('should serialize to json correctly when frozen is provided', () {
final channel = ChannelModel.temp(
final channel = ChannelModel(
type: 'type',
id: 'id',
cid: 'a:a',
@@ -51,12 +51,12 @@ void main() {
test('should serialize to json correctly', () {
final event = Event(
user: User.temp(id: 'id'),
user: User(id: 'id'),
type: 'type',
cid: 'cid',
connectionId: 'connectionId',
createdAt: DateTime.parse('2020-01-29T03:22:47.63613Z'),
me: OwnUser.temp(id: 'id2'),
me: OwnUser(id: 'id2'),
totalUnreadCount: 1,
unreadChannels: 1,
online: true,
@@ -97,7 +97,7 @@ void main() {
});
test('should serialize to json correctly', () {
final message = Message.temp(
final message = Message(
id: '4637f7e4-a06b-42db-ba5a-8d8270dd926f',
text:
'https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA',
@@ -34,7 +34,7 @@ void main() {
expect(reaction.type, 'wow');
expect(
reaction.user.toJson(),
User.temp(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: {
User(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(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: {
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
'name': 'Daisy Morgan'
}),
@@ -19,14 +19,14 @@ void main() {
test('should parse json correctly', () {
final read = Read.fromJson(json.decode(jsonExample));
expect(read.lastRead, DateTime.parse('2020-01-28T22:17:30.966485504Z'));
expect(read.user?.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
expect(read.user.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
expect(read.unreadMessages, 10);
});
test('should serialize to json correctly', () {
final read = Read(
lastRead: DateTime.parse('2020-01-28T22:17:30.966485504Z'),
user: User.temp(id: 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e'),
user: User(id: 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e'),
unreadMessages: 10,
);
@@ -18,7 +18,7 @@ void main() {
});
test('should serialize to json correctly', () {
final user = User.temp(
final user = User(
id: 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e',
role: 'abc',
);