Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SK-258 added create session method, session sync #133

Merged
merged 12 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@testing-library/user-event": "^13.5.0",
"blurhash": "^2.0.5",
"browser-image-compression": "^2.0.2",
"buffer": "^6.0.3",
"dotenv": "^16.0.3",
"framer-motion": "^8.0.2",
"get-browser-fingerprint": "^3.2.0",
Expand Down
21 changes: 10 additions & 11 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Api {
this.baseUrl = baseUrl;
this.socket = null;
this.curerntUserId = null;
this.currentDeviceId = null;
this.responsesPromises = {};
this.onMessageListener = null;
this.onMessageStatusListener = null;
Expand Down Expand Up @@ -171,27 +172,23 @@ class Api {
}

async userLogin(data) {
const deviceId = getBrowserFingerprint({
enableScreen: false,
hardwareOnly: true,
});
const requestData = {
request: {
user_login: data.token
? {
token: data.token,
deviceId: getBrowserFingerprint({
enableScreen: false,
hardwareOnly: true,
}),
}
? { token: data.token, deviceId }
: {
login: data.login,
password: data.password,
deviceId: getBrowserFingerprint({
enableScreen: false,
hardwareOnly: true,
}),
deviceId,
},
id: getUniqueId("userLogin"),
},
};
api.currentDeviceId = deviceId.toString();
const resObjKey = null;
return this.sendPromise(requestData, resObjKey);
}
Expand Down Expand Up @@ -257,6 +254,7 @@ class Api {
},
};
const resObjKey = "success";
localStorage.removeItem("sessionId");
return this.sendPromise(requestData, resObjKey);
}

Expand Down Expand Up @@ -348,6 +346,7 @@ class Api {
body: data.body,
cid: data.cid,
attachments: data.attachments,
encrypted_message_type: data.encrypted_message_type,
},
};
this.responsesPromises[requestData.message.id] = { resolve, reject };
Expand Down
1 change: 0 additions & 1 deletion src/assets/icons/encryption/ResetAccount.svg

This file was deleted.

3 changes: 3 additions & 0 deletions src/components/auth/components/LoginLinks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import OvalLoader from "@components/_helpers/OvalLoader";
import encryptionService from "@services/encryptionService";
import navigateTo from "@utils/navigation/navigate_to";
import showCustomAlert from "@utils/show_alert";
import subscribeForNotifications from "@services/notifications";
Expand All @@ -21,6 +22,8 @@ export default function LoginLinks({ changePage, content }) {
setIsLoader(true);
try {
const userData = await usersService.login(content);
await encryptionService.clearStoredAccount();
await encryptionService.registerDevice(userData._id);
navigateTo("/");
subscribeForNotifications();
dispatch(setSelectedConversation({}));
Expand Down
4 changes: 3 additions & 1 deletion src/components/auth/components/SignUpLinks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import OvalLoader from "@components/_helpers/OvalLoader";
import encryptionService from "@services/encryptionService";
import navigateTo from "@utils/navigation/navigate_to";
import showCustomAlert from "@utils/show_alert";
import subscribeForNotifications from "@services/notifications";
Expand All @@ -25,7 +26,8 @@ export default function SignUpLinks({ changePage, content }) {

if (isLogin) {
const userData = await usersService.login(content);

await encryptionService.clearStoredAccount();
await encryptionService.registerDevice(userData._id);
subscribeForNotifications();
dispatch(setSelectedConversation({}));
dispatch(setUserIsLoggedIn(true));
Expand Down
38 changes: 14 additions & 24 deletions src/components/hub/ChatForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import api from "@api/api";
import encryptionService from "@services/encryptionService";
import navigateTo from "@utils/navigation/navigate_to";
import removeAndNavigateLastSection from "@utils/navigation/get_prev_page";
import { selectCurrentUserId } from "@store/values/CurrentUserId";
import { getIsTabInFocus } from "@store/values/IsTabInFocus";
Expand All @@ -26,14 +25,11 @@ import "@styles/hub/ChatForm.css";
import ChatFormContent from "@components/hub/chatForm/ChatFormContent.js";
import ChatFormHeader from "@components/hub/chatForm/ChatFormHeader.js";
import ChatFormInputs from "@components/hub/chatForm/ChatFormInputs.js";
import LockScreen from "@components/hub/LockScreen";

export default function ChatForm() {
const dispatch = useDispatch();
const location = useLocation();

const isLockScreenPath = location.pathname.includes("/auth_encrypted");

const currentUserId = useSelector(selectCurrentUserId);
const conversations = useSelector(selectConversationsEntities);
const selectedConversation = useSelector(getConverastionById);
Expand Down Expand Up @@ -83,21 +79,14 @@ export default function ChatForm() {

useEffect(() => {
if (selectedConversation?.is_encrypted) {
if (!encryptionService.hasAccount() && !isLockScreenPath) {
dispatch(clearSelectedConversation());
navigateTo(`/auth_encrypted?convId=${selectedConversation._id}`);
return;
}

!isLockScreenPath &&
encryptionService
.createEncryptionSession(
selectedConversation.owner_id === currentUserId
? selectedConversation.opponent_id
: selectedConversation.owner_id
)
.then(({ session }) => setSuccessfulEncryptedSession(!!session))
.catch(() => setSuccessfulEncryptedSession(false));
encryptionService
.createEncryptionSession(
selectedConversation.owner_id === currentUserId
? selectedConversation.opponent_id
: selectedConversation.owner_id
)
.then(({ session }) => setSuccessfulEncryptedSession(!!session))
.catch(() => setSuccessfulEncryptedSession(false));
}

files.length && setFiles([]);
Expand All @@ -109,7 +98,7 @@ export default function ChatForm() {
document.removeEventListener("swiped-left", closeForm);
document.removeEventListener("swiped-right", closeForm);
};
}, [location, selectedCID]);
}, [location, selectedConversation?.is_encrypted]);

useEffect(() => {
const { hash } = location;
Expand All @@ -125,12 +114,13 @@ export default function ChatForm() {

return (
<section className={`chat-form__container ${selectedCID ? "" : "fcc"}`}>
{isLockScreenPath ? (
<LockScreen />
) : selectedCID ? (
{selectedCID ? (
<>
<ChatFormHeader closeFormFunc={closeForm} />
<ChatFormContent scrollRef={chatMessagesBlock} />
<ChatFormContent
scrollRef={chatMessagesBlock}
isEncryptedConversation={selectedConversation?.is_encrypted}
/>
<ChatFormInputs
chatMessagesBlockRef={chatMessagesBlock}
isEncryptedSessionActive={successfulEncryptedSession}
Expand Down
93 changes: 0 additions & 93 deletions src/components/hub/LockScreen.js

This file was deleted.

11 changes: 9 additions & 2 deletions src/components/hub/chatForm/ChatFormContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { selectActiveConversationMessages } from "@store/values/Messages";
import { useMemo } from "react";
import { useSelector } from "react-redux";

export default function ChatFormContent({ scrollRef }) {
export default function ChatFormContent({
scrollRef,
isEncryptedConversation,
}) {
const messages = useSelector(selectActiveConversationMessages);

const chatContentView = useMemo(() => {
Expand All @@ -27,7 +30,11 @@ export default function ChatFormContent({ scrollRef }) {

return (
<div className="chat-content__container">
<p className="chat-emty__text">Write the first message...</p>
<p className="chat-emty__text">
{isEncryptedConversation
? "Start an encrypted conversation by sending a message to the chat..."
: "Write the first message..."}
</p>
</div>
);
}, [messages, scrollRef]);
Expand Down
Loading