feat: complete interactive audio player, contact resolver, unread clearance, and media sending

This commit is contained in:
Hamza-Ayed
2026-05-18 16:51:29 +03:00
parent 56f29b8306
commit 25bdf1fba1
6 changed files with 267 additions and 30 deletions

View File

@@ -57,10 +57,26 @@ class ConversationsController extends GetxController {
final parts = c.id.split('@');
final phoneNumber = parts[0];
final matchedName = Get.find<ContactsService>().getContactName(phoneNumber, c.name);
final contactsService = Get.find<ContactsService>();
// Try matching using c.name (which has the formatted number string, e.g. "+962 7 8152 3783")
String matchedName = contactsService.getContactName(c.name, c.name);
// If it didn't match (i.e. returned c.name), try matching using phoneNumber
if (matchedName == c.name) {
matchedName = contactsService.getContactName(phoneNumber, c.name);
}
return c.copyWith(name: matchedName);
}
void clearUnreadCount(String chatId) {
final index = conversations.indexWhere((c) => c.id == chatId);
if (index != -1) {
conversations[index] = conversations[index].copyWith(unreadCount: 0);
_saveConversationsToCache(conversations.map((c) => c.toJson()).toList());
}
}
// ── Local Caching ────────────────────────────────────────────────────────
Future<void> _loadCachedConversations() async {
try {
@@ -156,10 +172,11 @@ class ConversationsController extends GetxController {
final index = conversations.indexWhere((c) => c.id == chatId);
if (index != -1) {
final existing = conversations[index];
final isCurrentActiveChat = _svc.activeChatId.value == chatId;
final updated = existing.copyWith(
lastMessage: lastMsg,
timestamp: lastMsg.timestamp,
unreadCount: lastMsg.fromMe ? existing.unreadCount : existing.unreadCount + 1,
unreadCount: (lastMsg.fromMe || isCurrentActiveChat) ? 0 : existing.unreadCount + 1,
);
conversations.removeAt(index);
conversations.insert(0, updated);