Commit 26c5852d authored by pg mr's avatar pg mr
Browse files

Added fixes

parent ff4fc92a
Pipeline #7734 failed with stages
in 0 seconds
......@@ -21,6 +21,7 @@
from gajim.common import helpers
from gajim.common.app import interface
from gajim.common.exceptions import GajimGeneralException
from gajim.common.helpers import open_uri
from gajim.common.regex import LINK_REGEX
from gajim import dialogs
......@@ -259,16 +260,12 @@ def on_remove_event(_action, param):
win.show_title()
def on_open_link_from_msg_event(_action, param):
dict_ = param.unpack()
account, jid, type_ = dict_['account'], dict_['jid'], dict_['type_']
to_search = app.events.get_events(account,jid)[-1].message # something better might be needed
search_result =LINK_REGEX.search(to_search).group()
if search_result is not None:
if search_result.startswith("www."): #for "legacy_prefixes"
search_result = "http://%s"%search_result
if search_result.startswith("ftp."): #for "legacy_prefixes"
search_result = "ftp://%s"%search_result
Gtk.show_uri_on_window(None,search_result,Gdk.CURRENT_TIME)
par_unpack = param.unpack()
dict_ = dict(par_unpack[0])
account, jid, type_ = dict_['account'], dict_['jid'], dict_['type_'] # maybe use this to remove event?
for link in par_unpack[1]:
open_uri(link)
# Other Actions
......
......@@ -470,7 +470,7 @@ def _get_account_actions(account):
('-delete-motd', a.on_delete_motd, 'online', 's'),
('-open-event', a.on_open_event, 'always', 'a{sv}'),
('-remove-event', a.on_remove_event, 'always', 'a{sv}'),
('-open-link-from-msg-event', a.on_open_link_from_msg_event, 'always', 'a{sv}'),
('-open-link-from-msg-event', a.on_open_link_from_msg_event, 'always', '(a(sv)as)'),
('-import-contacts', a.on_import_contacts, 'online', 's'),
]
......
......@@ -23,7 +23,7 @@
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import re
import sys
import logging
......@@ -37,7 +37,7 @@
from gajim.common import helpers
from gajim.common import ged
from gajim.common.const import StyleAttr
from gajim.common.i18n import _
from gajim.common.i18n import _, ngettext
from gajim.common.nec import EventHelper
from gajim.common.regex import LINK_REGEX
......@@ -210,9 +210,18 @@ def popup(self, event_type, jid, account, type_='', icon_name=None,
notification.add_button_with_target(
_('Mark as Read'), action, variant_dict)
if text is not None:
if LINK_REGEX.search(text) is not None:
search_result = list(LINK_REGEX.finditer(text))
if len(search_result) != 0:
notification.set_body(self._make_links_nice(text))
action = 'app.{}-open-link-from-msg-event'.format(account)
notification.add_button_with_target(_('Open link'), action, variant_dict)
button_text = ngettext('Open %d link',
"Open %d links",
len(search_result),
len(search_result),
len(search_result))
uris = GLib.Variant('as', [sr.group() for sr in search_result])
variant_link = GLib.Variant('(a(sv)as)', (dict_, uris))
notification.add_button_with_target(button_text, action, variant_link)
# Only one notification per JID
if event_type == _('Contact Changed Status'):
......@@ -233,6 +242,24 @@ def popup(self, event_type, jid, account, type_='', icon_name=None,
app.app.send_notification(notif_id, notification)
def _make_links_nice(self, text: str) -> str:
if "body-hyperlinks" in self._daemon_capabilities:
def add_prefix(match: re.Match) -> str:
uri = match.group()
prefix = ""
if uri.startswith("www."):
prefix = "https"
elif uri.startswith("ftp."):
prefix = "ftp"
elif re.match(r'\w+@\S+\.\S*[^\s\W]', uri): # should match naked username
prefix = "xmpp"
return "<a href=\"%s\">%s</a>" % ("%s://%s" % (prefix, uri), uri)
return LINK_REGEX.sub(add_prefix, text)
elif "body-markup" in self._daemon_capabilities:
return LINK_REGEX.sub("<u>\g<0></u>", text)
return text
@staticmethod
def _get_avatar_for_notification(account, jid):
scale = get_monitor_scale_factor()
......
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