feat: sort conversations by favorite status then by last message time.
This commit is contained in:
@@ -255,6 +255,16 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
state = state.copyWith(isLoadingConversations: true, clearError: true);
|
||||
try {
|
||||
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(
|
||||
conversations: result,
|
||||
isLoadingConversations: false,
|
||||
|
||||
Reference in New Issue
Block a user