feat: sort conversations by favorite status then by last message time.

This commit is contained in:
pradeepkumar
2026-03-20 02:34:11 +05:30
parent 858c912df9
commit 38423d1586

View File

@@ -255,6 +255,16 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
state = state.copyWith(isLoadingConversations: true, clearError: true); state = state.copyWith(isLoadingConversations: true, clearError: true);
try { try {
final result = await _repository.getConversations(); final result = await _repository.getConversations();
// Sort: favorites first, then by lastMessageAt
final currentUserId = _currentUserId;
result.sort((a, b) {
final aFav = a.userId == currentUserId ? a.userFavorited : a.agentFavorited;
final bFav = b.userId == currentUserId ? b.userFavorited : b.agentFavorited;
if (aFav != bFav) return aFav ? -1 : 1;
final aTime = a.lastMessageAt ?? '';
final bTime = b.lastMessageAt ?? '';
return bTime.compareTo(aTime);
});
state = state.copyWith( state = state.copyWith(
conversations: result, conversations: result,
isLoadingConversations: false, isLoadingConversations: false,