This commit is contained in:
retoor 2025-03-08 08:25:49 +01:00
parent 1b72063a5b
commit 5a72c8cd83
6 changed files with 35 additions and 23 deletions

View File

@ -22,11 +22,11 @@ class ChannelMemberModel(BaseModel):
return await self.app.services.channel.get(uid=self['channel_uid'])
async def get_name(self):
if self["channel_uid"] == "dm":
channel = await self.get_channel()
if channel["tag"] == "dm":
user = await self.get_other_dm_user()
return user['nick']
channel = await self.get_channel()
return channel['name']
return channel['name'] or self['label']
async def get_other_dm_user(self):
channel = await self.get_channel()
@ -37,4 +37,4 @@ class ChannelMemberModel(BaseModel):
if model["uid"] != self['uid']:
return await self.app.services.user.get(uid=model["user_uid"])
return await self.get_user()

View File

@ -36,7 +36,11 @@ class ChannelMemberService(BaseService):
async def get_dm(self,from_user, to_user):
async for model in self.query("SELECT channel_member.* FROM channel_member INNER JOIN channel ON (channel.uid = channel_member.channel_uid and channel.tag = 'dm') INNER JOIN channel_member AS channel_member2 ON(channel_member2.channel_uid = channel.uid AND channel_member2.user_uid = :to_user) WHERE channel_member.user_uid=:from_user " ,dict(from_user=from_user, to_user=to_user)):
return model
return None
if not from_user == to_user:
return None
async for model in self.query("SELECT channel_member.* FROM channel_member INNER JOIN channel ON (channel.uid = channel_member.channel_uid and channel.tag = 'dm') LEFT JOIN channel_member AS channel_member2 ON(channel_member2.channel_uid = NULL AND channel_member2.user_uid = NULL) WHERE channel_member.user_uid=:from_user " ,dict(from_user=from_user, to_user=to_user)):
return model
async def get_other_dm_user(self, channel_uid, user_uid):
channel_member = await self.get(channel_uid=channel_uid, user_uid=user_uid)

View File

@ -5,18 +5,18 @@
<div class="threads">
{% for thread in threads %}
{% autoescape false %}
<div style="max-width:100%;" data-uid="{{thread.uid}}" data-color="{{thread.last_message_user_color}}" data-channel_uid="{{thread.uid}}"
data-user_nick="{{last_message_user_nick}}" data-created_at="{{thread.created_at}}" data-user_uid="{{user_uid}}"
<a href="/channel/{{thread.uid}}.html" style="max-width:100%;" data-uid="{{thread.uid}}" data-color="{{thread.last_message_user_color}}" data-channel_uid="{{thread.uid}}"
data-name="{{thread.name}}" data-created_at="{{thread.created_at}}" data-user_uid="{{thread.user_uid}}"
class="thread">
<div class="avatar" style="opacity: 1; background-color: {{thread.last_message_user_color}}; color: black;"><img
src="/avatar/{{thread.last_message_user_uid}}.svg" /></div>
<div class="message-content">
<div class="author" style="opacity: 1; color: {{thread.last_message_user_color}};">{{thread.last_message_user_nick}}</div>
<div class="author" style="opacity: 1; color: {{thread.name_color}};">{{thread.name}}</div>
<div class="text">{% autoescape false %}{% emoji %}{% linkify %}{% markdown %}{% autoescape false %}{{ thread.last_message_text }}{%raw %} {% endraw%}{%endautoescape%}{% endmarkdown %}{% endlinkify %}{% endemoji %}{%
endautoescape %}</div>
<div class="time opacity: 1; no-select" data-created_at="{{thread.created_at}}"></div>
</div>
</div>
</a>
{% endautoescape %}
{% endfor %}

View File

@ -3,7 +3,7 @@
{% block main %}
<section class="chat-area" id="chat">
<div class="chat-header">
<h2>{{ channel.label.value }}</h2>
<h2>{{ name }}</h2>
</div>
<div class="chat-messages">
{% for message in messages %}

View File

@ -8,23 +8,24 @@ class ThreadsView(BaseView):
async for channel_member in user.get_channel_members():
thread = {}
channel = await self.services.channel.get(uid=channel_member["channel_uid"])
last_message = await channel.get_last_message()
if not last_message:
continue
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
thread['name_color'] = "#f05a28"
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"])
if channel['tag'] == "dm":
thread['name_color'] = user_last_message['color']
thread['last_message_user_color'] = user_last_message['color']
threads.append(thread)

View File

@ -42,6 +42,11 @@ class WebView(BaseView):
return web.HTTPFound("/channel/{}.html".format(channel["uid"]))
if not channel:
return web.HTTPNotFound()
channel_member = await self.app.services.channel_member.get(user_uid=self.session.get("uid"), channel_uid=channel["uid"])
if not channel_member:
return web.HTTPNotFound()
user = await self.services.user.get(uid=self.session.get("uid"))
messages = [await self.app.services.channel_message.to_extended_dict(message) for message in await self.app.services.channel_message.offset(
channel["uid"]
@ -60,4 +65,6 @@ class WebView(BaseView):
item["name"] = subscribed_channel["label"]
item["uid"] = subscribed_channel["channel_uid"]
channels.append(item)
return await self.render_template("web.html", {"channel": channel,"user": user,"messages": messages , "channels": channels})
name = await channel_member.get_name()
return await self.render_template("web.html", {"name": name, "channel": channel,"user": user,"messages": messages , "channels": channels})