addChatMember method
override
Adds an User to a Chat-group by the authority of the authenticated MyUser.
Implementation
@override
Future<void> addChatMember(ChatId chatId, UserId userId) async {
Log.debug('addChatMember($chatId, $userId)', '$runtimeType');
final RxChatImpl? chat = chats[chatId];
final FutureOr<RxUser?> userOrFuture = _userRepo.get(userId);
final RxUser? user = userOrFuture is RxUser?
? userOrFuture
: await userOrFuture;
if (user != null) {
final member = DtoChatMember(
user.user.value,
PreciseDateTime.now(),
null,
);
chat?.members.put(member);
}
try {
try {
await Backoff.run(
() async {
await _graphQlProvider.addChatMember(chatId, userId);
},
retryIf: (e) => e.isNetworkRelated,
retries: 10,
);
} on AddChatMemberException catch (e) {
switch (e.code) {
case AddChatMemberErrorCode.artemisUnknown:
case AddChatMemberErrorCode.blocked:
rethrow;
case AddChatMemberErrorCode.unknownUser:
case AddChatMemberErrorCode.notGroup:
if (user != null) {
chat?.members.remove(user.id);
}
case AddChatMemberErrorCode.unknownChat:
await remove(chatId);
break;
}
}
} catch (_) {
if (user != null) {
chat?.members.remove(user.id);
}
rethrow;
}
// Redial the added member, if [Chat] has an [OngoingCall] happening in it.
if (chats[chatId]?.chat.value.ongoingCall != null) {
await _callRepo.redialChatCallMember(chatId, userId);
}
}