aboutsummaryrefslogtreecommitdiff
path: root/cli/onionshare_cli/web/chat_mode.py
diff options
context:
space:
mode:
authorSaptak S <saptak013@gmail.com>2020-11-10 20:01:11 +0530
committerSaptak S <saptak013@gmail.com>2020-11-10 20:01:11 +0530
commitd1cada0f7e88a58ae0be82b66cdd8d5da1219bb5 (patch)
tree80a22e8aa45ef16fefbfb752c87f4ba51af7add2 /cli/onionshare_cli/web/chat_mode.py
parent7ab10a0a57cf9d60b0115e7b3399fad09ee072c3 (diff)
downloadonionshare-d1cada0f7e88a58ae0be82b66cdd8d5da1219bb5.tar.gz
onionshare-d1cada0f7e88a58ae0be82b66cdd8d5da1219bb5.zip
Improves the logic of updating both flask session and socket session with new nickname
Diffstat (limited to 'cli/onionshare_cli/web/chat_mode.py')
-rw-r--r--cli/onionshare_cli/web/chat_mode.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/cli/onionshare_cli/web/chat_mode.py b/cli/onionshare_cli/web/chat_mode.py
index 15e236d3..03843ee8 100644
--- a/cli/onionshare_cli/web/chat_mode.py
+++ b/cli/onionshare_cli/web/chat_mode.py
@@ -66,7 +66,8 @@ class ChatModeWeb:
)
session["room"] = self.web.settings.default_settings["chat"]["room"]
self.web.add_request(
- request.path, {"id": history_id, "status_code": 200},
+ request.path,
+ {"id": history_id, "status_code": 200},
)
self.web.add_request(self.web.REQUEST_LOAD, request.path)
@@ -83,14 +84,23 @@ class ChatModeWeb:
def update_session_username():
history_id = self.cur_history_id
data = request.get_json()
- if data.get("username", "") not in self.connected_users:
+ if (
+ data.get("username", "")
+ and data.get("username", "") not in self.connected_users
+ ):
session["name"] = data.get("username", session.get("name"))
self.web.add_request(
- request.path, {"id": history_id, "status_code": 200},
+ request.path,
+ {"id": history_id, "status_code": 200},
)
self.web.add_request(self.web.REQUEST_LOAD, request.path)
- r = make_response(jsonify(username=session.get("name"), success=True,))
+ r = make_response(
+ jsonify(
+ username=session.get("name"),
+ success=True,
+ )
+ )
return self.web.add_security_headers(r)
@self.web.socketio.on("joined", namespace="/chat")
@@ -125,7 +135,7 @@ class ChatModeWeb:
"""Sent by a client when the user updates their username.
The message is sent to all people in the room."""
current_name = session.get("name")
- if message["username"] not in self.connected_users:
+ if message.get("username", ""):
session["name"] = message["username"]
self.connected_users[
self.connected_users.index(current_name)