Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
31c4faa
Baseline
ah0yt Mar 6, 2019
88ba53f
Updating baseline - created skeleton website and tweaked the layout
ah0yt Mar 15, 2019
19cb8b7
Updating baseline again - working through issues, javascript and html…
ah0yt Mar 21, 2019
faea99e
Rebaselining to capture progress and work arounds
ah0yt Mar 22, 2019
9be05ee
Basic messaging now works
ah0yt Mar 22, 2019
88e73ff
Saving snapshot before making substantial changes
ah0yt Mar 22, 2019
38f1f00
fixed messaging and loadUsername() issues
ah0yt Mar 23, 2019
a4cb7cf
Changes to channel selection
ah0yt Mar 23, 2019
7ccd19e
tracking channel state and restoring if user rejoins
ah0yt Mar 23, 2019
e79f893
more updates on channel state handling
ah0yt Mar 23, 2019
0e7b0e3
Added personal touch bage that tracks number of user messages posted
ah0yt Mar 24, 2019
37dc6c5
Channel selection properly changes messages - reworked datetime calcu…
ah0yt Mar 24, 2019
635ca41
More fixes - behavior ok on Chrome, but spurious on Firefox and Safar…
ah0yt Mar 25, 2019
75ab8a8
More updates and fixes from testing with Chrome and Firefox
ah0yt Mar 25, 2019
f663bba
Updated README.md
ah0yt Mar 25, 2019
ef2448d
Update README.md
ah0yt Mar 25, 2019
92712b2
Update README.md
ah0yt Mar 25, 2019
e390d06
Update README.md
ah0yt Mar 25, 2019
8fe81dc
Update README.md
ah0yt Mar 25, 2019
a49f5dd
Update README.md
ah0yt Mar 25, 2019
8be0615
Update README.md
ah0yt Mar 25, 2019
716a311
Update README.md
ah0yt Mar 25, 2019
7f3ea66
Update README.md
ah0yt Mar 25, 2019
77a4cc2
Update README.md
ah0yt Mar 25, 2019
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
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# Project 2
# Project 2 README.md file

Web Programming with Python and JavaScript
### Flack Overview:
Flack is a simple messaging application that allows users to register with a display name, create / join channels (chat rooms) and post messages. To post a message, a user simply selects (or creates) a channel and enters text in the message box located at the bottom of the screen. Pressing the "Post" button, adds the message to the active lists and updates anyone else in the channel

##Personal Touch:
The personal touch includes the addition of messages badges in the user list that tracks and displays the number of messages posted by each user

## Notes:

1) The application uses pop-ups to prompt the user for their display name and channel - the browser MUST allow pop-ups for proper functionality of the application. Here is what the prompt looks like:

<img src="https://user-images.githubusercontent.com/32006324/54920669-2c9f8680-4eda-11e9-9885-10319313668f.jpg" width="500">

2) To add channels select the plus (+) icon next to "Channels" - the "General" channel is provided by default just like Slack

3) New users joining the app are displayed in the left side Users column

<img src="https://user-images.githubusercontent.com/32006324/54931780-0e448580-4ef0-11e9-8f96-62d5c01810b4.jpg" width="900">

4) The application has been tested mostly on Chrome and some on Firefox.

## Key files and resources:
1) application.py - primary flack application that serves the index.html file, tracks channels / messages and manages user websocket connections.

2) index.js - client side javascript file which is the core of this application. Handles client interactions with the server via websockets

3) index.html - the single page application screen base on boostrap

4) static resources - this includes the index.html file (mentioned above), three graphic files (addGraphic.png,
favicon.ico, and flackUser.png) and the style.css which is mostly used to to properly configure messages

5) requirements.txt - a list of dependent python modules necessary for running the server

6) README.md - this file




106 changes: 103 additions & 3 deletions application.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,113 @@
import os

from flask import Flask
import datetime
from flask import Flask, render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)

# Configure to use filesystem session type
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY")
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"

socketio = SocketIO(app)
app.secret_key = os.urandom(32)

# Global lists and dicts
channels = {}
message = {}
messages = []
users = {}

MESSAGELIMIT = 100

@app.route("/")
@app.route("/index")
def index():
return "Project 2: TODO"
return render_template("index.html")

# set up a user who is connecting to the server
@socketio.on('user connect')
def connect(data):
global channels
messages = []

# check if channels empty - first time through
if not channels:
# get server date / time
current = datetime.datetime.now()

displayHeader = " | "+str(current.hour)+":"+str(current.minute)+" | "+str(current.month)+" "+str(current.day)+", "+str(current.year)

# always provide a general channel just like slack
messages.insert(0, {'username': "System",
'channel': "General",
'datetime': displayHeader,
'message': "Welcome to Flack!"})

channels['General'] = messages
emit("select channel", channels, broadcast=False)
else:
# already have some channels so communicate
updatedChannels = []

# extract updated list of channels
for key in channels.keys():
updatedChannels.append(key)

# emit current channel list
emit("update channels", {'channel': updatedChannels}, broadcast=True)

# check if user already connected
if (data["username"] not in users.values()):

# if users{} empty - first time through
if not users:
users.update({0: data["username"]})
else:
# determine next dict key and increment to add new user
dictKeys = list(users.keys())
nextKey = max(dictKeys)+1
users.update({nextKey: data["username"]})

# let everyone know a user has joined
print(users)
emit("add user", users, broadcast=True)


@socketio.on('get channel')
def getChannel(data):
global channels
updatedChannels = []

# emit current channel list
emit("select channel", channels, broadcast=False)

@socketio.on('new channel')
def addChannel(data):
global channels
updatedChannels = []

# add the new channel to the server channel list
channels.update({data['channel']: []})

# extract updated list of channels
for key in channels.keys():
updatedChannels.append(key)

# let everyone know a new channel is available
emit("update channels", {'channel': updatedChannels}, broadcast=True)

@socketio.on('post message')
def addMessage(data):
global channels

# add the message, but keep lists (message queue) to 100
if len(channels[data['channel']]) > MESSAGELIMIT:
channels.setdefault(data['channel'], []).append(data)
channels.setdefault(data['channel'], []).pop(0)
else:
channels.setdefault(data['channel'], []).append(data)

# notify everyone of new message
emit("add message", data, broadcast=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Flask
Flask-SocketIO
datetime
Binary file added static/FlackUser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading