feat: Enable direct chat initiation from agent network, improve GIF rendering in chat, and fix message order and webview authentication.

This commit is contained in:
pradeepkumar
2026-03-15 01:04:36 +05:30
parent 84e9cd9680
commit f659be07ae
5 changed files with 146 additions and 48 deletions

View File

@@ -221,11 +221,14 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
page: nextPage,
);
final newMessages = result.messages;
// API returns chronological order (oldest first), but our ListView is
// reverse: true so we need newest-first order (index 0 = newest).
final newMessages = result.messages.reversed.toList();
final paginationInfo = result.pagination;
final existingMessages =
loadMore ? (state.messages[conversationId] ?? []) : <ChatMessage>[];
// When loading more (older messages), append to end (older = higher index)
final mergedMessages =
loadMore ? [...existingMessages, ...newMessages] : newMessages;
@@ -404,6 +407,36 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
return null;
}
}
Future<String?> startConversationWithUser(String userId) async {
if (!mounted) return null;
state = state.copyWith(isLoadingConversations: true, clearError: true);
try {
final conversation =
await _repository.startConversationWithUser(userId);
if (!mounted) return conversation.id;
final exists = state.conversations.any((c) => c.id == conversation.id);
final updatedConversations = exists
? state.conversations
: [conversation, ...state.conversations];
state = state.copyWith(
conversations: updatedConversations,
isLoadingConversations: false,
);
return conversation.id;
} catch (_) {
if (mounted) {
state = state.copyWith(
isLoadingConversations: false,
error: 'Failed to start conversation',
);
}
return null;
}
}
}
final messagingProvider =