diff --git a/src/snek/templates/threads.html b/src/snek/templates/threads.html new file mode 100644 index 0000000..2d7d01b --- /dev/null +++ b/src/snek/templates/threads.html @@ -0,0 +1,153 @@ +{% extends "app.html" %} + +{% block main %} +
+
+

?

+
+
+ {% for thread in threads %} + {% autoescape false %} +
+
+
+
{{thread.last_message_user_nick}}
+
{% autoescape false %}{% emoji %}{% linkify %}{% markdown %}{% autoescape false %}{{ thread.last_message_text }}{%raw %} {% endraw%}{%endautoescape%}{% endmarkdown %}{% endlinkify %}{% endemoji %}{% + endautoescape %}
+
+
+
+ + {% endautoescape %} + {% endfor %} +
+ +
+ + +{% endblock %} diff --git a/src/snek/view/threads.py b/src/snek/view/threads.py new file mode 100644 index 0000000..d8f4359 --- /dev/null +++ b/src/snek/view/threads.py @@ -0,0 +1,31 @@ +from snek.system.view import BaseView + +class ThreadsView(BaseView): + + async def get(self): + threads = [] + user = await self.services.user.get(uid=self.session.get("uid")) + async for channel_member in user.get_channel_members(): + thread = {} + channel = await self.services.channel.get(uid=channel_member["channel_uid"]) + thread["uid"] = channel['uid'] + thread["name"] = await channel_member.get_name() + thread["new_count"] = channel_member["new_count"] + thread["last_message_on"] = channel["last_message_on"] + thread['created_at'] = thread['last_message_on'] + last_message = await channel.get_last_message() + if last_message: + thread["last_message_text"] = last_message["message"] + thread['last_message_user_uid'] = last_message["user_uid"] + user_last_message = await self.app.services.user.get(uid=last_message["user_uid"]) + thread['last_message_user_nick'] = user_last_message["nick"] + thread['last_message_user_color'] = user_last_message['color'] + else: + thread["last_message_text"] = None + thread['last_message_user_uid'] = None + thread['last_message_user_nick'] = None + thread['last_message_user_color'] = None + threads.append(thread) + + + return await self.render_template("threads.html", dict(threads=threads,user=user))