feat: add dm channel sidebar with last message sorting and user context to template rendering
Add channel subscription loading in render_template to populate sidebar with private DM channels showing other user's nick, sort channels by last_message_on descending, and inject user object into template context for authenticated sessions.
This commit is contained in:
@@ -143,6 +143,31 @@ class Application(BaseApplication):
|
||||
|
||||
# @time_cache_async(60)
|
||||
async def render_template(self, template, request, context=None):
|
||||
channels = []
|
||||
if not context:
|
||||
context = {}
|
||||
if request.session.get("uid"):
|
||||
async for subscribed_channel in self.services.channel_member.find(user_uid=request.session.get("uid"), deleted_at=None, is_banned=False):
|
||||
item = {}
|
||||
other_user = await self.services.channel_member.get_other_dm_user(subscribed_channel["channel_uid"], request.session.get("uid"))
|
||||
parent_object = await subscribed_channel.get_channel()
|
||||
last_message =await parent_object.get_last_message()
|
||||
item["last_message_on"] = parent_object["last_message_on"]
|
||||
item["is_private"] = parent_object["tag"] == "dm"
|
||||
if other_user:
|
||||
item["name"] = other_user["nick"]
|
||||
item["uid"] = subscribed_channel["channel_uid"]
|
||||
else:
|
||||
item["name"] = subscribed_channel["label"]
|
||||
item["uid"] = subscribed_channel["channel_uid"]
|
||||
channels.append(item)
|
||||
|
||||
channels.sort(key=lambda x: x['last_message_on'] or '', reverse=True)
|
||||
if not 'channels' in context:
|
||||
context['channels'] = channels
|
||||
if not 'user' in context:
|
||||
context['user'] = await self.services.user.get(uid=request.session.get("uid"))
|
||||
|
||||
return await super().render_template(template, request, context)
|
||||
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@ class TerminalSocketView(BaseView):
|
||||
terminal_folder = pathlib.Path("terminal")
|
||||
for path in terminal_folder.iterdir():
|
||||
destination_path = root.joinpath(path.name)
|
||||
if not destination_path.exists():
|
||||
if not path.is_dir():
|
||||
destination_path.write_bytes(path.read_bytes())
|
||||
if not path.is_dir():
|
||||
destination_path.write_bytes(path.read_bytes())
|
||||
return root
|
||||
|
||||
async def get(self):
|
||||
|
||||
Reference in New Issue
Block a user