From 0e6d3db92622cb1e6bc5e9b89ae6089a5433cc70 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 5 Dec 2017 19:02:23 +0100 Subject: [PATCH] Do not show xmpp uris as links that have invalid jids --- .../conversations/ui/adapter/MessageAdapter.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index af1bd21fb..b93931d7e 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -76,6 +76,7 @@ import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.Patterns; import eu.siacs.conversations.utils.StylingHelper; import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.xmpp.mam.MamReference; public class MessageAdapter extends ArrayAdapter implements CopyTextView.CopyHandler { @@ -114,6 +115,14 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } }; + private static final Linkify.MatchFilter XMPPURI_MATCH_FILTER = new Linkify.MatchFilter() { + @Override + public boolean acceptMatch(CharSequence s, int start, int end) { + XmppUri uri = new XmppUri(s.subSequence(start,end).toString()); + return uri.isJidValid(); + } + }; + private final ConversationActivity activity; private DisplayMetrics metrics; @@ -491,7 +500,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie StylingHelper.format(body, viewHolder.messageBody.getCurrentTextColor()); - Linkify.addLinks(body, XMPP_PATTERN, "xmpp"); + Linkify.addLinks(body, XMPP_PATTERN, "xmpp", XMPPURI_MATCH_FILTER, null); Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER); Linkify.addLinks(body, GeoHelper.GEO_URI, "geo"); FixedURLSpan.fix(body);