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