Кэширование ID пользователей из чатов (на 24 часа)

This commit is contained in:
needle10
2025-11-22 21:38:48 +03:00
parent bf995d8358
commit 321720cd0a
15 changed files with 669 additions and 238 deletions

View File

@@ -40,7 +40,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
super.initState();
_currentContact = widget.initialContact;
_contactSubscription = ApiService.instance.contactUpdates.listen((contact) {
if (contact.id == _currentContact.id && mounted) {
ApiService.instance.updateCachedContact(contact);
@@ -50,17 +49,14 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
}
});
_membersSubscription = ApiService.instance.messages.listen((message) {
if (message['type'] == 'group_members' && mounted) {
_handleGroupMembersResponse(message['payload']);
}
});
_loadMembersFromCache();
if (_loadedMembers.length < 50) {
_loadedMembers.clear();
_loadedMemberIds.clear();
@@ -69,7 +65,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
ApiService.instance.getGroupMembers(widget.chatId, marker: 0, count: 50);
_isLoadingMembers = true;
} else {
_lastMarker = _loadedMembers.isNotEmpty
? _loadedMembers.last['id'] as int?
: null;
@@ -81,7 +76,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
);
}
_scrollController.addListener(_onScroll);
}
@@ -109,7 +103,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
return;
}
List<dynamic> membersRaw = [];
if (currentChat['members'] is List) {
membersRaw = currentChat['members'] as List<dynamic>;
@@ -163,31 +156,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
);
}
void _handleGroupMembersResponse(Map<String, dynamic> payload) {
print(
'DEBUG: _handleGroupMembersResponse вызван с payload: ${payload.keys}',
@@ -383,7 +351,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
),
),
);
}
},
),
@@ -426,7 +393,7 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
if (contact != null) {
removableMembers.add({
'id': id,
'name': contact['names']?[0]?['name'] ?? 'Неизвестный',
'name': contact['names']?[0]?['name'] ?? 'ID $id',
'contact': contact,
});
}
@@ -456,7 +423,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
content: Text('Удалено ${selectedMembers.length} участников'),
),
);
}
},
),
@@ -499,7 +465,7 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
if (contact != null) {
promotableMembers.add({
'id': id,
'name': contact['names']?[0]?['name'] ?? 'Неизвестный',
'name': contact['names']?[0]?['name'] ?? 'ID $id',
'contact': contact,
});
}
@@ -553,7 +519,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
ApiService.instance.leaveGroup(widget.chatId);
if (mounted) {
Navigator.of(context)
..pop()
..pop();
@@ -708,7 +673,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
Widget _buildGroupManagementButtons() {
final colorScheme = Theme.of(context).colorScheme;
bool amIAdmin = false;
final currentChat = _getCurrentGroupChat();
if (currentChat != null) {
@@ -777,7 +741,6 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
const SizedBox(height: 8),
],
SizedBox(
width: double.infinity,
child: FilledButton.icon(
@@ -837,12 +800,12 @@ class _GroupSettingsScreenState extends State<GroupSettingsScreen> {
final fullName = '$firstName $lastName'.trim();
name = fullName.isNotEmpty
? fullName
: (nameData['name'] as String? ?? 'Неизвестный');
: (nameData['name'] as String? ?? 'ID $id');
}
}
}
if (name == null || name.isEmpty) {
name = 'Неизвестный';
name = 'ID $id';
}
avatarUrl =
contact?['baseUrl'] as String? ?? contact?['baseRawUrl'] as String?;
@@ -1050,7 +1013,8 @@ class _AddMemberDialogState extends State<_AddMemberDialog> {
itemBuilder: (context, index) {
final contact = widget.contacts[index];
final contactId = contact['id'] as int;
final contactName = contact['names']?[0]?['name'] ?? 'Неизвестный';
final contactName =
contact['names']?[0]?['name'] ?? 'ID $contactId';
final isSelected = _selectedContacts.contains(contactId);
return CheckboxListTile(

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:io';
import 'dart:math';
import 'package:gwid/api/api_service.dart';
class StorageScreen extends StatefulWidget {
final bool isModal;
@@ -114,12 +115,39 @@ class _StorageScreenState extends State<StorageScreen>
}
Future<void> _clearCache() async {
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Очистить кэш'),
content: const Text(
'Это действие очистит весь кэш приложения, включая кэш сообщений, медиафайлов и аватаров. '
'Это действие нельзя отменить.',
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Отмена'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
style: TextButton.styleFrom(foregroundColor: Colors.orange),
child: const Text('Очистить'),
),
],
),
);
if (confirmed != true) return;
try {
ApiService.instance.clearAllCaches();
final cacheDir = await getTemporaryDirectory();
if (await cacheDir.exists()) {
await cacheDir.delete(recursive: true);
await cacheDir.create();
}
await _loadStorageInfo();
if (mounted) {