Private messaging actually works now

This commit is contained in:
SecretlyTaco 2018-03-23 03:50:33 +00:00
parent a09225a523
commit 2a2fb86b8b
3 changed files with 9 additions and 7 deletions

View file

@ -263,15 +263,17 @@ def messaging(user):
if request.method == "GET": if request.method == "GET":
return render_template( return render_template(
"messages.html", "messages.html",
messaging=accounts.get_display_name(user), logged_in=logged_in,
messaging=accounts.get_display_name(user.lower()),
messages=messages.get_messages(logged_in, user.lower()) messages=messages.get_messages(logged_in, user.lower())
) )
elif request.method == "POST": elif request.method == "POST":
messages.send_message( messages.send_message(
accounts.get_display_name(logged_in), accounts.get_display_name(logged_in.lower()),
accounts.get_display_name(user), accounts.get_display_name(user.lower()),
request.form['message_content'] request.form['message_content']
) )
return redirect(request.referrer)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -11,13 +11,13 @@ messages_db = db.messages
def send_message(msg_from, msg_to, msg_content): def send_message(msg_from, msg_to, msg_content):
if type(msg_from) == str: if type(msg_from) == str:
from_id = accounts.get_profile(msg_from)['_id'] from_id = accounts.account_details(msg_from.lower())['_id']
elif type(msg_from) == ObjectId: elif type(msg_from) == ObjectId:
from_id = msg_from from_id = msg_from
msg_from = accounts_db.find_one({'_id': from_id})['displayname'] msg_from = accounts_db.find_one({'_id': from_id})['displayname']
if type(msg_to) == str: if type(msg_to) == str:
to_id = accounts.get_profile(msg_to)['_id'] to_id = accounts.account_details(msg_to.lower())['_id']
elif type(msg_to) == ObjectId: elif type(msg_to) == ObjectId:
to_id = msg_to to_id = msg_to
msg_to = accounts_db.find_one({'_id': to_id})['displayname'] msg_to = accounts_db.find_one({'_id': to_id})['displayname']
@ -51,5 +51,5 @@ def get_messages(user1, user2):
"to" : user1_id "to" : user1_id
} }
]} ]}
).sort('timeSent', pymongo.DESCENDING) ).sort('timeSent', pymongo.ASCENDING)
return messages return messages

View file

@ -14,7 +14,7 @@
{% if messages %} {% if messages %}
{% for message in messages %} {% for message in messages %}
<div class="card mb-3" style="word-wrap: break-word; width: 100%;"> <div class="card mb-3" style="word-wrap: break-word; width: 100%;">
<div class="card-header"><b>{{ message.poster }}</b> at {{ message.timePosted.strftime('%Y-%m-%d %-H:%M') }}</div> <div class="card-header"><b>{{ message.fromName }}</b> at {{ message.timeSent.strftime('%Y-%m-%d %-H:%M') }}</div>
<div class="card-body"> <div class="card-body">
{{ message.content }} {{ message.content }}
</div> </div>