Skip to content

Commit e07f4a0

Browse files
koray-erenJeff
authored andcommitted
add invite link/qr to nav
1 parent c1b7052 commit e07f4a0

File tree

5 files changed

+107
-14
lines changed

5 files changed

+107
-14
lines changed

sogs/routes/views.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from flask import abort, render_template, Response, Blueprint
22

3+
from ..utils import message_body, decode_base64, message_contents
34
from .. import config, crypto, http
45
from ..model.room import get_accessible_rooms
6+
from ..model.user import User
57
from .messages import message_single, messages_recent
68
from . import auth, converters # noqa: F401
9+
from .. import session_pb2 as protobuf
10+
import time
711

812

913
from io import BytesIO
@@ -30,29 +34,48 @@ def serve_index():
3034

3135
@views.get("/r/<Room:room>/")
3236
def view_room(room):
33-
messageId = 37
37+
messageId = 100
3438
response = ''
3539
print()
3640
try:
37-
response = message_single(room=room, msg_id=messageId)
38-
# response = messages_recent(room=room)
41+
# response = message_single(room=room, msg_id=messageId)
42+
response = messages_recent(room=room)
3943
print(' +++ NO ERROR +++ ')
44+
if response.status_code == 200:
45+
print(" === EXISTS === ")
46+
47+
request_data = response.json[0]['data']
48+
signature = response.json[0]['signature']
49+
request = response.json[0]
50+
epoch_time = request['posted']
51+
decoded_data = decode_base64(request_data)
52+
print('protobuf')
53+
print(request_data)
54+
# content = protobuf.Content()
55+
print(protobuf.Content().ParseFromString(decoded_data) )
56+
print()
57+
print('MSG BODY:')
58+
print(type(response.json[0]) )
59+
print(request )
60+
print(message_contents(decoded_data) )
61+
my_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(epoch_time))
62+
print(my_time)
63+
# print(msg )
64+
print()
65+
else:
66+
print(" !!! NO MESSAGE !!! ")
67+
print()
4068
except Exception as e:
4169
print("ERROR MSG: {}".format(e))
4270

43-
if response.status_code == 200:
44-
print(" === EXISTS === ")
45-
print(response.json )
46-
else:
47-
print(" !!! NO MESSAGE !!! ")
48-
print()
4971
if not room.default_read:
5072
abort(http.FORBIDDEN)
5173

5274
return render_template(
5375
"view_room.html",
5476
room=room,
5577
show_recent=config.HTTP_SHOW_RECENT,
78+
test='yeehaw'
5679
)
5780

5881

sogs/static/view_room.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ const setup = async () => {
5353
}
5454

5555
const plain = Message.decode(data).dataMessage;
56-
console.log(plain)
56+
console.log("VERIFY:")
57+
console.log(data)
58+
console.log(Message.decode(data))
59+
console.log(Message.decode(data).dataMessage)
60+
console.log(Message)
61+
console.log(Message.verify)
62+
console.log(Message.verify(data))
5763
// if msg is a reply
5864
if (plain.quote){
5965
originalMsg = document.createElement('p');
@@ -64,7 +70,7 @@ const setup = async () => {
6470
e.appendChild(originalMsg);
6571
}
6672
e.appendChild(document.createTextNode(plain.profile.displayName +": "+plain.body));
67-
e.classList.add('bg-gray-300','dark:bg-lightGray', 'w-fit', 'rounded', 'p-2', 'my-2')
73+
e.classList.add('bg-gray-300','dark:bg-lightGray', 'w-fit', 'rounded-lg', 'p-2', 'my-2')
6874
elem.appendChild(e);
6975

7076
}

sogs/templates/base.html

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<html id="html" class="">
22
<head>
3+
34
<title> sogs </title>
45
<meta name="viewport" content="width=device-width, initial-scale=1">
56
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}">
@@ -29,15 +30,25 @@
2930
</script>
3031
</head>
3132
<body class="dark:bg-otherGray transition duration-500">
33+
34+
{% block modal %}
35+
{% endblock %}
36+
3237
<!-- header / navbar -->
33-
<div class="px-5 flex justify-between items-center w-full h-32
38+
<div class="px-2 sm:px-5 flex justify-between items-center w-full max-h-32
3439
bg-sessionGreen dark:bg-otherGray border-b-8 border-black dark:border-sessionGreen transition duration-500">
3540
<div class="text-black dark:text-white text-center">
3641
<h1 class="text-3xl xs:text-4xl sm:text-5xl">{% block heading %}{% endblock %}</h1>
3742
<p class="text-lg xs:text-xl sm:text-2xl">Session Open Group Server</p>
3843
</div>
39-
<button id="moonIcon" class='px-1 rounded' onclick="toggleDarkMode()"><img src="{{ url_for('static', filename='moon-d-50-min.png') }}" alt="moon"></button>
40-
<button id="sunIcon" style="display: none;" class='px-1 rounded' onclick="toggleDarkMode()"><img src="{{ url_for('static', filename='sun-w-50-min.png') }}" alt="sun"></button>
44+
45+
<div class="flex space-x-4 ">
46+
{% block invite %}
47+
{% endblock %}
48+
<button id="moonIcon" class='px-1 rounded' onclick="toggleDarkMode()"><img src="{{ url_for('static', filename='moon-d-50-min.png') }}" alt="moon"></button>
49+
<button id="sunIcon" style="display: none;" class='px-1 rounded' onclick="toggleDarkMode()"><img src="{{ url_for('static', filename='sun-w-50-min.png') }}" alt="sun"></button>
50+
51+
</div>
4152
</div>
4253

4354
<!-- content/body -->
@@ -73,6 +84,16 @@ <h1 class="text-3xl xs:text-4xl sm:text-5xl">{% block heading %}{% endblock %}</
7384
setPageTheme();
7485
}
7586
}
87+
88+
modal = document.getElementById('modal');
89+
function handleOpenModalClick() {
90+
modal.style.display = 'block';
91+
}
92+
93+
function handleCloseModalClick() {
94+
console.log("CLICKED CLICKED CLICKED CLICKED CLICKED CLICKED CLICKED")
95+
modal.style.display = 'none';
96+
}
7697

7798
setPageTheme();
7899
</script>

sogs/templates/view_room.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,51 @@
11
{% extends "base.html" %}
22

3+
<script>
4+
modal = document.getElementById('modal');
5+
function handleOpenModalClick() {
6+
modal.style.display = 'block';
7+
}
8+
9+
function handleCloseModalClick() {
10+
modal.style.display = 'none';
11+
}
12+
</script>
13+
14+
{% block modal %}
15+
<div id="modal" class="bg-green dark:bg-transparent w-screen h-screen">
16+
<div style="display: none;" class="flex flex-col justify-center absolute bg-lightGray rounded-lg w-5/6 max-w-2xl aspect-square left-1/2 translate-x-[-50%] top-1/2 translate-y-[-50%]">
17+
<div class="flex w-full justify-between ">
18+
<pre class="dark:text-white break-all whitespace-normal m-2">{{room.url}}</pre>
19+
<button onclick="handleCloseModalClick()" class="text-white bold text-center rounded px-1 m-2 "> X</button>
20+
</div>
21+
<img class="aspect-square p-2" src="invite.png" />
22+
</div>
23+
</div>
24+
25+
26+
{% endblock %}
27+
328
{% block heading %}
429
{{room.token}}
530
{% endblock %}
631

32+
{% block invite %}
33+
<div class=" h-28 flex flex-col justify-center ">
34+
<button onclick="handleOpenModalClick()" class="dark:text-white text-center text-xs sm:text-base">
35+
<img class="h-16 sm:h-20 sm:pt-2 aspect-square" src="invite.png" />
36+
Invite Link
37+
</button>
38+
</div>
39+
40+
{% endblock %}
41+
42+
743
{% block body %}
844
<div class="flex justify-center align-center space-x-3">
945
<div class="w-2/3 md:w-5/6">
1046
<button class="bg-black text-white dark:bg-sessionGreen dark:text-black rounded px-1 py-1 my-2" > <a href="/">< Back</a></button>
1147
<pre class="text-sm break-all whitespace-normal">{{room.url}}</pre>
48+
<pre class="text-sm break-all whitespace-normal">{{test}}</pre>
1249
</div>
1350
<div class="w-1/3 lg:w-auto ">
1451
<img class="aspect-square max-w-full max-h-40 " src="invite.png" />

sogs/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def message_body(data: bytes):
1515
msg.ParseFromString(remove_session_message_padding(data))
1616
return msg.dataMessage.body
1717

18+
def message_contents(data: bytes):
19+
"""given a bunch of bytes for a protobuf message return the entire message contents"""
20+
msg = protobuf.Content()
21+
msg.ParseFromString(remove_session_message_padding(data))
22+
return msg
23+
1824

1925
def encode_base64(data: bytes):
2026
return base64.b64encode(data).decode()

0 commit comments

Comments
 (0)