chore: format comments
This commit is contained in:
@@ -63,145 +63,145 @@ class Channel {
|
|||||||
_extraData.addAll(extraData);
|
_extraData.addAll(extraData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the channel is muted
|
/// Returns true if the channel is muted.
|
||||||
bool get isMuted =>
|
bool get isMuted =>
|
||||||
_client.state.currentUser?.channelMutes
|
_client.state.currentUser?.channelMutes
|
||||||
.any((element) => element.channel.cid == cid) ==
|
.any((element) => element.channel.cid == cid) ==
|
||||||
true;
|
true;
|
||||||
|
|
||||||
/// Returns true if the channel is muted as a stream
|
/// Returns true if the channel is muted, as a stream.
|
||||||
Stream<bool>? get isMutedStream => _client.state.currentUserStream
|
Stream<bool>? get isMutedStream => _client.state.currentUserStream
|
||||||
.map((event) =>
|
.map((event) =>
|
||||||
event!.channelMutes.any((element) => element.channel.cid == cid) ==
|
event!.channelMutes.any((element) => element.channel.cid == cid) ==
|
||||||
true)
|
true)
|
||||||
.distinct();
|
.distinct();
|
||||||
|
|
||||||
/// True if the channel is a group
|
/// True if the channel is a group.
|
||||||
bool get isGroup => memberCount != 2;
|
bool get isGroup => memberCount != 2;
|
||||||
|
|
||||||
/// True if the channel is distinct
|
/// True if the channel is distinct.
|
||||||
bool get isDistinct => id?.startsWith('!members') == true;
|
bool get isDistinct => id?.startsWith('!members') == true;
|
||||||
|
|
||||||
/// Channel configuration
|
/// Channel configuration.
|
||||||
ChannelConfig? get config {
|
ChannelConfig? get config {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?._channelState.channel?.config;
|
return state?._channelState.channel?.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel configuration as a stream
|
/// Channel configuration as a stream.
|
||||||
Stream<ChannelConfig?>? get configStream {
|
Stream<ChannelConfig?>? get configStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.config);
|
return state?.channelStateStream.map((cs) => cs.channel?.config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel user creator
|
/// Channel user creator.
|
||||||
User? get createdBy {
|
User? get createdBy {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?._channelState.channel?.createdBy;
|
return state?._channelState.channel?.createdBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel user creator as a stream
|
/// Channel user creator as a stream.
|
||||||
Stream<User?>? get createdByStream {
|
Stream<User?>? get createdByStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.createdBy);
|
return state?.channelStateStream.map((cs) => cs.channel?.createdBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel frozen status
|
/// Channel frozen status.
|
||||||
bool? get frozen {
|
bool? get frozen {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?._channelState.channel?.frozen;
|
return state?._channelState.channel?.frozen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel frozen status as a stream
|
/// Channel frozen status as a stream.
|
||||||
Stream<bool?>? get frozenStream {
|
Stream<bool?>? get frozenStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.frozen);
|
return state?.channelStateStream.map((cs) => cs.channel?.frozen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel creation date
|
/// Channel creation date.
|
||||||
DateTime? get createdAt {
|
DateTime? get createdAt {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?._channelState.channel?.createdAt;
|
return state?._channelState.channel?.createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel creation date as a stream
|
/// Channel creation date as a stream.
|
||||||
Stream<DateTime?>? get createdAtStream {
|
Stream<DateTime?>? get createdAtStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.createdAt);
|
return state?.channelStateStream.map((cs) => cs.channel?.createdAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel last message date
|
/// Channel last message date.
|
||||||
DateTime? get lastMessageAt {
|
DateTime? get lastMessageAt {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?._channelState.channel?.lastMessageAt;
|
return state?._channelState.channel?.lastMessageAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel last message date as a stream
|
/// Channel last message date as a stream.
|
||||||
Stream<DateTime?>? get lastMessageAtStream {
|
Stream<DateTime?>? get lastMessageAtStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.lastMessageAt);
|
return state?.channelStateStream.map((cs) => cs.channel?.lastMessageAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel updated date
|
/// Channel updated date.
|
||||||
DateTime? get updatedAt {
|
DateTime? get updatedAt {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?._channelState.channel?.updatedAt;
|
return state?._channelState.channel?.updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel updated date as a stream
|
/// Channel updated date as a stream.
|
||||||
Stream<DateTime?>? get updatedAtStream {
|
Stream<DateTime?>? get updatedAtStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.updatedAt);
|
return state?.channelStateStream.map((cs) => cs.channel?.updatedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel deletion date
|
/// Channel deletion date.
|
||||||
DateTime? get deletedAt {
|
DateTime? get deletedAt {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?._channelState.channel?.deletedAt;
|
return state?._channelState.channel?.deletedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel deletion date as a stream
|
/// Channel deletion date as a stream.
|
||||||
Stream<DateTime?>? get deletedAtStream {
|
Stream<DateTime?>? get deletedAtStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.deletedAt);
|
return state?.channelStateStream.map((cs) => cs.channel?.deletedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel member count
|
/// Channel member count.
|
||||||
int? get memberCount {
|
int? get memberCount {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?._channelState.channel?.memberCount;
|
return state?._channelState.channel?.memberCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel member count as a stream
|
/// Channel member count as a stream.
|
||||||
Stream<int?>? get memberCountStream {
|
Stream<int?>? get memberCountStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
|
|
||||||
return state?.channelStateStream.map((cs) => cs.channel?.memberCount);
|
return state?.channelStateStream.map((cs) => cs.channel?.memberCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel id
|
/// Channel id.
|
||||||
String? get id => state?._channelState.channel?.id ?? _id;
|
String? get id => state?._channelState.channel?.id ?? _id;
|
||||||
|
|
||||||
/// Channel type
|
/// Channel type.
|
||||||
String get type => state?._channelState.channel?.type ?? _type;
|
String get type => state?._channelState.channel?.type ?? _type;
|
||||||
|
|
||||||
/// Channel cid
|
/// Channel cid.
|
||||||
String? get cid => state?._channelState.channel?.cid ?? _cid;
|
String? get cid => state?._channelState.channel?.cid ?? _cid;
|
||||||
|
|
||||||
/// Channel team
|
/// Channel team.
|
||||||
String? get team {
|
String? get team {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state?._channelState.channel?.team;
|
return state?._channelState.channel?.team;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel extra data
|
/// Channel extra data.
|
||||||
Map<String, Object?> get extraData {
|
Map<String, Object?> get extraData {
|
||||||
var data = state?._channelState.channel?.extraData;
|
var data = state?._channelState.channel?.extraData;
|
||||||
if (data == null || data.isEmpty) {
|
if (data == null || data.isEmpty) {
|
||||||
@@ -210,7 +210,7 @@ class Channel {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel extra data as a stream
|
/// Channel extra data as a stream.
|
||||||
Stream<Map<String, dynamic>> get extraDataStream {
|
Stream<Map<String, dynamic>> get extraDataStream {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return state!.channelStateStream.map(
|
return state!.channelStateStream.map(
|
||||||
@@ -224,9 +224,10 @@ class Channel {
|
|||||||
|
|
||||||
final Completer<bool> _initializedCompleter = Completer();
|
final Completer<bool> _initializedCompleter = Completer();
|
||||||
|
|
||||||
/// True if this is initialized
|
/// True if this is initialized.
|
||||||
|
///
|
||||||
/// Call [watch] to initialize the client or instantiate it using
|
/// Call [watch] to initialize the client or instantiate it using
|
||||||
/// [Channel.fromState]
|
/// [Channel.fromState].
|
||||||
Future<bool> get initialized => _initializedCompleter.future;
|
Future<bool> get initialized => _initializedCompleter.future;
|
||||||
|
|
||||||
final _cancelableAttachmentUploadRequest = <String, CancelToken>{};
|
final _cancelableAttachmentUploadRequest = <String, CancelToken>{};
|
||||||
@@ -362,7 +363,9 @@ class Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send a [message] to this channel.
|
/// Send a [message] to this channel.
|
||||||
/// If [skipPush] is true the message will not send a push notification
|
///
|
||||||
|
/// If [skipPush] is true the message will not send a push notification.
|
||||||
|
///
|
||||||
/// Waits for a [_messageAttachmentsUploadCompleter] to complete
|
/// Waits for a [_messageAttachmentsUploadCompleter] to complete
|
||||||
/// before actually sending the message.
|
/// before actually sending the message.
|
||||||
Future<SendMessageResponse> sendMessage(
|
Future<SendMessageResponse> sendMessage(
|
||||||
@@ -427,6 +430,7 @@ class Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the [message] in this channel.
|
/// Updates the [message] in this channel.
|
||||||
|
///
|
||||||
/// Waits for a [_messageAttachmentsUploadCompleter] to complete
|
/// Waits for a [_messageAttachmentsUploadCompleter] to complete
|
||||||
/// before actually updating the message.
|
/// before actually updating the message.
|
||||||
Future<UpdateMessageResponse> updateMessage(Message message) async {
|
Future<UpdateMessageResponse> updateMessage(Message message) async {
|
||||||
@@ -489,8 +493,10 @@ class Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Partially updates the [message] in this channel.
|
/// Partially updates the [message] in this channel.
|
||||||
/// Use [set] to define values to be set
|
///
|
||||||
/// Use [unset] to define values to be unset
|
/// Use [set] to define values to be set.
|
||||||
|
///
|
||||||
|
/// Use [unset] to define values to be unset.
|
||||||
Future<UpdateMessageResponse> partialUpdateMessage(
|
Future<UpdateMessageResponse> partialUpdateMessage(
|
||||||
Message message, {
|
Message message, {
|
||||||
Map<String, Object?>? set,
|
Map<String, Object?>? set,
|
||||||
@@ -590,7 +596,7 @@ class Channel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unpins provided message
|
/// Unpins provided message.
|
||||||
Future<UpdateMessageResponse> unpinMessage(Message message) =>
|
Future<UpdateMessageResponse> unpinMessage(Message message) =>
|
||||||
partialUpdateMessage(
|
partialUpdateMessage(
|
||||||
message,
|
message,
|
||||||
@@ -599,7 +605,7 @@ class Channel {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Send a file to this channel
|
/// Send a file to this channel.
|
||||||
Future<SendFileResponse> sendFile(
|
Future<SendFileResponse> sendFile(
|
||||||
AttachmentFile file, {
|
AttachmentFile file, {
|
||||||
ProgressCallback? onSendProgress,
|
ProgressCallback? onSendProgress,
|
||||||
@@ -615,7 +621,7 @@ class Channel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send an image to this channel
|
/// Send an image to this channel.
|
||||||
Future<SendImageResponse> sendImage(
|
Future<SendImageResponse> sendImage(
|
||||||
AttachmentFile file, {
|
AttachmentFile file, {
|
||||||
ProgressCallback? onSendProgress,
|
ProgressCallback? onSendProgress,
|
||||||
@@ -631,7 +637,7 @@ class Channel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A message search.
|
/// Search for a message with the given options.
|
||||||
Future<SearchMessagesResponse> search({
|
Future<SearchMessagesResponse> search({
|
||||||
String? query,
|
String? query,
|
||||||
Filter? messageFilters,
|
Filter? messageFilters,
|
||||||
@@ -648,7 +654,7 @@ class Channel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a file from this channel
|
/// Delete a file from this channel.
|
||||||
Future<EmptyResponse> deleteFile(
|
Future<EmptyResponse> deleteFile(
|
||||||
String url, {
|
String url, {
|
||||||
CancelToken? cancelToken,
|
CancelToken? cancelToken,
|
||||||
@@ -662,7 +668,7 @@ class Channel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete an image from this channel
|
/// Delete an image from this channel.
|
||||||
Future<EmptyResponse> deleteImage(
|
Future<EmptyResponse> deleteImage(
|
||||||
String url, {
|
String url, {
|
||||||
CancelToken? cancelToken,
|
CancelToken? cancelToken,
|
||||||
@@ -676,14 +682,15 @@ class Channel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send an event on this channel
|
/// Send an event on this channel.
|
||||||
Future<EmptyResponse> sendEvent(Event event) {
|
Future<EmptyResponse> sendEvent(Event event) {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.sendEvent(id!, type, event);
|
return _client.sendEvent(id!, type, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a reaction to this channel
|
/// Send a reaction to this channel.
|
||||||
/// Set [enforceUnique] to true to remove the existing user reaction
|
///
|
||||||
|
/// Set [enforceUnique] to true to remove the existing user reaction.
|
||||||
Future<SendReactionResponse> sendReaction(
|
Future<SendReactionResponse> sendReaction(
|
||||||
Message message,
|
Message message,
|
||||||
String type, {
|
String type, {
|
||||||
@@ -746,7 +753,7 @@ class Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a reaction from this channel
|
/// Delete a reaction from this channel.
|
||||||
Future<EmptyResponse> deleteReaction(
|
Future<EmptyResponse> deleteReaction(
|
||||||
Message message, Reaction reaction) async {
|
Message message, Reaction reaction) async {
|
||||||
final type = reaction.type;
|
final type = reaction.type;
|
||||||
@@ -821,25 +828,25 @@ class Channel {
|
|||||||
return _client.deleteChannel(id!, type);
|
return _client.deleteChannel(id!, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes all messages from the channel
|
/// Removes all messages from the channel.
|
||||||
Future<EmptyResponse> truncate() async {
|
Future<EmptyResponse> truncate() async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.truncateChannel(id!, type);
|
return _client.truncateChannel(id!, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept invitation to the channel
|
/// Accept invitation to the channel.
|
||||||
Future<AcceptInviteResponse> acceptInvite([Message? message]) async {
|
Future<AcceptInviteResponse> acceptInvite([Message? message]) async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.acceptChannelInvite(id!, type, message: message);
|
return _client.acceptChannelInvite(id!, type, message: message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reject invitation to the channel
|
/// Reject invitation to the channel.
|
||||||
Future<RejectInviteResponse> rejectInvite([Message? message]) async {
|
Future<RejectInviteResponse> rejectInvite([Message? message]) async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.rejectChannelInvite(id!, type, message: message);
|
return _client.rejectChannelInvite(id!, type, message: message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add members to the channel
|
/// Add members to the channel.
|
||||||
Future<AddMembersResponse> addMembers(
|
Future<AddMembersResponse> addMembers(
|
||||||
List<String> memberIds, [
|
List<String> memberIds, [
|
||||||
Message? message,
|
Message? message,
|
||||||
@@ -848,7 +855,7 @@ class Channel {
|
|||||||
return _client.addChannelMembers(id!, type, memberIds, message: message);
|
return _client.addChannelMembers(id!, type, memberIds, message: message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invite members to the channel
|
/// Invite members to the channel.
|
||||||
Future<InviteMembersResponse> inviteMembers(
|
Future<InviteMembersResponse> inviteMembers(
|
||||||
List<String> memberIds, [
|
List<String> memberIds, [
|
||||||
Message? message,
|
Message? message,
|
||||||
@@ -857,7 +864,7 @@ class Channel {
|
|||||||
return _client.inviteChannelMembers(id!, type, memberIds, message: message);
|
return _client.inviteChannelMembers(id!, type, memberIds, message: message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove members from the channel
|
/// Remove members from the channel.
|
||||||
Future<RemoveMembersResponse> removeMembers(
|
Future<RemoveMembersResponse> removeMembers(
|
||||||
List<String> memberIds, [
|
List<String> memberIds, [
|
||||||
Message? message,
|
Message? message,
|
||||||
@@ -866,7 +873,7 @@ class Channel {
|
|||||||
return _client.removeChannelMembers(id!, type, memberIds, message: message);
|
return _client.removeChannelMembers(id!, type, memberIds, message: message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send action for a specific message of this channel
|
/// Send action for a specific message of this channel.
|
||||||
Future<SendActionResponse> sendAction(
|
Future<SendActionResponse> sendAction(
|
||||||
Message message,
|
Message message,
|
||||||
Map<String, dynamic> formData,
|
Map<String, dynamic> formData,
|
||||||
@@ -913,9 +920,10 @@ class Channel {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark all messages as read
|
/// Mark all messages as read.
|
||||||
|
///
|
||||||
/// Optionally provide a [messageId] if you want to mark a
|
/// Optionally provide a [messageId] if you want to mark a
|
||||||
/// particular message as read
|
/// particular message as read.
|
||||||
Future<EmptyResponse> markRead({String? messageId}) async {
|
Future<EmptyResponse> markRead({String? messageId}) async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
client.state.totalUnreadCount =
|
client.state.totalUnreadCount =
|
||||||
@@ -924,7 +932,7 @@ class Channel {
|
|||||||
return _client.markChannelRead(id!, type, messageId: messageId);
|
return _client.markChannelRead(id!, type, messageId: messageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads the initial channel state and watches for changes
|
/// Loads the initial channel state and watches for changes.
|
||||||
Future<ChannelState> watch() async {
|
Future<ChannelState> watch() async {
|
||||||
ChannelState response;
|
ChannelState response;
|
||||||
|
|
||||||
@@ -955,15 +963,16 @@ class Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop watching the channel
|
/// Stop watching the channel.
|
||||||
Future<EmptyResponse> stopWatching() async {
|
Future<EmptyResponse> stopWatching() async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.stopChannelWatching(id!, type);
|
return _client.stopChannelWatching(id!, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List the message replies for a parent message
|
/// List the message replies for a parent message.
|
||||||
|
///
|
||||||
/// Set [preferOffline] to true to avoid the api call if the data is already
|
/// Set [preferOffline] to true to avoid the api call if the data is already
|
||||||
/// in the offline storage
|
/// in the offline storage.
|
||||||
Future<QueryRepliesResponse> getReplies(
|
Future<QueryRepliesResponse> getReplies(
|
||||||
String parentId, {
|
String parentId, {
|
||||||
PaginationParams? options,
|
PaginationParams? options,
|
||||||
@@ -987,7 +996,7 @@ class Channel {
|
|||||||
return repliesResponse;
|
return repliesResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List the reactions for a message in the channel
|
/// List the reactions for a message in the channel.
|
||||||
Future<QueryReactionsResponse> getReactions(
|
Future<QueryReactionsResponse> getReactions(
|
||||||
String messageId, {
|
String messageId, {
|
||||||
PaginationParams? pagination,
|
PaginationParams? pagination,
|
||||||
@@ -997,7 +1006,7 @@ class Channel {
|
|||||||
pagination: pagination,
|
pagination: pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Retrieves a list of messages by ID
|
/// Retrieves a list of messages by given [messageIDs].
|
||||||
Future<GetMessagesByIdResponse> getMessagesById(
|
Future<GetMessagesByIdResponse> getMessagesById(
|
||||||
List<String> messageIDs,
|
List<String> messageIDs,
|
||||||
) async {
|
) async {
|
||||||
@@ -1008,7 +1017,7 @@ class Channel {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves a list of messages by ID
|
/// Translate a message by given [messageId] and [language].
|
||||||
Future<TranslateMessageResponse> translateMessage(
|
Future<TranslateMessageResponse> translateMessage(
|
||||||
String messageId,
|
String messageId,
|
||||||
String language,
|
String language,
|
||||||
@@ -1018,12 +1027,13 @@ class Channel {
|
|||||||
language,
|
language,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Creates a new channel
|
/// Creates a new channel.
|
||||||
Future<ChannelState> create() async => query(state: false);
|
Future<ChannelState> create() async => query(state: false);
|
||||||
|
|
||||||
/// Query the API, get messages, members or other channel fields
|
/// Query the API, get messages, members or other channel fields.
|
||||||
/// Set [preferOffline] to true to avoid the api call if the data is already
|
///
|
||||||
/// in the offline storage
|
/// Set [preferOffline] to true to avoid the API call if the data is already
|
||||||
|
/// in the offline storage.
|
||||||
Future<ChannelState> query({
|
Future<ChannelState> query({
|
||||||
bool state = true,
|
bool state = true,
|
||||||
bool watch = false,
|
bool watch = false,
|
||||||
@@ -1077,7 +1087,7 @@ class Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Query channel members
|
/// Query channel members.
|
||||||
Future<QueryMembersResponse> queryMembers({
|
Future<QueryMembersResponse> queryMembers({
|
||||||
Filter? filter,
|
Filter? filter,
|
||||||
List<SortOption>? sort,
|
List<SortOption>? sort,
|
||||||
@@ -1092,19 +1102,19 @@ class Channel {
|
|||||||
pagination: pagination,
|
pagination: pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Mutes the channel
|
/// Mutes the channel.
|
||||||
Future<EmptyResponse> mute({Duration? expiration}) {
|
Future<EmptyResponse> mute({Duration? expiration}) {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.muteChannel(cid!, expiration: expiration);
|
return _client.muteChannel(cid!, expiration: expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unmutes the channel
|
/// Unmute the channel.
|
||||||
Future<EmptyResponse> unmute() {
|
Future<EmptyResponse> unmute() {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.unmuteChannel(cid!);
|
return _client.unmuteChannel(cid!);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bans a user from the channel
|
/// Bans the user with given [userID] from the channel.
|
||||||
Future<EmptyResponse> banUser(
|
Future<EmptyResponse> banUser(
|
||||||
String userID,
|
String userID,
|
||||||
Map<String, dynamic> options,
|
Map<String, dynamic> options,
|
||||||
@@ -1118,7 +1128,7 @@ class Channel {
|
|||||||
return _client.banUser(userID, opts);
|
return _client.banUser(userID, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the ban for a user in the channel
|
/// Remove the ban for the user with given [userID] in the channel.
|
||||||
Future<EmptyResponse> unbanUser(String userID) async {
|
Future<EmptyResponse> unbanUser(String userID) async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.unbanUser(userID, {
|
return _client.unbanUser(userID, {
|
||||||
@@ -1127,7 +1137,7 @@ class Channel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shadow bans a user from the channel
|
/// Shadow bans the user with the given [userID] from the channel.
|
||||||
Future<EmptyResponse> shadowBan(
|
Future<EmptyResponse> shadowBan(
|
||||||
String userID,
|
String userID,
|
||||||
Map<String, dynamic> options,
|
Map<String, dynamic> options,
|
||||||
@@ -1141,7 +1151,7 @@ class Channel {
|
|||||||
return _client.shadowBan(userID, opts);
|
return _client.shadowBan(userID, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the shadow ban for a user in the channel
|
/// Remove the shadow ban for the user with the given [userID] in the channel.
|
||||||
Future<EmptyResponse> removeShadowBan(String userID) async {
|
Future<EmptyResponse> removeShadowBan(String userID) async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.removeShadowBan(userID, {
|
return _client.removeShadowBan(userID, {
|
||||||
@@ -1151,8 +1161,10 @@ class Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Hides the channel from [StreamChatClient.queryChannels] for the user
|
/// Hides the channel from [StreamChatClient.queryChannels] for the user
|
||||||
/// until a message is added If [clearHistory] is set to true - all messages
|
/// until a message is added.
|
||||||
/// will be removed for the user
|
///
|
||||||
|
/// If [clearHistory] is set to true - all messages
|
||||||
|
/// will be removed for the user.
|
||||||
Future<EmptyResponse> hide({bool clearHistory = false}) async {
|
Future<EmptyResponse> hide({bool clearHistory = false}) async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
final response = await _client.hideChannel(
|
final response = await _client.hideChannel(
|
||||||
@@ -1170,7 +1182,7 @@ class Channel {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the hidden status for the channel
|
/// Removes the hidden status for the channel.
|
||||||
Future<EmptyResponse> show() async {
|
Future<EmptyResponse> show() async {
|
||||||
_checkInitialized();
|
_checkInitialized();
|
||||||
return _client.showChannel(id!, type);
|
return _client.showChannel(id!, type);
|
||||||
@@ -1178,7 +1190,7 @@ class Channel {
|
|||||||
|
|
||||||
/// Stream of [Event] coming from websocket connection specific for the
|
/// Stream of [Event] coming from websocket connection specific for the
|
||||||
/// channel. Pass an eventType as parameter in order to filter just a type
|
/// channel. Pass an eventType as parameter in order to filter just a type
|
||||||
/// of event
|
/// of event.
|
||||||
Stream<Event> on([
|
Stream<Event> on([
|
||||||
String? eventType,
|
String? eventType,
|
||||||
String? eventType2,
|
String? eventType2,
|
||||||
@@ -1216,7 +1228,7 @@ class Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets last typing to null and sends the typing.stop event
|
/// Sets last typing to null and sends the typing.stop event.
|
||||||
Future<void> stopTyping([String? parentId]) async {
|
Future<void> stopTyping([String? parentId]) async {
|
||||||
if (config?.typingEvents == false) {
|
if (config?.typingEvents == false) {
|
||||||
return;
|
return;
|
||||||
@@ -1230,7 +1242,7 @@ class Channel {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this method to dispose the channel client
|
/// Call this method to dispose the channel client.
|
||||||
void dispose() {
|
void dispose() {
|
||||||
state?.dispose();
|
state?.dispose();
|
||||||
}
|
}
|
||||||
@@ -1244,9 +1256,9 @@ class Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The class that handles the state of the channel listening to the events
|
/// The class that handles the state of the channel listening to the events.
|
||||||
class ChannelClientState {
|
class ChannelClientState {
|
||||||
/// Creates a new instance listening to events and updating the state
|
/// Creates a new instance listening to events and updating the state.
|
||||||
ChannelClientState(
|
ChannelClientState(
|
||||||
this._channel,
|
this._channel,
|
||||||
ChannelState channelState,
|
ChannelState channelState,
|
||||||
@@ -1393,23 +1405,25 @@ class ChannelClientState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Flag which indicates if [ChannelClientState] contain latest/recent messages or not.
|
/// Flag which indicates if [ChannelClientState] contain latest/recent messages or not.
|
||||||
|
///
|
||||||
/// This flag should be managed by UI sdks.
|
/// This flag should be managed by UI sdks.
|
||||||
/// When false, any new message (received by WebSocket event
|
///
|
||||||
/// - [EventType.messageNew]) will not be pushed on to message list.
|
/// When false, any new message received by WebSocket event
|
||||||
|
/// [EventType.messageNew] will not be pushed on to message list.
|
||||||
bool get isUpToDate => _isUpToDateController.value;
|
bool get isUpToDate => _isUpToDateController.value;
|
||||||
|
|
||||||
set isUpToDate(bool isUpToDate) => _isUpToDateController.add(isUpToDate);
|
set isUpToDate(bool isUpToDate) => _isUpToDateController.add(isUpToDate);
|
||||||
|
|
||||||
/// [isUpToDate] flag count as a stream
|
/// [isUpToDate] flag count as a stream.
|
||||||
Stream<bool> get isUpToDateStream => _isUpToDateController.stream;
|
Stream<bool> get isUpToDateStream => _isUpToDateController.stream;
|
||||||
|
|
||||||
final BehaviorSubject<bool> _isUpToDateController =
|
final BehaviorSubject<bool> _isUpToDateController =
|
||||||
BehaviorSubject.seeded(true);
|
BehaviorSubject.seeded(true);
|
||||||
|
|
||||||
/// The retry queue associated to this channel
|
/// The retry queue associated to this channel.
|
||||||
late final RetryQueue _retryQueue;
|
late final RetryQueue _retryQueue;
|
||||||
|
|
||||||
/// Retry failed message
|
/// Retry failed message.
|
||||||
Future<void> retryFailedMessages() async {
|
Future<void> retryFailedMessages() async {
|
||||||
final failedMessages =
|
final failedMessages =
|
||||||
<Message>[...messages, ...threads.values.expand((v) => v)]
|
<Message>[...messages, ...threads.values.expand((v) => v)]
|
||||||
@@ -1502,7 +1516,7 @@ class ChannelClientState {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a message to this channel
|
/// Add a message to this channel.
|
||||||
void addMessage(Message message) {
|
void addMessage(Message message) {
|
||||||
if (message.parentId == null || message.showInChannel == true) {
|
if (message.parentId == null || message.showInChannel == true) {
|
||||||
final newMessages = List<Message>.from(_channelState.messages);
|
final newMessages = List<Message>.from(_channelState.messages);
|
||||||
@@ -1567,36 +1581,36 @@ class ChannelClientState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel message list
|
/// Channel message list.
|
||||||
List<Message> get messages => _channelState.messages;
|
List<Message> get messages => _channelState.messages;
|
||||||
|
|
||||||
/// Channel message list as a stream
|
/// Channel message list as a stream.
|
||||||
Stream<List<Message>?> get messagesStream => channelStateStream
|
Stream<List<Message>?> get messagesStream => channelStateStream
|
||||||
.map((cs) => cs.messages)
|
.map((cs) => cs.messages)
|
||||||
.distinct(const ListEquality().equals);
|
.distinct(const ListEquality().equals);
|
||||||
|
|
||||||
/// Channel pinned message list
|
/// Channel pinned message list.
|
||||||
List<Message>? get pinnedMessages => _channelState.pinnedMessages.toList();
|
List<Message>? get pinnedMessages => _channelState.pinnedMessages.toList();
|
||||||
|
|
||||||
/// Channel pinned message list as a stream
|
/// Channel pinned message list as a stream.
|
||||||
Stream<List<Message>?> get pinnedMessagesStream =>
|
Stream<List<Message>?> get pinnedMessagesStream =>
|
||||||
channelStateStream.map((cs) => cs.pinnedMessages.toList());
|
channelStateStream.map((cs) => cs.pinnedMessages.toList());
|
||||||
|
|
||||||
/// Get channel last message
|
/// Get channel last message.
|
||||||
Message? get lastMessage => _channelState.messages.isNotEmpty == true
|
Message? get lastMessage => _channelState.messages.isNotEmpty == true
|
||||||
? _channelState.messages.last
|
? _channelState.messages.last
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
/// Get channel last message
|
/// Get channel last message.
|
||||||
Stream<Message?> get lastMessageStream => messagesStream
|
Stream<Message?> get lastMessageStream => messagesStream
|
||||||
.map((event) => event?.isNotEmpty == true ? event!.last : null);
|
.map((event) => event?.isNotEmpty == true ? event!.last : null);
|
||||||
|
|
||||||
/// 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.
|
||||||
Stream<List<Member>> get membersStream => CombineLatestStream.combine2<
|
Stream<List<Member>> get membersStream => CombineLatestStream.combine2<
|
||||||
List<Member?>?, Map<String?, User?>, List<Member>>(
|
List<Member?>?, Map<String?, User?>, List<Member>>(
|
||||||
channelStateStream.map((cs) => cs.members),
|
channelStateStream.map((cs) => cs.members),
|
||||||
@@ -1605,19 +1619,19 @@ class ChannelClientState {
|
|||||||
members!.map((e) => e!.copyWith(user: users[e.user!.id])).toList(),
|
members!.map((e) => e!.copyWith(user: users[e.user!.id])).toList(),
|
||||||
).distinct(const ListEquality().equals);
|
).distinct(const ListEquality().equals);
|
||||||
|
|
||||||
/// Channel watcher count
|
/// Channel watcher count.
|
||||||
int? get watcherCount => _channelState.watcherCount;
|
int? get watcherCount => _channelState.watcherCount;
|
||||||
|
|
||||||
/// Channel watcher count as a stream
|
/// Channel watcher count as a stream.
|
||||||
Stream<int?> get watcherCountStream =>
|
Stream<int?> get watcherCountStream =>
|
||||||
channelStateStream.map((cs) => cs.watcherCount);
|
channelStateStream.map((cs) => cs.watcherCount);
|
||||||
|
|
||||||
/// Channel watchers list
|
/// Channel watchers list.
|
||||||
List<User> get watchers => _channelState.watchers
|
List<User> get watchers => _channelState.watchers
|
||||||
.map((e) => _channel.client.state.users[e.id] ?? e)
|
.map((e) => _channel.client.state.users[e.id] ?? e)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
/// Channel watchers list as a stream
|
/// Channel watchers list as a stream.
|
||||||
Stream<List<User>> get watchersStream => CombineLatestStream.combine2<
|
Stream<List<User>> get watchersStream => CombineLatestStream.combine2<
|
||||||
List<User>?, Map<String?, User?>, List<User>>(
|
List<User>?, Map<String?, User?>, List<User>>(
|
||||||
channelStateStream.map((cs) => cs.watchers),
|
channelStateStream.map((cs) => cs.watchers),
|
||||||
@@ -1625,20 +1639,20 @@ class ChannelClientState {
|
|||||||
(watchers, users) => watchers!.map((e) => users[e.id] ?? e).toList(),
|
(watchers, users) => watchers!.map((e) => users[e.id] ?? e).toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Channel read list
|
/// Channel read list.
|
||||||
List<Read>? get read => _channelState.read;
|
List<Read>? get read => _channelState.read;
|
||||||
|
|
||||||
/// Channel read list as a stream
|
/// Channel read list as a stream.
|
||||||
Stream<List<Read>?> get readStream => channelStateStream.map((cs) => cs.read);
|
Stream<List<Read>?> get readStream => channelStateStream.map((cs) => cs.read);
|
||||||
|
|
||||||
final BehaviorSubject<int> _unreadCountController = BehaviorSubject.seeded(0);
|
final BehaviorSubject<int> _unreadCountController = BehaviorSubject.seeded(0);
|
||||||
|
|
||||||
set unreadCount(int value) => _unreadCountController.add(value);
|
set unreadCount(int value) => _unreadCountController.add(value);
|
||||||
|
|
||||||
/// Unread count getter as a stream
|
/// Unread count getter as a stream.
|
||||||
Stream<int> get unreadCountStream => _unreadCountController.stream.distinct();
|
Stream<int> get unreadCountStream => _unreadCountController.stream.distinct();
|
||||||
|
|
||||||
/// Unread count getter
|
/// Unread count getter.
|
||||||
int get unreadCount => _unreadCountController.value;
|
int get unreadCount => _unreadCountController.value;
|
||||||
|
|
||||||
bool _countMessageAsUnread(Message message) {
|
bool _countMessageAsUnread(Message message) {
|
||||||
@@ -1654,7 +1668,7 @@ class ChannelClientState {
|
|||||||
!userIsMuted;
|
!userIsMuted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update threads with updated information about messages
|
/// Update threads with updated information about messages.
|
||||||
void updateThreadInfo(String parentId, List<Message> messages) {
|
void updateThreadInfo(String parentId, List<Message> messages) {
|
||||||
final newThreads = Map<String, List<Message>>.from(threads);
|
final newThreads = Map<String, List<Message>>.from(threads);
|
||||||
|
|
||||||
@@ -1676,7 +1690,7 @@ class ChannelClientState {
|
|||||||
_threads = newThreads;
|
_threads = newThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete all channel messages
|
/// Delete all channel messages.
|
||||||
void truncate() {
|
void truncate() {
|
||||||
_channelState = _channelState.copyWith(
|
_channelState = _channelState.copyWith(
|
||||||
messages: [],
|
messages: [],
|
||||||
@@ -1685,7 +1699,7 @@ class ChannelClientState {
|
|||||||
|
|
||||||
final List<String> _updatedMessagesIds = [];
|
final List<String> _updatedMessagesIds = [];
|
||||||
|
|
||||||
/// Update channelState with updated information
|
/// Update channelState with updated information.
|
||||||
void updateChannelState(ChannelState updatedState) {
|
void updateChannelState(ChannelState updatedState) {
|
||||||
final newMessages = <Message>[
|
final newMessages = <Message>[
|
||||||
...updatedState.messages,
|
...updatedState.messages,
|
||||||
@@ -1737,13 +1751,13 @@ class ChannelClientState {
|
|||||||
int _sortByCreatedAt(Message a, Message b) =>
|
int _sortByCreatedAt(Message a, Message b) =>
|
||||||
a.createdAt.compareTo(b.createdAt);
|
a.createdAt.compareTo(b.createdAt);
|
||||||
|
|
||||||
/// The channel state related to this client
|
/// The channel state related to this client.
|
||||||
ChannelState get _channelState => _channelStateController.value;
|
ChannelState get _channelState => _channelStateController.value;
|
||||||
|
|
||||||
/// The channel state related to this client as a stream
|
/// The channel state related to this client as a stream.
|
||||||
Stream<ChannelState> get channelStateStream => _channelStateController.stream;
|
Stream<ChannelState> get channelStateStream => _channelStateController.stream;
|
||||||
|
|
||||||
/// The channel state related to this client
|
/// The channel state related to this client.
|
||||||
ChannelState get channelState => _channelStateController.value;
|
ChannelState get channelState => _channelStateController.value;
|
||||||
late BehaviorSubject<ChannelState> _channelStateController;
|
late BehaviorSubject<ChannelState> _channelStateController;
|
||||||
|
|
||||||
@@ -1754,11 +1768,11 @@ class ChannelClientState {
|
|||||||
_debouncedUpdatePersistenceChannelState.call([v]);
|
_debouncedUpdatePersistenceChannelState.call([v]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The channel threads related to this channel
|
/// The channel threads related to this channel.
|
||||||
Map<String, List<Message>> get threads =>
|
Map<String, List<Message>> get threads =>
|
||||||
_threadsController.value.map((key, value) => MapEntry(key, value));
|
_threadsController.value.map((key, value) => MapEntry(key, value));
|
||||||
|
|
||||||
/// The channel threads related to this channel as a stream
|
/// The channel threads related to this channel as a stream.
|
||||||
Stream<Map<String, List<Message>>> get threadsStream =>
|
Stream<Map<String, List<Message>>> get threadsStream =>
|
||||||
_threadsController.stream;
|
_threadsController.stream;
|
||||||
final BehaviorSubject<Map<String, List<Message>>> _threadsController =
|
final BehaviorSubject<Map<String, List<Message>>> _threadsController =
|
||||||
@@ -1772,10 +1786,10 @@ class ChannelClientState {
|
|||||||
_threadsController.add(v);
|
_threadsController.add(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel related typing users last value
|
/// Channel related typing users last value.
|
||||||
Map<User, Event> get typingEvents => _typingEventsController.value;
|
Map<User, Event> get typingEvents => _typingEventsController.value;
|
||||||
|
|
||||||
/// Channel related typing users stream
|
/// Channel related typing users stream.
|
||||||
Stream<Map<User, Event>> get typingEventsStream =>
|
Stream<Map<User, Event>> get typingEventsStream =>
|
||||||
_typingEventsController.stream;
|
_typingEventsController.stream;
|
||||||
|
|
||||||
@@ -1903,7 +1917,7 @@ class ChannelClientState {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this method to dispose this object
|
/// Call this method to dispose this object.
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_debouncedUpdatePersistenceChannelState.cancel();
|
_debouncedUpdatePersistenceChannelState.cancel();
|
||||||
_unreadCountController.close();
|
_unreadCountController.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user