File tree Expand file tree Collapse file tree
api/src/main/java/com/getcode/network Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,6 +131,7 @@ class ConversationStreamController @Inject constructor(
131131 val updates = result.getOrNull() ? : return @result
132132 val (messages, pointers) = updates
133133
134+ historyController.updateChatWithMessages(chat, messages)
134135 val messagesWithContent = messages.map {
135136 messageWithContentMapper.map(chat.id to it)
136137 }
Original file line number Diff line number Diff line change @@ -83,22 +83,26 @@ class HistoryController @Inject constructor(
8383 chat = _chats .value?.find { it.id == chatId },
8484 onMessagesFetched = { messages ->
8585 val chat = _chats .value?.find { it.id == chatId } ? : return @ChatMessagePagingSource
86- val updatedMessages = (chat.messages + messages).distinctBy { it.id }
87- val updatedChat = chat.copy(messages = updatedMessages)
88- val chats = _chats .value?.map {
89- if (it.id == updatedChat.id) {
90- updatedChat
91- } else {
92- it
93- }
94- }
95- _chats .update { chats }
86+ updateChatWithMessages(chat, messages)
9687 }
9788 ).also {
9889 pagerMap[chatId] = it
9990 }
10091 }
10192
93+ fun updateChatWithMessages (chat : Chat , messages : List <ChatMessage >) {
94+ val updatedMessages = (chat.messages + messages).distinctBy { it.id }
95+ val updatedChat = chat.copy(messages = updatedMessages)
96+ val chats = _chats .value?.map {
97+ if (it.id == updatedChat.id) {
98+ updatedChat
99+ } else {
100+ it
101+ }
102+ }
103+ _chats .update { chats }
104+ }
105+
102106 fun chatFlow (chatId : ID ) =
103107 chatFlows[chatId] ? : chatMessagePager(chatId).flow.cachedIn(GlobalScope ).also {
104108 chatFlows[chatId] = it
You can’t perform that action at this time.
0 commit comments