Linkyfy tel and sms URIs

Stephen Paul Weber created

Change summary

src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java |  2 +
src/main/java/eu/siacs/conversations/utils/Patterns.java    | 14 +++++-
2 files changed, 13 insertions(+), 3 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java 🔗

@@ -127,6 +127,8 @@ public class MyLinkify {
 
     public static void addLinks(Editable body, boolean includeGeo) {
         Linkify.addLinks(body, Patterns.XMPP_PATTERN, "xmpp", XMPPURI_MATCH_FILTER, null);
+        Linkify.addLinks(body, Patterns.TEL_URI, "tel");
+        Linkify.addLinks(body, Patterns.SMS_URI, "sms");
         Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER);
         if (includeGeo) {
             Linkify.addLinks(body, GeoHelper.GEO_URI, "geo");

src/main/java/eu/siacs/conversations/utils/Patterns.java 🔗

@@ -337,9 +337,10 @@ public class Patterns {
             + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
             + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@";
     private static final String PORT_NUMBER = "\\:\\d{1,5}";
-    private static final String PATH_AND_QUERY = "\\/(?:(?:[" + LABEL_CHAR
-            + "\\;\\/\\?\\:\\@\\&\\=\\#\\~"  // plus optional query params
-            + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_\\$])|(?:\\%[a-fA-F0-9]{2}))*";
+    private static final String PATH_CHAR = "(?:(?:[" + LABEL_CHAR
+            + "\\;\\/\\?\\:\\@\\&\\=\\#\\~"
+            + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_\\$])|(?:\\%[a-fA-F0-9]{2}))";
+    private static final String PATH_AND_QUERY = "\\/" + PATH_CHAR + "*";
     /**
      *  Regular expression pattern to match most part of RFC 3987
      *  Internationalized URLs, aka IRIs.
@@ -464,6 +465,13 @@ public class Patterns {
             "(\\+[0-9]+[\\- \\.]*)?"        // +<digits><sdd>*
                     + "(\\([0-9]+\\)[\\- \\.]*)?"   // (<digits>)<sdd>*
                     + "([0-9][0-9\\- \\.]+[0-9])"); // <digit><digit|sdd>+<digit>
+
+    public static final Pattern TEL_URI =
+        Pattern.compile("tel:(?:(?:\\+\\d+)|(?:\\d+;phone-context=" + PATH_CHAR + "+))");
+
+    public static final Pattern SMS_URI =
+        Pattern.compile("sms:(?:(?:\\+\\d+)|(?:\\d+;phone-context=" + PATH_CHAR + "+))");
+
     /**
      *  Convenience method to take all of the non-null matching groups in a
      *  regex Matcher and return them as a concatenated string.