diasporadiaries

a platform for writing stories with personal accounts and messages
git clone git://parazyd.org/diasporadiaries.git
Log | Files | Refs | Submodules | README | LICENSE

commit bf634ca22fb5cdc964af23b14323acd8e4bcff0c
parent 2a4b2ba7f5b822b1556bb247a2b9ef2d9330722b
Author: parazyd <parazyd@dyne.org>
Date:   Wed, 23 Jan 2019 14:30:49 +0100

Implement read/unread messages.

Diffstat:
Mtemplates/index.html | 2+-
Mtemplates/messages.html | 8+++++++-
Mutils.py | 15++++++++++++---
3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/templates/index.html b/templates/index.html @@ -22,7 +22,7 @@ others of their kind. Make them feel less scared and lonely.</p> <p class="text-center"> - <a href="/write" class="btn btn-lg btn-primary">GO AND WRITE DOWN YOUR + <a href="/write" class="btn btn-lg btn-secondary">GO AND WRITE DOWN YOUR STORY!</a> </p> diff --git a/templates/messages.html b/templates/messages.html @@ -18,8 +18,9 @@ <table class="table table-striped table-hover"> <thead> <tr> - <th scope="col">From</th> + <th scope="col">With</th> <th scope="col">Latest</th> + <th scope="col">Status</th> <th scope="col">At</th> </tr> </thead> @@ -28,6 +29,11 @@ <tr> <td><a href="/messages?from={{ i[1] }}">{{ i[0] }}</a></td> <td><a href="/messages?from={{ i[1] }}">{{ i[2]['message'] }}</a></td> + {% if i[2]['unread'] == 1 %} + <td><span class="fa fa-envelope" style="font-size: 1.5em;" title="Unread"></span></td> + {% else %} + <td><span class="fa fa-envelope-open" style="font-size: 1.5em;" title="Read"></span></td> + {% endif %} <td>{{ i[2]['time'] }}</td> </tr> {% endfor %} diff --git a/utils.py b/utils.py @@ -311,10 +311,18 @@ def get_messages(user_id, id_from): json.dump(data, msgfile) return [] - messages = [] + marked = [] for i in data: - i['time'] = strftime('%d.%m.%Y. %H:%M UTC', gmtime(i['time'])) - messages.append(i) + i['unread'] = 0 + marked.append(i) + + with open(msgpath, 'w') as msgfile: + json.dump(marked, msgfile) + + messages = [] + for j in marked: + j['time'] = strftime('%d.%m.%Y. %H:%M UTC', gmtime(j['time'])) + messages.append(j) return messages @@ -339,6 +347,7 @@ def send_message(id_to, msg, id_us): 'from': ours['name'], 'message': Markup(msg).striptags(), 'time': int(time()), + 'unread': 1, } ourdata = []