diff --git a/src/api/api.js b/src/api/api.js
index c4da27c8..11444e63 100644
--- a/src/api/api.js
+++ b/src/api/api.js
@@ -9,7 +9,7 @@ class Api {
constructor(baseUrl) {
this.baseUrl = baseUrl;
this.socket = null;
- this.curerntUserId = null;
+ this.currentUserId = null;
this.responsesPromises = {};
this.onMessageListener = null;
this.onMessageStatusListener = null;
@@ -40,6 +40,12 @@ class Api {
);
return;
}
+ if (message.event.conversation_updated) {
+ this.onConversationCreateListener?.(
+ message.event.conversation_updated
+ );
+ return;
+ }
if (message.event.conversation_kicked) {
this.onConversationDeleteListener?.(
message.event.conversation_kicked
@@ -67,7 +73,7 @@ class Api {
if (this.onMessageListener) {
this.onMessageListener(message.message);
}
- if (message.message.from.toString() !== this.curerntUserId) {
+ if (message.message.from !== this.currentUserId) {
EventEmitter.emit("onMessage", message.message);
}
return;
@@ -158,6 +164,7 @@ class Api {
login: data.ulogin,
password: data.pass,
deviceId: getBrowserFingerprint(true),
+ application_id: 6783
},
id: getUniqueId("userLogin"),
},
diff --git a/src/components/generic/chatComponents/ParticipantInChatInfo.js b/src/components/generic/chatComponents/ParticipantInChatInfo.js
index 593c03e4..508972fa 100644
--- a/src/components/generic/chatComponents/ParticipantInChatInfo.js
+++ b/src/components/generic/chatComponents/ParticipantInChatInfo.js
@@ -29,7 +29,7 @@ export default function ParticipantInChatInfo({
if (isCurrentUser) {
return;
}
- navigate(pathname + hash + `/participant?uid=${user._id}`);
+ navigate(pathname + hash + `/participant?uid=${user.native_id}`);
}}
>
{user.login}
diff --git a/src/components/generic/messageComponents/ChatMessage.js b/src/components/generic/messageComponents/ChatMessage.js
index 3baa1956..c1246240 100644
--- a/src/components/generic/messageComponents/ChatMessage.js
+++ b/src/components/generic/messageComponents/ChatMessage.js
@@ -43,7 +43,7 @@ export default function ChatMessage({
return (
{isNextMessageYours ? (
diff --git a/src/components/generic/messageComponents/InformativeMessage.js b/src/components/generic/messageComponents/InformativeMessage.js
index 9917d2d4..c9a9f0de 100644
--- a/src/components/generic/messageComponents/InformativeMessage.js
+++ b/src/components/generic/messageComponents/InformativeMessage.js
@@ -16,7 +16,7 @@ export default function InformativeMessage({
: "informative-message"
}
onClick={() =>
- navigate(pathname + hash + `/participant?uid=${params?.user?._id}`)
+ navigate(pathname + hash + `/participant?uid=${params?.user?.native_id}`)
}
>
{text}
diff --git a/src/components/screens/Login.js b/src/components/screens/Login.js
index 6e63c413..baebd177 100644
--- a/src/components/screens/Login.js
+++ b/src/components/screens/Login.js
@@ -39,7 +39,7 @@ export default function Login() {
const { token: userToken, user: userData } = await api.userLogin(data);
localStorage.setItem("sessionId", userToken);
- api.curerntUserId = userData._id;
+ api.currentUserId = userData.native_id;
navigate("/main");
subscribeForNotifications();
diff --git a/src/components/screens/chat/ChatList.js b/src/components/screens/chat/ChatList.js
index 4300d4d2..3e7caaee 100644
--- a/src/components/screens/chat/ChatList.js
+++ b/src/components/screens/chat/ChatList.js
@@ -37,7 +37,7 @@ export default function ChatList() {
? jwtDecode(localStorage.getItem("sessionId"))
: null;
const currentUser = useMemo(
- () => (userInfo ? participants[userInfo._id] : {}),
+ () => (userInfo ? participants[userInfo.native_id] : {}),
[userInfo, participants]
);
@@ -93,7 +93,7 @@ export default function ChatList() {
const list = [];
for (const obj of conversations) {
const chatName = !obj.name
- ? obj.owner_id === userInfo?._id
+ ? obj.owner_id === userInfo?.native_id
? participants[obj.opponent_id]?.login
: participants[obj.owner_id]?.login
: obj.name;
@@ -117,7 +117,7 @@ export default function ChatList() {
countOfNewMessages={obj.unread_messages_count}
chatType={obj.type}
lastMessage={obj.last_message}
- uId={userInfo?._id}
+ uId={userInfo?.native_id}
/>
);
diff --git a/src/components/screens/chat/MessagesList.js b/src/components/screens/chat/MessagesList.js
index a938ad79..e2a54e54 100644
--- a/src/components/screens/chat/MessagesList.js
+++ b/src/components/screens/chat/MessagesList.js
@@ -139,7 +139,7 @@ export default function MessagesList({ scrollRef }) {
- {getParticipantName(owner_id === userInfo._id ? opponent_id : owner_id)}
+ {getParticipantName(owner_id === userInfo.native_id ? opponent_id : owner_id)}
);
}, [selectedConversation, participants]);
@@ -64,9 +64,9 @@ export default function ChatFormInfo({ closeForm }) {
return null;
}
- return conv.owner_id === userInfo._id
- ? participants[conv.opponent_id]?._id
- : participants[conv.owner_id]?._id;
+ return conv.owner_id === userInfo.native_id
+ ? participants[conv.opponent_id]?.native_id
+ : participants[conv.owner_id]?.native_id;
}, [selectedCID, participants]);
const opponentLastActivity = participants[opponentId]?.recent_activity;
@@ -102,7 +102,7 @@ export default function ChatFormInfo({ closeForm }) {
`/main/#${selectedCID}${
selectedConversation.type === "g"
? "/info"
- : "/opponentinfo?uid=" + participants[opponentId]._id
+ : "/opponentinfo?uid=" + participants[opponentId].native_id
}`
)
}
diff --git a/src/components/screens/chat/chatFormBlocks/ChatFormInputs.js b/src/components/screens/chat/chatFormBlocks/ChatFormInputs.js
index 0d0ef7ce..d0071439 100644
--- a/src/components/screens/chat/chatFormBlocks/ChatFormInputs.js
+++ b/src/components/screens/chat/chatFormBlocks/ChatFormInputs.js
@@ -64,11 +64,11 @@ export default function ChatFormInputs({
}
setIsSendMessageDisable(true);
messageInputEl.current.value = "";
- const mid = userInfo._id + Date.now();
+ const mid = `${userInfo.native_id}${Date.now()}`;
let msg = {
_id: mid,
body: text,
- from: userInfo._id,
+ from: userInfo.native_id,
t: Date.now(),
attachments: files.map((file) => ({
file_id: file.name,
@@ -114,7 +114,7 @@ export default function ChatFormInputs({
msg = {
_id: response.server_mid,
body: text,
- from: userInfo._id,
+ from: userInfo.native_id,
status: "sent",
t: response.t,
attachments: attachments.map((obj, i) => ({
diff --git a/src/components/screens/info/ChatInfoPage.js b/src/components/screens/info/ChatInfoPage.js
index 64a6f31d..b02493e2 100644
--- a/src/components/screens/info/ChatInfoPage.js
+++ b/src/components/screens/info/ChatInfoPage.js
@@ -38,7 +38,7 @@ export default function ChatInfoPage() {
if (!userInfo || !selectedConversation) {
return false;
}
- return userInfo._id === selectedConversation.owner_id?.toString();
+ return userInfo.native_id === selectedConversation.owner_id;
}, [userInfo, selectedConversation]);
window.onkeydown = function (event) {
@@ -71,7 +71,7 @@ export default function ChatInfoPage() {
return null;
}
- const isCurrentUser = u._id === userInfo._id;
+ const isCurrentUser = u.native_id === userInfo.native_id;
const deleteUser = async (event) => {
event.stopPropagation();
@@ -82,7 +82,7 @@ export default function ChatInfoPage() {
const requestData = {
cid: selectedCID,
- participants: { remove: [u._id] },
+ participants: { remove: [u.native_id] },
};
await api.conversationUpdate(requestData);
//remove user form participants field - redux
@@ -90,7 +90,7 @@ export default function ChatInfoPage() {
return (
(userInfo ? participants[userInfo._id] : {}),
+ () => (userInfo ? participants[userInfo.native_id] : {}),
[participants, userInfo]
);
diff --git a/src/components/screens/info/UserSearch.js b/src/components/screens/info/UserSearch.js
index 9d71df59..90158489 100644
--- a/src/components/screens/info/UserSearch.js
+++ b/src/components/screens/info/UserSearch.js
@@ -56,7 +56,7 @@ export default function UserSearch({ type }) {
if (selectedUsers.length) {
const requestData = {
type: selectedUsers.length > 1 ? "g" : "u", //fix it in future
- participants: selectedUsers.map((el) => el._id),
+ participants: selectedUsers.map((el) => el.native_id),
};
selectedUsers.length > 1 &&
(requestData["name"] = window.prompt("Please enter a chat name."));
@@ -75,7 +75,7 @@ export default function UserSearch({ type }) {
event.preventDefault();
if (selectedUsers.length) {
- const addUsersArr = selectedUsers.map((el) => el._id);
+ const addUsersArr = selectedUsers.map((el) => el.native_id);
const requestData = {
cid: selectedCID,
participants: { add: addUsersArr },
@@ -110,12 +110,12 @@ export default function UserSearch({ type }) {
}
setSelectedUsers([...selectedUsers, data]);
- setIgnoreIds([...ignoreIds, data._id]);
- setSearchedUsers(searchedUsers.filter((el) => el._id !== data._id));
+ setIgnoreIds([...ignoreIds, data.native_id]);
+ setSearchedUsers(searchedUsers.filter((el) => el.native_id !== data.native_id));
};
const removeUserToIgnore = async (data) => {
- setSelectedUsers(selectedUsers.filter((el) => el._id !== data._id));
- setIgnoreIds(ignoreIds.filter((id) => id !== data._id));
+ setSelectedUsers(selectedUsers.filter((el) => el.native_id !== data.native_id));
+ setIgnoreIds(ignoreIds.filter((id) => id !== data.native_id));
setSearchedUsers([...searchedUsers, data]);
};
@@ -172,7 +172,7 @@ export default function UserSearch({ type }) {
{selectedUsers.length
? selectedUsers.map((d) => (
removeUserToIgnore(d)}
uLogin={d.login}
/>
@@ -183,7 +183,7 @@ export default function UserSearch({ type }) {
{searchedUsers.length ? (
searchedUsers.map((d) => (
addUserToIgnore(d)}
uLogin={d.login}
/>
diff --git a/src/services/activityService.js b/src/services/activityService.js
index b3b29b51..33943015 100644
--- a/src/services/activityService.js
+++ b/src/services/activityService.js
@@ -11,7 +11,7 @@ class ActivityService {
constructor() {
api.onUserActivityListener = (user) => {
const uId = Object.keys(user)[0];
- store.dispatch(upsertUser({ _id: uId, recent_activity: user[uId] }));
+ store.dispatch(upsertUser({ native_id: +uId, recent_activity: user[uId] }));
};
store.subscribe(() => {
@@ -19,6 +19,11 @@ class ActivityService {
store.getState();
const selectedConversationId = selectedConversation.value.id;
+ if (!selectedConversationId) {
+ this.currentChatId = null
+ return
+ }
+
if (
!conversations.entities[selectedConversationId]?.created_at ||
!participants.ids.length ||
@@ -48,7 +53,7 @@ class ActivityService {
}
const uId =
- this.activeChat.owner_id === userInfo._id
+ this.activeChat.owner_id === userInfo.native_id
? this.activeChat.opponent_id
: this.activeChat.owner_id;
@@ -59,7 +64,7 @@ class ActivityService {
api.subscribeToUserActivity(uId).then((activity) => {
store.dispatch(
upsertUser({
- _id: uId,
+ native_id: +uId,
recent_activity: activity[uId],
})
);
diff --git a/src/services/autoLoginService.js b/src/services/autoLoginService.js
index 342ded79..7ba52dbe 100644
--- a/src/services/autoLoginService.js
+++ b/src/services/autoLoginService.js
@@ -35,7 +35,7 @@ class AutoLoginService {
if (userToken && userToken !== "undefined") {
localStorage.setItem("sessionId", userToken);
- api.curerntUserId = userData._id;
+ api.currentUserId = userData.native_id;
subscribeForNotifications();
store.dispatch(upsertUser(userData));
diff --git a/src/services/conversationsService.js b/src/services/conversationsService.js
index 59046e55..4aa113db 100644
--- a/src/services/conversationsService.js
+++ b/src/services/conversationsService.js
@@ -19,7 +19,7 @@ class ConversationsService {
...chat,
unread_messages_count: chat.unread_messages_count || 0,
messagesIds: [],
- participants: users.map((u) => u._id),
+ participants: users.map((u) => u.native_id),
})
);
store.dispatch(addUsers(users));
diff --git a/src/services/messagesService.js b/src/services/messagesService.js
index 28799fe3..3311c20a 100644
--- a/src/services/messagesService.js
+++ b/src/services/messagesService.js
@@ -44,13 +44,13 @@ class MessagesService {
}
const userInfo = jwtDecode(localStorage.getItem("sessionId"));
- message.from === userInfo._id && (message["status"] = "sent");
+ message.from === userInfo.native_id && (message["status"] = "sent");
store.dispatch(addMessage(message));
let countOfNewMessages = 0;
message.cid === this.currentChatId
? api.markConversationAsRead({ cid: this.currentChatId })
- : (countOfNewMessages = message.from === userInfo._id ? 0 : 1);
+ : (countOfNewMessages = message.from === userInfo.native_id ? 0 : 1);
store.dispatch(
updateLastMessageField({
cid: message.cid,
@@ -66,7 +66,7 @@ class MessagesService {
store.dispatch(
upsertChat({
_id: message.cid,
- participants: [...conv.participants, user._id],
+ participants: [...conv.participants, user.native_id],
})
);
}
@@ -75,7 +75,7 @@ class MessagesService {
store.dispatch(
upsertChat({
_id: message.cid,
- participants: conv.participants.filter((uId) => uId !== user._id),
+ participants: conv.participants.filter((uId) => uId !== user.native_id),
})
);
}
@@ -154,7 +154,7 @@ class MessagesService {
store.dispatch(
upsertParticipants({
cid: this.currentChatId,
- participants: arr.map((obj) => obj._id),
+ participants: arr.map((obj) => obj.native_id),
})
)
);
diff --git a/src/store/Participants.js b/src/store/Participants.js
index 4dcaa8c7..ebc23a85 100644
--- a/src/store/Participants.js
+++ b/src/store/Participants.js
@@ -1,8 +1,8 @@
import { createEntityAdapter, createSlice } from "@reduxjs/toolkit";
export const participantsAdapter = createEntityAdapter({
- selectId: ({ _id }) => _id,
- sortComparer: (a, b) => a._id.localeCompare(b._id),
+ selectId: ({ _id, native_id }) => native_id,
+ sortComparer: (a, b) => typeof a.native_id === 'string' ? a.native_id.localeCompare(b.native_id) : a.native_id - b.native_id,
});
export const {