Skip to content

Commit

Permalink
messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
cc-d committed Oct 21, 2019
1 parent 3b45ebe commit d781b3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
11 changes: 8 additions & 3 deletions ieddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,8 +1422,10 @@ def reply_message(username=None, mid=None):
return render_template('message_reply.html', message=m, sendto=False, self_pgp=get_pgp_from_username(session['username']),
other_pgp=get_pgp_from_username(m.sender), other_user=get_user_from_name(username))

def sendmsg(title=None, text=None, sender=None, sent_to=None, encrypted=False, encrypted_key_id=None):
new_message = Message(title=title, text=text, sender=sender, sent_to=sent_to, encrypted=encrypted, encrypted_key_id=encrypted_key_id)

def sendmsg(title=None, text=None, sender=None, sent_to=None, encrypted=False, encrypted_key_id=None, in_reply_to=None):
new_message = Message(title=title, text=text, sender=sender, in_reply_to=in_reply_to, sent_to=sent_to, encrypted=encrypted,
encrypted_key_id=encrypted_key_id)
db.session.add(new_message)
db.session.commit()

Expand All @@ -1441,13 +1443,16 @@ def msg(username=None):
encrypted = request.form.get('msgencrypted')
encrypted_key_id = request.form.get('key_id')

if encrypted != None:
if encrypted == 'true':
encrypted = True
encrypted_key_id = encrypted_key_id
else:
encrypted = False
encrypted_key_id = None

if encrypted_key_id == '':
encrypted_key_id = None

if sent_to == None:
sent_to = username

Expand Down
2 changes: 2 additions & 0 deletions static/pgp.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ const encryptMessage = async(ask=false) => {
$('#message-textarea').val(encrypted);
$('#encryptMessageButton').replaceWith($('<button type="button" class="btn btn-sm btn-success" ' +
'id="encryptMessageButton" disabled><i class="fa fa-lock"></i> message encrypted</button>'));
$('#msgencrypted').val('true');
});

}catch (e) {
if (ask === false) {
console.log('invalid passphrase');
Expand Down
27 changes: 12 additions & 15 deletions templates/messages.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
<h2 class='margin-lr'> unread messages </h2>
{% for message in unread %}

{% if has_encrypted %}
{% if message.encrypted == True and message.encrypted_key_id == self_pgp.id %}
{% include 'message.html' %}
{% elif message.encrypted == True %}
<p style='color: red;'>you have encrypted messages but cannot read them</p>
{% endif %}
{{ message.encrypted_key_id }}{{ self_pgp.id }}
{% if message.encrypted == True and message.encrypted_key_id == self_pgp.id|string %}
{% include 'message.html' %}
{% elif message.encrypted == True and message.encrypted_key_id|string != self_pgp.id|string and message.encrypted_key_id|string != 'None' %}
<div class='margin-lr'><p style='color: red;'>you have a encrypted messages but (probably) cannot read it. Sent to: {{ message.encrypted_key_id }} - You are: {{ self_pgp.id }}</p></div>
{% else %}
{% include 'message.html' %}
{% endif %}
Expand All @@ -46,23 +45,21 @@ <h2 class='margin-lr'> unread messages </h2>
<h2 class='margin-lr'> read messages </h2>
{% for message in read %}
{% include 'message.html' %}

{% if has_encrypted %}
{% if message.encrypted == True and message.encrypted_key_id == self_pgp.id %}
{% include 'message.html' %}
{% elif message.encrypted == True %}
<div class='missing-message margin-lr' style='border: 1px dashed red; margin: 0.5rem;'>
<p class='margin-lr' style='color: red;'>a message was encrypted with a old/different pgp key. it has been hidden</p>
</div>
{% endif %}
{% if message.encrypted == True and message.encrypted_key_id|string == self_pgp.id|string %}
{% include 'message.html' %}
{% elif message.encrypted == True and message.encrypted_key_id|string != self_pgp.id|string and message.encrypted_key_id|string != 'None' %}
<div class='margin-lr'><p style='color: red;'>you have a encrypted messages but (probably) cannot read it. Sent to: {{ message.encrypted_key_id }} - You are: {{ self_pgp.id }}</p></div>
{% else %}
{% include 'message.html' %}
{% endif %}

{% else %}
<p class='margin-lr'> no unread messages</p><br><br>
{% endfor %}
{% endif %}



{% if sent != [] %}
<h2 class='margin-lr'> sent messages </h2>
{% for message in sent %}
Expand Down

0 comments on commit d781b3f

Please sign in to comment.