fix: какое то уведомление при входе в незнакомые каналы
This commit is contained in:
@@ -266,7 +266,11 @@ class Api {
|
||||
}
|
||||
|
||||
/// Отправляет запрос и ждёт ответ от сервера.
|
||||
Future<Packet> sendRequest(int opcode, Map<dynamic, dynamic> payload) async {
|
||||
Future<Packet> sendRequest(
|
||||
int opcode,
|
||||
Map<dynamic, dynamic> payload, {
|
||||
bool silent = false,
|
||||
}) async {
|
||||
final session = _session;
|
||||
if (session == null) {
|
||||
throw StateError('Нет соединения (${Opcode.name(opcode)})');
|
||||
@@ -296,7 +300,7 @@ class Api {
|
||||
throw ex;
|
||||
}
|
||||
final text = _serverErrorText(packet.payload);
|
||||
if (text != null) _errorController.add(text);
|
||||
if (text != null && !silent) _errorController.add(text);
|
||||
final err = PacketError(
|
||||
messageFromErrorPayload(packet.payload),
|
||||
errorKey: resp.errorKey,
|
||||
|
||||
@@ -399,7 +399,7 @@ class ChatsModule {
|
||||
'chatId': chatId,
|
||||
'messageId': msgIdNum,
|
||||
'mark': mark,
|
||||
});
|
||||
}, silent: true);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ class ChatsModule {
|
||||
'chatId': chatId,
|
||||
'messageId': msgIdNum,
|
||||
'mark': mark,
|
||||
});
|
||||
}, silent: true);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -1348,12 +1348,36 @@ class ChatsModule {
|
||||
await api.sendRequest(Opcode.chatSubscribe, {
|
||||
'chatId': chatId,
|
||||
'subscribe': subscribe,
|
||||
});
|
||||
}, silent: true);
|
||||
} catch (e) {
|
||||
logger.w('subscribeChat failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<({CachedChat chat, int? subscribersCount})> joinChannel(
|
||||
Api api,
|
||||
String link,
|
||||
int accountId,
|
||||
) async {
|
||||
final packet = await api.sendRequest(Opcode.chatJoin, {
|
||||
'link': link,
|
||||
}, silent: true);
|
||||
if (!packet.isOk) {
|
||||
throw PacketError(messageFromErrorPayload(packet.payload));
|
||||
}
|
||||
final payload = packet.payload;
|
||||
final chatMap = payload is Map ? payload['chat'] : null;
|
||||
if (chatMap is! Map) {
|
||||
throw const PacketError('Не удалось подписаться');
|
||||
}
|
||||
final cached = await cacheServerChat(chatMap, accountId);
|
||||
if (cached == null) {
|
||||
throw const PacketError('Не удалось подписаться');
|
||||
}
|
||||
final count = chatMap['participantsCount'];
|
||||
return (chat: cached, subscribersCount: count is int ? count : null);
|
||||
}
|
||||
|
||||
Future<bool> ensureChatCached(Api api, int accountId, int chatId) async {
|
||||
final rows = await AppDatabase.loadChat(accountId, chatId);
|
||||
if (rows.isNotEmpty) return true;
|
||||
|
||||
Reference in New Issue
Block a user