Commit b291d573 authored by Philipp Hörist's avatar Philipp Hörist

Groupchat: Display groupchat names in banner

Name is determined in the following way:

1. Bookmark name
2. Disco info muc#roomconfig_roomname value
3. localpart of the JID
parent 89d1e307
......@@ -173,12 +173,28 @@ class Contact(CommonContact):
return self.jid
def get_shown_name(self):
if self._is_groupchat:
return self._get_groupchat_name()
if self.name:
return self.name
if self.contact_name:
return self.contact_name
return self.jid.split('@')[0]
def _get_groupchat_name(self):
from gajim.common import app
con = app.connections[self.account.name]
name = con.get_module('Bookmarks').get_name_from_bookmark(self.jid)
if name:
return name
cache = caps_cache.muc_caps_cache.cache
if self.jid in cache:
name = cache[self.jid].muc_room_name
if name:
return name
return self.jid.split('@')[0]
def get_shown_groups(self):
if self.is_observer():
return [_('Observers')]
......
......@@ -246,11 +246,10 @@ class Bookmarks(BaseModule):
self.store_bookmarks()
def get_name_from_bookmark(self, jid: str) -> str:
fallback = jid.split('@')[0]
bookmark = self.get_bookmark_from_jid(jid)
if bookmark is None:
return fallback
return bookmark.name or fallback
return
return bookmark.name
def is_bookmark(self, jid: str) -> bool:
return self.get_bookmark_from_jid(jid) is not None
......
......@@ -110,7 +110,6 @@ class GroupchatControl(ChatControlBase):
def __init__(self, parent_win, contact, muc_data, acct, is_continued=False):
ChatControlBase.__init__(self, self.TYPE_ID, parent_win,
'groupchat_control', contact, acct)
self.force_non_minimizable = False
self.is_continued = is_continued
self.is_anonymous = True
......@@ -170,11 +169,6 @@ class GroupchatControl(ChatControlBase):
self.room_jid = self.contact.jid
self._muc_data = muc_data
bm_module = app.connections[self.account].get_module('Bookmarks')
self.name = bm_module.get_name_from_bookmark(self.room_jid)
self.contact.name = self.name
self.widget_set_visible(self.xml.get_object('banner_eventbox'),
app.config.get('hide_groupchat_banner'))
......@@ -370,6 +364,10 @@ class GroupchatControl(ChatControlBase):
return ''
return self._subject_data.subject
@property
def room_name(self):
return self.contact.get_shown_name()
def add_actions(self):
super().add_actions()
actions = [
......@@ -998,7 +996,7 @@ class GroupchatControl(ChatControlBase):
# if this is a continued conversation
label_str = self.get_continued_conversation_name()
else:
label_str = self.name
label_str = self.room_name
label_str = GLib.markup_escape_text(label_str)
# count waiting highlighted messages
......@@ -1106,12 +1104,7 @@ class GroupchatControl(ChatControlBase):
room jid
"""
self.name_label.set_ellipsize(Pango.EllipsizeMode.END)
if self.is_continued:
name = self.get_continued_conversation_name()
else:
name = self.room_jid
self.name_label.set_text(name)
self.name_label.set_text(self.room_name)
def _nec_update_avatar(self, obj):
if obj.contact.room_jid != self.room_jid:
......@@ -2221,7 +2214,7 @@ class GroupchatControl(ChatControlBase):
_('Leave Group Chat'),
_('Are you sure you want to leave this group chat?'),
_('If you close this window, you will leave '
'\'%s\'.') % self.name,
'\'%s\'.') % self.room_name,
_('_Do not ask me again'),
[DialogButton.make('Cancel',
callback=on_cancel),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment