Merge branch 'develop' into patch-1
This commit is contained in:
@@ -4,15 +4,9 @@ import 'dart:math';
|
||||
import 'package:collection/collection.dart'
|
||||
show IterableExtension, ListEquality;
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:rate_limiter/rate_limiter.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:stream_chat/src/client/retry_queue.dart';
|
||||
import 'package:stream_chat/src/core/error/error.dart';
|
||||
import 'package:stream_chat/src/core/models/attachment_file.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_state.dart';
|
||||
import 'package:stream_chat/src/core/models/user.dart';
|
||||
import 'package:stream_chat/src/core/util/utils.dart';
|
||||
import 'package:stream_chat/src/event_type.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
/// Class that manages a specific channel.
|
||||
@@ -825,7 +819,7 @@ class Channel {
|
||||
final now = DateTime.now();
|
||||
final user = _client.state.currentUser;
|
||||
|
||||
final latestReactions = [...message.latestReactions ?? <Reaction>[]];
|
||||
var latestReactions = [...message.latestReactions ?? <Reaction>[]];
|
||||
if (enforceUnique) {
|
||||
latestReactions.removeWhere((it) => it.userId == user!.id);
|
||||
}
|
||||
@@ -839,10 +833,17 @@ class Channel {
|
||||
extraData: extraData,
|
||||
);
|
||||
|
||||
// Inserting at the 0th index as it's the latest reaction
|
||||
latestReactions.insert(0, newReaction);
|
||||
final ownReactions = [...latestReactions]
|
||||
..removeWhere((it) => it.userId != user!.id);
|
||||
latestReactions = (latestReactions
|
||||
// Inserting at the 0th index as it's the latest reaction
|
||||
..insert(0, newReaction))
|
||||
.take(10)
|
||||
.toList();
|
||||
final ownReactions = enforceUnique
|
||||
? <Reaction>[newReaction]
|
||||
: <Reaction>[
|
||||
...message.ownReactions ?? [],
|
||||
newReaction,
|
||||
];
|
||||
|
||||
final newMessage = message.copyWith(
|
||||
reactionCounts: {...message.reactionCounts ?? <String, int>{}}
|
||||
@@ -882,7 +883,6 @@ class Channel {
|
||||
Reaction reaction,
|
||||
) async {
|
||||
final type = reaction.type;
|
||||
final user = _client.state.currentUser;
|
||||
|
||||
final reactionCounts = {...message.reactionCounts ?? <String, int>{}};
|
||||
if (reactionCounts.containsKey(type)) {
|
||||
@@ -899,8 +899,11 @@ class Channel {
|
||||
r.type == reaction.type &&
|
||||
r.messageId == reaction.messageId);
|
||||
|
||||
final ownReactions = [...latestReactions]
|
||||
..removeWhere((it) => it.userId != user!.id);
|
||||
final ownReactions = message.ownReactions
|
||||
?..removeWhere((r) =>
|
||||
r.userId == reaction.userId &&
|
||||
r.type == reaction.type &&
|
||||
r.messageId == reaction.messageId);
|
||||
|
||||
final newMessage = message.copyWith(
|
||||
reactionCounts: reactionCounts..removeWhere((_, value) => value == 0),
|
||||
@@ -1268,6 +1271,21 @@ class Channel {
|
||||
pagination: pagination,
|
||||
);
|
||||
|
||||
/// Query channel banned users.
|
||||
Future<QueryBannedUsersResponse> queryBannedUsers({
|
||||
Filter? filter,
|
||||
List<SortOption>? sort,
|
||||
PaginationParams? pagination,
|
||||
}) {
|
||||
_checkInitialized();
|
||||
filter ??= Filter.equal('channel_cid', cid!);
|
||||
return _client.queryBannedUsers(
|
||||
filter: filter,
|
||||
sort: sort,
|
||||
pagination: pagination,
|
||||
);
|
||||
}
|
||||
|
||||
/// Mutes the channel.
|
||||
Future<EmptyResponse> mute({Duration? expiration}) {
|
||||
_checkInitialized();
|
||||
@@ -1281,9 +1299,17 @@ class Channel {
|
||||
}
|
||||
|
||||
/// Bans the user with given [userID] from the channel.
|
||||
@Deprecated("Use 'banMember' instead")
|
||||
Future<EmptyResponse> banUser(
|
||||
String userID,
|
||||
Map<String, dynamic> options,
|
||||
) =>
|
||||
banMember(userID, options);
|
||||
|
||||
/// Bans the member with given [userID] from the channel.
|
||||
Future<EmptyResponse> banMember(
|
||||
String userID,
|
||||
Map<String, dynamic> options,
|
||||
) async {
|
||||
_checkInitialized();
|
||||
final opts = Map<String, dynamic>.from(options)
|
||||
@@ -1295,7 +1321,11 @@ class Channel {
|
||||
}
|
||||
|
||||
/// Remove the ban for the user with given [userID] in the channel.
|
||||
Future<EmptyResponse> unbanUser(String userID) async {
|
||||
@Deprecated("Use 'unbanMember' instead")
|
||||
Future<EmptyResponse> unbanUser(String userID) => unbanMember(userID);
|
||||
|
||||
/// Remove the ban for the member with given [userID] in the channel.
|
||||
Future<EmptyResponse> unbanMember(String userID) async {
|
||||
_checkInitialized();
|
||||
return _client.unbanUser(userID, {
|
||||
'type': type,
|
||||
@@ -1466,6 +1496,10 @@ class ChannelClientState {
|
||||
|
||||
_listenMemberRemoved();
|
||||
|
||||
_listenMemberBanned();
|
||||
|
||||
_listenMemberUnbanned();
|
||||
|
||||
_startCleaning();
|
||||
|
||||
_startCleaningPinnedMessages();
|
||||
@@ -1543,6 +1577,7 @@ class ChannelClientState {
|
||||
members: List.from(
|
||||
channelState.members..removeWhere((m) => m.userId == user!.id),
|
||||
),
|
||||
read: channelState.read..removeWhere((r) => r.user.id == user!.id),
|
||||
));
|
||||
}));
|
||||
}
|
||||
@@ -1568,6 +1603,54 @@ class ChannelClientState {
|
||||
}));
|
||||
}
|
||||
|
||||
void _listenMemberBanned() {
|
||||
_subscriptions.add(_channel
|
||||
.on(EventType.userBanned)
|
||||
.where((it) => it.cid != null) // filters channel ban from app ban
|
||||
.listen(
|
||||
(event) async {
|
||||
final user = event.user!;
|
||||
final member = await _channel
|
||||
.queryMembers(filter: Filter.equal('id', user.id))
|
||||
.then((it) => it.members.first);
|
||||
|
||||
_updateMember(member);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
void _listenMemberUnbanned() {
|
||||
_subscriptions.add(_channel
|
||||
.on(EventType.userUnbanned)
|
||||
.where((it) => it.cid != null) // filters channel ban from app ban
|
||||
.listen(
|
||||
(event) async {
|
||||
final user = event.user!;
|
||||
final member = await _channel
|
||||
.queryMembers(filter: Filter.equal('id', user.id))
|
||||
.then((it) => it.members.first);
|
||||
|
||||
_updateMember(member);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
void _updateMember(Member member) {
|
||||
final currentMembers = [...members];
|
||||
final memberIndex = currentMembers.indexWhere(
|
||||
(m) => m.userId == member.userId,
|
||||
);
|
||||
|
||||
if (memberIndex == -1) return;
|
||||
currentMembers[memberIndex] = member;
|
||||
|
||||
updateChannelState(
|
||||
channelState.copyWith(
|
||||
members: currentMembers,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Flag which indicates if [ChannelClientState] contain latest/recent messages or not.
|
||||
///
|
||||
/// This flag should be managed by UI sdks.
|
||||
@@ -1609,10 +1692,19 @@ class ChannelClientState {
|
||||
|
||||
void _listenReactionDeleted() {
|
||||
_subscriptions.add(_channel.on(EventType.reactionDeleted).listen((event) {
|
||||
final userId = _channel.client.state.currentUser!.id;
|
||||
final oldMessage =
|
||||
messages.firstWhereOrNull((it) => it.id == event.message?.id);
|
||||
final reaction = event.reaction;
|
||||
final ownReactions = oldMessage?.ownReactions
|
||||
?.whereNot((it) =>
|
||||
it.type == reaction?.type &&
|
||||
it.score == reaction?.score &&
|
||||
it.messageId == reaction?.messageId &&
|
||||
it.userId == reaction?.userId &&
|
||||
it.extraData == reaction?.extraData)
|
||||
.toList(growable: false);
|
||||
final message = event.message!.copyWith(
|
||||
ownReactions: [...event.message!.latestReactions!]
|
||||
..removeWhere((it) => it.userId != userId),
|
||||
ownReactions: ownReactions,
|
||||
);
|
||||
addMessage(message);
|
||||
}));
|
||||
@@ -1620,10 +1712,10 @@ class ChannelClientState {
|
||||
|
||||
void _listenReactions() {
|
||||
_subscriptions.add(_channel.on(EventType.reactionNew).listen((event) {
|
||||
final userId = _channel.client.state.currentUser!.id;
|
||||
final oldMessage =
|
||||
messages.firstWhereOrNull((it) => it.id == event.message?.id);
|
||||
final message = event.message!.copyWith(
|
||||
ownReactions: [...event.message!.latestReactions!]
|
||||
..removeWhere((it) => it.userId != userId),
|
||||
ownReactions: oldMessage?.ownReactions,
|
||||
);
|
||||
addMessage(message);
|
||||
}));
|
||||
@@ -1636,10 +1728,11 @@ class ChannelClientState {
|
||||
EventType.reactionUpdated,
|
||||
)
|
||||
.listen((event) {
|
||||
final userId = _channel.client.state.currentUser!.id;
|
||||
final oldMessage =
|
||||
messages.firstWhereOrNull((it) => it.id == event.message?.id);
|
||||
|
||||
final message = event.message!.copyWith(
|
||||
ownReactions: [...event.message!.latestReactions!]
|
||||
..removeWhere((it) => it.userId != userId),
|
||||
ownReactions: oldMessage?.ownReactions,
|
||||
);
|
||||
addMessage(message);
|
||||
|
||||
@@ -1734,7 +1827,13 @@ class ChannelClientState {
|
||||
if (replyCount == null || replyCount == 0) return;
|
||||
|
||||
addMessage(parentMessage.copyWith(replyCount: replyCount - 1));
|
||||
updateThreadInfo(parentId, threads[parentId]!..remove(message));
|
||||
updateThreadInfo(
|
||||
parentId,
|
||||
threads[parentId]!
|
||||
..removeWhere(
|
||||
(e) => e.id == message.id,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Remove regular message
|
||||
final allMessages = [...messages];
|
||||
|
||||
@@ -66,8 +66,11 @@ class StreamChatClient {
|
||||
this.logLevel = Level.WARNING,
|
||||
LogHandlerFunction? logHandlerFunction,
|
||||
RetryPolicy? retryPolicy,
|
||||
Location? location,
|
||||
@Deprecated('Use location to change baseUrl instead') String? baseURL,
|
||||
@Deprecated('''
|
||||
Location is now deprecated in favor of the new edge server. Will be removed in v4.0.0.
|
||||
Read more here: https://getstream.io/blog/chat-edge-infrastructure
|
||||
''') Location? location,
|
||||
String? baseURL,
|
||||
Duration connectTimeout = const Duration(seconds: 6),
|
||||
Duration receiveTimeout = const Duration(seconds: 6),
|
||||
StreamChatApi? chatApi,
|
||||
@@ -79,7 +82,6 @@ class StreamChatClient {
|
||||
|
||||
final options = StreamHttpClientOptions(
|
||||
baseUrl: baseURL,
|
||||
location: location,
|
||||
connectTimeout: connectTimeout,
|
||||
receiveTimeout: receiveTimeout,
|
||||
headers: {'X-Stream-Client': defaultUserAgent},
|
||||
@@ -685,6 +687,18 @@ class StreamChatClient {
|
||||
return response;
|
||||
}
|
||||
|
||||
/// Query banned users.
|
||||
Future<QueryBannedUsersResponse> queryBannedUsers({
|
||||
required Filter filter,
|
||||
List<SortOption>? sort,
|
||||
PaginationParams? pagination,
|
||||
}) =>
|
||||
_chatApi.moderation.queryBannedUsers(
|
||||
filter: filter,
|
||||
sort: sort,
|
||||
pagination: pagination,
|
||||
);
|
||||
|
||||
/// A message search.
|
||||
Future<SearchMessagesResponse> search(
|
||||
Filter filter, {
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:stream_chat/src/client/channel.dart';
|
||||
import 'package:stream_chat/src/client/retry_policy.dart';
|
||||
import 'package:stream_chat/src/core/error/error.dart';
|
||||
import 'package:stream_chat/src/core/models/message.dart';
|
||||
import 'package:stream_chat/src/event_type.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
/// The retry queue associated to a channel
|
||||
|
||||
Reference in New Issue
Block a user