Skip to content

Commit be761f7

Browse files
duplicate object fixes
1 parent 4c0295f commit be761f7

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

src/MirrorflyChatComponent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export function MirrorflyChatComponent() {
4343
const handleDeepLink = ({ url }) => {
4444
if (url) {
4545
const route = url.replace(getAppSchema(), '');
46-
const [stack, screenWithQuery] = route.split('/');
47-
const [screen, queryString] = screenWithQuery.split('?');
46+
const queryString = route.split('?')[1];
4847
// Manually parse the query string
4948
const params = {};
5049
if (queryString) {

src/components/ChatMessage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function ChatMessage({ chatUser, item, showNickName }) {
4444
useFocusEffect(
4545
React.useCallback(() => {
4646
if (useXmppStatus === CONNECTED && !isSender && msgStatus !== 2 && deleteStatus === 0 && recallStatus === 0) {
47+
console.log('useXmppStatus ==>', useXmppStatus, isSender, msgStatus, deleteStatus, recallStatus);
4748
const groupId = MIX_BARE_JID.test(chatUser) ? getUserIdFromJid(chatUser) : '';
4849
sendSeenStatus(publisherJid, msgId, groupId);
4950
}

src/redux/chatMessageDataSlice.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ const chatMessageDataSlice = createSlice({
1111
initialState,
1212
reducers: {
1313
setChatMessages(state, action) {
14+
const removeDuplicates = messages => {
15+
const seen = new Set();
16+
return messages.filter(message => {
17+
const isDuplicate = seen.has(message.msgId);
18+
seen.add(message.msgId);
19+
return !isDuplicate;
20+
});
21+
};
1422
const { userJid = '', data } = action.payload;
1523
const userId = getUserIdFromJid(userJid);
1624
if (!Array.isArray(data)) return;
1725
if (state[userId]) {
18-
state[userId] = [...state[userId], ...data];
26+
// Merge existing messages with new ones
27+
state[userId] = removeDuplicates([...state[userId], ...data]);
1928
} else {
29+
// Add new messages if userId does not exist
2030
state[userId] = data;
2131
}
2232
},

src/redux/recentChatDataSlice.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@ const recentChatDataSlice = createSlice({
1414
initialState,
1515
reducers: {
1616
setRecentChats(state, action) {
17-
state.recentChats = [...state.recentChats, ...action.payload];
17+
const newChats = action.payload;
18+
19+
// Create a map of existing chats by userJid for quick lookup
20+
const existingChatsMap = state.recentChats.reduce((acc, chat) => {
21+
acc[chat.userJid] = chat;
22+
return acc;
23+
}, {});
24+
25+
// Merge the new chats into the existing ones, prioritizing new chats
26+
const updatedChats = [
27+
...Object.values(existingChatsMap),
28+
...newChats.filter(chat => !existingChatsMap[chat.userJid]),
29+
];
30+
31+
// Update the state with the combined result
32+
state.recentChats = updatedChats;
1833
},
1934
addRecentChatItem(state, action) {
2035
const { userJid, newIndex = 0, archiveSetting, publisherId } = action.payload;

src/uikitMethods.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export const mirrorflyProfileUpdate = async ({ nickName, image, status, mobileNu
225225
updatedMobileNumber,
226226
updatedEmail,
227227
);
228+
currentScreen = RECENTCHATSCREEN;
228229
return UserInfo;
229230
};
230231

0 commit comments

Comments
 (0)