feat: добавил создание канала. Возможности модерации пока нет.

This commit is contained in:
Jganenokk
2026-07-25 16:12:17 +07:00
parent d0fb5e317f
commit 50acd58a9e
3 changed files with 316 additions and 6 deletions
+32 -5
View File
@@ -1435,6 +1435,33 @@ class ChatsModule {
required String title,
required List<int> userIds,
bool notify = true,
}) => _createChat(
api,
chatType: 'CHAT',
title: title,
userIds: userIds,
notify: notify,
);
Future<CachedChat?> createChannel(
Api api, {
required String title,
List<int> userIds = const [],
bool notify = true,
}) => _createChat(
api,
chatType: 'CHANNEL',
title: title,
userIds: userIds,
notify: notify,
);
Future<CachedChat?> _createChat(
Api api, {
required String chatType,
required String title,
required List<int> userIds,
required bool notify,
}) async {
final payload = {
'message': {
@@ -1443,7 +1470,7 @@ class ChatsModule {
{
'_type': 'CONTROL',
'event': 'new',
'chatType': 'CHAT',
'chatType': chatType,
'title': title,
'userIds': userIds,
},
@@ -1453,22 +1480,22 @@ class ChatsModule {
};
final packet = await api.sendRequest(Opcode.msgSend, payload);
if (!packet.isOk) {
logger.w('createGroupChat: server error payload=${packet.payload}');
logger.w('_createChat($chatType): server error payload=${packet.payload}');
return null;
}
final data = packet.payload;
if (data is! Map) {
logger.w('createGroupChat: payload is not a Map: $data');
logger.w('_createChat($chatType): payload is not a Map: $data');
return null;
}
final chat = data['chat'];
if (chat is! Map) {
logger.w('createGroupChat: response has no chat field: $data');
logger.w('_createChat($chatType): response has no chat field: $data');
return null;
}
final accountId = await TokenStorage.getActiveAccountId();
if (accountId == null) {
logger.w('createGroupChat: no active account id');
logger.w('_createChat($chatType): no active account id');
return null;
}
return cacheServerChat(chat, accountId);