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

Fixing partial messages/long message ui #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 2 additions & 26 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,12 @@ def check_older_than(chat_dic, secs_to_live = 180):

if secs >= secs_to_live:
return True

return False


def get_random_color():

r = lambda: random.randint(0,128)
return (r(),r(),r())


def process_chat(chat_dic):

chats = []
max_chat_len = 69
if len(chat_dic["msg"]) > max_chat_len:

for message in textwrap.wrap(chat_dic["msg"], width = max_chat_len):
partial_chat = {}
partial_chat["msg"] = message.strip()
partial_chat["timestamp"] = datetime.datetime.now()
partial_chat["username"] = session["_id"]
partial_chat["color"] = session["color"]
chats.append(partial_chat)

else:
chats = [chat_dic]

return chats


# Remove headers that can be used to fingerprint this server
@app.after_request
def remove_headers(response):
Expand Down Expand Up @@ -199,7 +175,7 @@ def chat_messages(url_addition):
chat["timestamp"] = datetime.datetime.now()
chat["username"] = session["_id"]
chat["color"] = session["color"]
chats = process_chat(chat)
chats = [chat]
chatlines = chatlines + chats
chatlines = chatlines[-13:]
more_chats = True
Expand Down Expand Up @@ -243,7 +219,7 @@ def chat_messages_js(url_addition):
chat["username"] = session["_id"]
chat["color"] = session["color"]
chat["num_people"] = len(chatters)
chats = process_chat(chat)
chats = [chat]
chatlines = chatlines + chats
chatlines = chatlines[-13:]
more_chats = True
Expand Down
15 changes: 6 additions & 9 deletions templates/chats.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<html>
<head>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<meta http-equiv="refresh" content="1" >
<style>
*{
padding-top:3px;
font-family: Lucida Sans Typewriter,Lucida Console,monaco,Bitstream Vera Sans Mono,monospace;
font-size:22px;
}
</style>

<div style="float:right; font-size:10px;">People in chat: {{ num_people }}</div>
<div id="peopleinchat">People in chat: {{ num_people }}</div>
<table>
{% for message_dic in chatlines %}
<tr>
<td name="msg" class="msg" style="color:rgb{{ message_dic["color"] }};"><b>{{ message_dic["username"] }}</b>: {{ message_dic["msg"] }}</td>
<th scope="row" name="msg" class="msg name" style='color: rgb({{ message_dic["color"] }});'><b>{{ message_dic["username"] }}:</b></th>
<td name="msg" class="msg text" style='color: rgb({{ message_dic["color"] }});'><b>{{ message_dic["msg"] }}</b></td>
</tr>
{% endfor %}
</table>
Expand Down
15 changes: 6 additions & 9 deletions templates/chats_script.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<html>
<head>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<!--<meta http-equiv="refresh" content="1" >-->
<style>
*{
padding-top:3px;
font-family: Lucida Sans Typewriter,Lucida Console,monaco,Bitstream Vera Sans Mono,monospace;
font-size:22px;
}
</style>

<div style="float:right; font-size:10px;">People in chat: {{ num_people }}</div>
<div id="peopleinchat">People in chat: {{ num_people }}</div>
<table>
{% for message_dic in chatlines %}
<tr>
<td name="msg" class="msg" style="color:rgb{{ message_dic["color"] }};"><b>{{ message_dic["username"] }}</b>: {{ message_dic["msg"] }}</td>
<th scope="row" name="msg" class="msg name" style='color: rgb({{ message_dic["color"] }});'><b>{{ message_dic["username"] }}:</b></th>
<td name="msg" class="msg text" style='color: rgb({{ message_dic["color"] }});'><b>{{ message_dic["msg"] }}</b></td>
</tr>
{% endfor %}
</table>
Expand Down
12 changes: 2 additions & 10 deletions templates/drop.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@
<head>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<script src="{{ url_for('static', filename='jquery.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>

<noscript>
<style>html{display:none;}</style>
<meta http-equiv="refresh" content="0.0;url=noscript">
</noscript>

<style>
*{
padding-top:3px;
font-family: Lucida Sans Typewriter,Lucida Console,monaco,Bitstream Vera Sans Mono,monospace;
font-size:22px;
}

</style>

<script>
function doPoll() {
$( document ).ready(function() {
Expand All @@ -35,7 +27,7 @@
var color2 = JSON.stringify(obj.color[1]);
var color3 = JSON.stringify(obj.color[2]);
//alert(color1);
$("#chatf").append('<tr>' + '<td name="msg" class="msg" style="color:rgb(' + color1 + ',' + color2 + ',' + color3 + ');"><b>' + obj.username + ': ' + obj.msg + '</b></td>');
$("#chatf").append('<tr><th scope="row" name="msg" class="msg name" style="color:rgb(' + color1 + ',' + color2 + ',' + color3 + ');"><b>' + obj.username + ': </b></th><td name="msg" class="msg text" style="color:rgb(' + color1 + ',' + color2 + ',' + color3 + ');"><b>' + obj.msg + '</b></td></tr>');
$("#numpeeps").html(obj.num_people);
//alert(obj.num_people);
}
Expand Down
13 changes: 4 additions & 9 deletions templates/drop.noscript.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<!doctype html>
<title>Your Drop</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<style>
*{
padding-top:3px;
font-family: Lucida Sans Typewriter,Lucida Console,monaco,Bitstream Vera Sans Mono,monospace;
font-size:22px;
}
<head>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>


</style>

<div id="welcome">Welcome to drop {{ hostname }}<br />
Share the <a href="/{{ path }}">drop URL</a> with your friends to chat with them. Do not share it publicly.<br />
Expand Down
12 changes: 4 additions & 8 deletions templates/landing.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<!doctype html>
<title>Your Drop</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<style>
*{
padding-top:3px;
font-family: Lucida Sans Typewriter,Lucida Console,monaco,Bitstream Vera Sans Mono,monospace;
font-size:22px;
}
</style>
<head>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>

<noscript>
<style type="text/css">
Expand Down