Philipp Hörist pushed to branch master at gajim / gajim


Commits:
c0f61266 by Nicoco at 2024-06-29T06:48:03+00:00
feat: Make HTTP links clickable in room descriptions

- - - - -


3 changed files:

- gajim/gtk/chat_banner.py
- gajim/gtk/groupchat_info.py
- gajim/gtk/util.py


Changes:

=====================================
gajim/gtk/chat_banner.py
=====================================
@@ -37,6 +37,7 @@
 from gajim.gtk.menus import get_singlechat_menu
 from gajim.gtk.tooltips import ContactTooltip
 from gajim.gtk.util import AccountBadge
+from gajim.gtk.util import make_href_markup
 
 
 class ChatBanner(Gtk.Box, EventHelper):
@@ -304,7 +305,7 @@ def _update_name_label(self) -> None:
 
         self._ui.name_label.set_tooltip_text(tooltip_text)
 
-    def _get_muc_description_text(self) -> str:
+    def _get_muc_description_text(self) -> str | None:
         contact = self._contact
         assert isinstance(contact, GroupchatContact)
 
@@ -312,8 +313,8 @@ def _get_muc_description_text(self) -> str:
         if not typing or not app.settings.get('show_chatstate_in_banner'):
             disco_info = app.storage.cache.get_last_disco_info(contact.jid)
             if disco_info is None:
-                return ''
-            return disco_info.muc_description or ''
+                return None
+            return disco_info.muc_description
 
         composers = tuple(c.name for c in typing)
         n = len(composers)
@@ -333,7 +334,7 @@ def _update_description_label(self) -> None:
         else:
             assert not isinstance(contact, GroupchatContact)
             text = contact.status or ''
-        self._ui.description_label.set_text(text)
+        self._ui.description_label.set_markup(make_href_markup(text))
         self._ui.description_label.set_visible(bool(text))
 
     def _update_account_badge(self) -> None:


=====================================
gajim/gtk/groupchat_info.py
=====================================
@@ -8,7 +8,6 @@
 import time
 
 from gi.repository import Gdk
-from gi.repository import GLib
 from gi.repository import Gtk
 from nbxmpp import JID
 from nbxmpp.namespaces import Namespace
@@ -151,8 +150,7 @@ def set_subject(self, muc_subject: MucSubject | None) -> 
None:
         self._ui.author_label.set_visible(has_author)
 
         has_subject = bool(muc_subject.text)
-        subject = GLib.markup_escape_text(muc_subject.text)
-        self._ui.subject.set_markup(make_href_markup(subject))
+        self._ui.subject.set_markup(make_href_markup(muc_subject.text))
         self._ui.subject.set_visible(has_subject)
         self._ui.subject_label.set_visible(has_subject)
 
@@ -187,7 +185,7 @@ def set_from_disco_info(self, info: DiscoInfo) -> None:
 
         # Set description
         has_desc = bool(info.muc_description)
-        self._ui.description.set_text(info.muc_description or '')
+        self._ui.description.set_markup(make_href_markup(info.muc_description))
         self._ui.description.set_visible(has_desc)
         self._ui.description_label.set_visible(has_desc)
 


=====================================
gajim/gtk/util.py
=====================================
@@ -652,11 +652,16 @@ def get_thumbnail_size(pixbuf: GdkPixbuf.Pixbuf, size: 
int) -> tuple[int, int]:
     return image_width, image_height
 
 
-def make_href_markup(string: str) -> str:
+def make_href_markup(string: str | None) -> str:
+    if not string:
+        return ''
+
     url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
     assert isinstance(url_color, str)
     color = convert_rgb_to_hex(url_color)
 
+    string = GLib.markup_escape_text(string)
+
     def _to_href(match: Match[str]) -> str:
         url = match.group()
         if '://' not in url:



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/c0f61266c062d7e422842a7547bba740638a7ac7

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/c0f61266c062d7e422842a7547bba740638a7ac7
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to