built to satisfy the requirements for project 2: in CS50 Web Programming with Python and JavaScript , programming course by Harvard University.
Chit-Chat is online messaging service built with flask and javascript.
the project folder contain this files and folders:
static
/index.js
templates
/index.html
uploads
/application.py
/REAME.md
/requirements.txt
- Flask-Session: Flask-Session is an extension for Flask that adds support for Server-side Session to web applications.
-
display name should remembered: i used Server-side Session to store the username in the server filesystem
- user log in for first time
- server look for previously stored username , if the username not in user server-side session, authintcation request sent to th client.
- client ask the user for a display name, then send it to the server.
- server recieve the display name and store it in the user server-side session (filesystem) to be remembered when user comeback any time.
-
channel creation and channel list:
- when user joined for first time he loged in to a default channel, called General Talk,
- when user create new channel the client send event to the server with the room name
- the server check for name availability, then add the channel room to a list
- then server will send un event to clients with a complete list of channels to refresh the new changes, log in the user his new room.
- clients refresh the available channels.
-
message view and store 100 most recent messages per channel in server-side memory: for this requirement, i chooses to use a dictionary, where keys are channels name, and values are lists(deque*) of dictionarys ( every dictionary represent a message and contain body, sender, and file url if the message are uploaded file).
deque is list-like container with fast appends and pops on either end. it allow to pop items from left so we keep most recent messages.
read here for more info about deque
- when user log in and join the default room , or last visited room, he receive a list of messages(dictionares) and display it to user.
- when user send a message, the server store it in memory in the data-container mentioned before. if the count reach 100 we pop left a message before we store the new message.
-
sending message associated with the sender display name and the timestamp:
- the client will send the message alongside sender name and timestamp derived from Unix time, which is a value consisting of the number of milliseconds that have passed since midnight on January 1st, 1970.
- the server will pass it to other clients.
- clients will receive the message object, and Retrieving message and sender info and convert the timestamp associated with the message to local time and string format for display to users.
-
remembering the channel the user was on previously: the last channel user was on are stored in the user session on server-side's file-system.
-
the personal touch:
- user can send txt, pdf, png, jpg, jpeg, gif files to others
- there is a status animated icon, light green when connected or yellow when there are connections issues.
- also online users counter. display to user when he loged in.