progress on slow mode

This commit is contained in:
groovinchip
2021-07-26 11:42:24 -04:00
parent 848aa550f7
commit 9fb60e93c1
9 changed files with 178 additions and 16 deletions
@@ -130,6 +130,9 @@ class Channel {
return state?.channelStateStream.map((cs) => cs.channel?.cooldown);
}
///
DateTime? cooldownStartedAt;
/// Channel creation date
DateTime? get createdAt {
_checkInitialized();
@@ -429,6 +432,9 @@ class Channel {
skipPush: skipPush,
);
state!.addMessage(response.message);
if (cooldown! > 0) {
cooldownStartedAt = DateTime.now();
}
return response;
} catch (e) {
if (e is StreamChatNetworkError && e.isRetriable) {
@@ -827,6 +833,20 @@ class Channel {
return _client.updateChannelPartial(id!, type, set: set, unset: unset);
}
/// Enable slow mode
Future<UpdateChannelResponse> enableSlowMode({
required int cooldownInterval,
}) async {
_checkInitialized();
return _client.enableSlowdown(id!, type, cooldownInterval);
}
/// Disable slow mode
Future<UpdateChannelResponse> disableSlowMode() async {
_checkInitialized();
return _client.disableSlowdown(id!, type);
}
/// Delete this channel. Messages are permanently removed.
Future<EmptyResponse> delete() async {
_checkInitialized();
@@ -1244,6 +1244,28 @@ class StreamChatClient {
language,
);
/// Enables slow mode
Future<UpdateChannelResponse> enableSlowdown(
String channelId,
String channelType,
int cooldown,
) async =>
_chatApi.channel.enableSlowdown(
channelId,
channelType,
cooldown,
);
/// Disables slow mode
Future<UpdateChannelResponse> disableSlowdown(
String channelId,
String channelType,
) async =>
_chatApi.channel.disableSlowdown(
channelId,
channelType,
);
/// Pins provided message
/// [timeoutOrExpirationDate] can either be a [DateTime] or a value in seconds
/// to be added to [DateTime.now]