diff --git a/src/main.rs b/src/main.rs index 9c2a2ec..5282c3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1374,9 +1374,11 @@ async fn handle_websocket(socket: WebSocket, state: Arc) { } let users = recv_state.users.read().await; - if let Some(recipient_tx) = users.get(&chat_msg.to_user) { - let message_json = serde_json::to_string(&chat_msg).unwrap(); - let _ = recipient_tx.send(Message::Text(message_json)); + if chat_msg.to_user != chat_msg.from_user { + if let Some(recipient_tx) = users.get(&chat_msg.to_user) { + let message_json = serde_json::to_string(&chat_msg).unwrap(); + let _ = recipient_tx.send(Message::Text(message_json)); + } } if let Some(sender_tx) = users.get(&username) { diff --git a/web/index.html b/web/index.html index 7dcd861..a2b70c7 100644 --- a/web/index.html +++ b/web/index.html @@ -1,1787 +1,1994 @@ - + - - - - Secure Chat App - - - - - - -
-
-
Login
-
Register
-
- - - - -
-
- - -
-
- - -
- -
- - -
-
- - -
-
- - -
-
- - -
- -
-
+ /* Very small screens */ + @media (max-width: 320px) { + .chat-avatar { + width: 40px; + height: 40px; + font-size: 16px; + margin-right: 8px; + } - -
- -
- -
Secure Chat
- +
+ Register +
+
+ + + + +
+
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
- -
- -
-
-

Chats

- +
Secure Chat
+ +
+ +
+ +
+
+

Chats

+ +
+ +
+
+ My Chats
+
+ New Chat +
+
+ + +
+ +
+
+ + +
    + +
+
+ + +
+
+
+ +
+ +
+
+
+ Select a chat +
+
+ Choose someone to message +
+
+
+ +
+ +
+
+
+

Welcome to Secure Chat

+

Select a chat to start messaging

+
+
+
+ +
+
+ + +
+
+
+
+
+ + + + + + -
- - + - - \ No newline at end of file + + // Event listeners + document + .getElementById("messageInput") + .addEventListener("keydown", function (e) { + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + sendMessage(); + } + }); + + document + .getElementById("loginPassword") + .addEventListener("keypress", function (e) { + if (e.key === "Enter") login(); + }); + + document + .getElementById("registerPassword") + .addEventListener("keypress", function (e) { + if (e.key === "Enter") register(); + }); + + // Avatar upload handler + document + .getElementById("avatarInput") + .addEventListener("change", function (e) { + const file = e.target.files[0]; + if (file) { + // Validate file type + if (!file.type.startsWith("image/")) { + showAlert("Please select an image file", "error"); + return; + } + + // Validate file size (5MB) + if (file.size > 5 * 1024 * 1024) { + showAlert("Image must be less than 5MB", "error"); + return; + } + + uploadAvatar(file); + e.target.value = ""; // Reset input + } + }); + + // Close modals when clicking outside + document + .getElementById("profileModal") + .addEventListener("click", function (e) { + if (e.target === this) { + closeProfileModal(); + } + }); + + document + .getElementById("deleteModal") + .addEventListener("click", function (e) { + if (e.target === this) { + closeDeleteModal(); + } + }); + + // Close chats panel when clicking on overlay (mobile) + document + .getElementById("chatsPanel") + .addEventListener("click", function (e) { + if (e.target === this && isMobile) { + hideChatsPanel(); + } + }); + + document.getElementById("loginPhone").focus(); + + +