feat/fix: Все кнопки в экране профиля(кроме жалоб). Фикс ожирения бабла. Новые сообщения теперь не тянут вниз если ты отлистал
This commit is contained in:
@@ -333,6 +333,7 @@ class AccountModule {
|
||||
ContactCache.clear();
|
||||
TranscriptionCache.clear();
|
||||
ComplaintsModule.clear();
|
||||
ContactsModule.clearBlockedCache();
|
||||
banners.clear();
|
||||
chats.resetForAccountSwitch();
|
||||
|
||||
@@ -348,6 +349,7 @@ class AccountModule {
|
||||
ContactCache.clear();
|
||||
TranscriptionCache.clear();
|
||||
ComplaintsModule.clear();
|
||||
ContactsModule.clearBlockedCache();
|
||||
banners.clear();
|
||||
chats.resetForAccountSwitch();
|
||||
|
||||
@@ -380,6 +382,7 @@ class AccountModule {
|
||||
ContactCache.clear();
|
||||
TranscriptionCache.clear();
|
||||
ComplaintsModule.clear();
|
||||
ContactsModule.clearBlockedCache();
|
||||
banners.clear();
|
||||
chats.resetForAccountSwitch();
|
||||
await ContactsModule.primeCacheFromDb(accountId);
|
||||
@@ -431,6 +434,7 @@ class AccountModule {
|
||||
ContactCache.clear();
|
||||
TranscriptionCache.clear();
|
||||
ComplaintsModule.clear();
|
||||
ContactsModule.clearBlockedCache();
|
||||
banners.clear();
|
||||
chats.resetForAccountSwitch();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import '../api.dart';
|
||||
import '../../core/protocol/opcode_map.dart';
|
||||
import '../../core/protocol/packet.dart';
|
||||
|
||||
class ComplaintReason {
|
||||
final int reasonId;
|
||||
@@ -9,6 +10,8 @@ class ComplaintReason {
|
||||
}
|
||||
|
||||
class ComplaintsModule {
|
||||
static const int userTypeId = 6;
|
||||
|
||||
static Map<int, List<ComplaintReason>>? _cache;
|
||||
|
||||
static void clear() => _cache = null;
|
||||
@@ -17,10 +20,15 @@ class ComplaintsModule {
|
||||
final cached = _cache;
|
||||
if (cached != null) return cached;
|
||||
|
||||
final response = await api.sendRequest(Opcode.complainReasonsGet, {
|
||||
'complainSync': 0,
|
||||
});
|
||||
if (!response.isOk) return cached ?? const {};
|
||||
final Packet response;
|
||||
try {
|
||||
response = await api.sendRequest(Opcode.complainReasonsGet, {
|
||||
'complainSync': 0,
|
||||
}, silent: true);
|
||||
} catch (_) {
|
||||
return const {};
|
||||
}
|
||||
if (!response.isOk) return const {};
|
||||
|
||||
final payload = response.payload;
|
||||
if (payload is! Map) return const {};
|
||||
@@ -65,14 +73,19 @@ class ComplaintsModule {
|
||||
required int reasonId,
|
||||
required int typeId,
|
||||
required List<int> ids,
|
||||
required int parentId,
|
||||
int? parentId,
|
||||
}) async {
|
||||
final response = await api.sendRequest(Opcode.complain, {
|
||||
'reasonId': reasonId,
|
||||
'typeId': typeId,
|
||||
'ids': ids,
|
||||
'parentId': parentId,
|
||||
});
|
||||
final Packet response;
|
||||
try {
|
||||
response = await api.sendRequest(Opcode.complain, {
|
||||
'reasonId': reasonId,
|
||||
'typeId': typeId,
|
||||
'ids': ids,
|
||||
'parentId': ?parentId,
|
||||
}, silent: true);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
if (!response.isOk) return false;
|
||||
final payload = response.payload;
|
||||
return payload is Map && payload['success'] == true;
|
||||
|
||||
@@ -328,6 +328,70 @@ class ContactsModule {
|
||||
return true;
|
||||
}
|
||||
|
||||
static final Set<int> _blockedIds = <int>{};
|
||||
static bool _blockedLoaded = false;
|
||||
|
||||
static void clearBlockedCache() {
|
||||
_blockedIds.clear();
|
||||
_blockedLoaded = false;
|
||||
}
|
||||
|
||||
static const int _blockedPageSize = 100;
|
||||
static const int _blockedMaxPages = 20;
|
||||
|
||||
static Future<bool> isBlocked(Api api, int contactId) async {
|
||||
if (!_blockedLoaded) await _loadBlockedIds(api);
|
||||
return _blockedIds.contains(contactId);
|
||||
}
|
||||
|
||||
static Future<void> _loadBlockedIds(Api api) async {
|
||||
final ids = <int>{};
|
||||
try {
|
||||
for (var page = 0; page < _blockedMaxPages; page++) {
|
||||
final map = await api.sendRequestMap(Opcode.contactList, {
|
||||
'status': 'BLOCKED',
|
||||
'count': _blockedPageSize,
|
||||
'from': page * _blockedPageSize,
|
||||
});
|
||||
final contacts = map?['contacts'];
|
||||
if (contacts is! List) return;
|
||||
ids.addAll(
|
||||
contacts.whereType<Map>().map((c) => c['id']).whereType<int>(),
|
||||
);
|
||||
if (contacts.length < _blockedPageSize) break;
|
||||
}
|
||||
} catch (e) {
|
||||
logger.w('Не удалось получить список заблокированных: $e');
|
||||
return;
|
||||
}
|
||||
_blockedIds
|
||||
..clear()
|
||||
..addAll(ids);
|
||||
_blockedLoaded = true;
|
||||
}
|
||||
|
||||
static Future<bool> setBlocked(Api api, int contactId, bool blocked) async {
|
||||
try {
|
||||
final packet = await api.sendRequest(Opcode.contactUpdate, {
|
||||
'contactId': contactId,
|
||||
'action': blocked ? 'BLOCK' : 'UNBLOCK',
|
||||
});
|
||||
if (packet.isError) return false;
|
||||
} catch (e) {
|
||||
logger.w('setBlocked $contactId: $e');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (blocked) {
|
||||
_blockedIds.add(contactId);
|
||||
} else {
|
||||
_blockedIds.remove(contactId);
|
||||
}
|
||||
ContactInfoFetch.invalidate(contactId);
|
||||
revision.value++;
|
||||
return true;
|
||||
}
|
||||
|
||||
static Future<void> syncFromLoginPayload(
|
||||
Map<dynamic, dynamic> data,
|
||||
int accountId,
|
||||
|
||||
Reference in New Issue
Block a user