From d353c59f01b2b7311e9a1996bc40f2515fbef9a6 Mon Sep 17 00:00:00 2001 From: ptchaya_p Date: Mon, 5 Aug 2024 16:21:12 +0700 Subject: [PATCH 1/2] fix: filter out unsynced message --- src/screens/ChatRoom/ChatRoom.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/screens/ChatRoom/ChatRoom.tsx b/src/screens/ChatRoom/ChatRoom.tsx index e8c5b8a..64885c7 100644 --- a/src/screens/ChatRoom/ChatRoom.tsx +++ b/src/screens/ChatRoom/ChatRoom.tsx @@ -166,15 +166,22 @@ const ChatRoom: ChatRoomScreenComponentType = ({ route }) => { disposers.push( MessageRepository.getMessages( { subChannelId: channelId, limit: 10, includeDeleted: true }, - (value) => { - const messages = value.data; - - // mark the last message as read - if (messages.length > 0) { - const lastMessage = messages[0]; - lastMessage.markRead(); + ({ data: messages, loading, error }) => { + if (!loading && messages) { + // filter syned message since UIKIT did not support unsync message yet + const syncedMessages = messages.filter( + (message) => + !message.syncState || message.syncState === 'synced' + ); + + // mark the last message as read + if (syncedMessages.length > 0) { + const lastMessage = messages[0]; + lastMessage.markRead(); + } + + setMessagesData({ data: syncedMessages, loading, error }); } - setMessagesData(value); } ) ); From 7b44a70f291ca6a0dc76faec78bde8bb731fe164 Mon Sep 17 00:00:00 2001 From: ptchaya_p Date: Mon, 5 Aug 2024 16:36:46 +0700 Subject: [PATCH 2/2] fix: remove unused --- src/routes/ChatNavigator.tsx | 1 - src/screens/RecentChat/RecentChat.tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/routes/ChatNavigator.tsx b/src/routes/ChatNavigator.tsx index ad3a38c..658607d 100644 --- a/src/routes/ChatNavigator.tsx +++ b/src/routes/ChatNavigator.tsx @@ -14,7 +14,6 @@ import { ChatRoomSetting } from '../screens/ChatDetail/ChatRoomSetting'; import { EditChatRoomDetail } from '../screens/EditChatDetail/EditChatRoomDetail'; import MemberDetail from '../screens/MemberDetail/MemberDetail'; import ChatRoom from '../screens/ChatRoom/ChatRoom'; -import useAuth from '../hooks/useAuth'; export default function ChatNavigator() { const Stack = createNativeStackNavigator(); diff --git a/src/screens/RecentChat/RecentChat.tsx b/src/screens/RecentChat/RecentChat.tsx index 08a7756..912bb06 100644 --- a/src/screens/RecentChat/RecentChat.tsx +++ b/src/screens/RecentChat/RecentChat.tsx @@ -9,7 +9,7 @@ import ChatList, { } from '../../components/ChatList/index'; import useAuth from '../../hooks/useAuth'; import { useEffect, useState } from 'react'; -import moment, { locale } from 'moment'; +import moment from 'moment'; import { useStyles } from './styles'; import CustomText from '../../components/CustomText';