From daac695094660c19c59d0c90010db33f076a33cf Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 15 Nov 2024 05:21:13 +0100 Subject: [PATCH] Add wownero I think the regex is too broad but no one seems to know what it should be (cherry picked from commit 13066f53b074415aaccf39bac93b0aa4beaa843f) --- src/main/java/eu/siacs/conversations/entities/Message.java | 2 +- .../eu/siacs/conversations/ui/ContactDetailsActivity.java | 4 ++++ .../eu/siacs/conversations/ui/adapter/MessageAdapter.java | 5 +++++ src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java | 1 + src/main/java/eu/siacs/conversations/utils/Patterns.java | 6 ++++++ src/monocleschat/res/drawable/wownero_24dp.xml | 5 +++++ 6 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/monocleschat/res/drawable/wownero_24dp.xml diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index acd556f16..7cc99bf59 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -1452,7 +1452,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable public synchronized Uri wholeIsKnownURI() { if (wholeIsKnownURI != null) return wholeIsKnownURI; - if (Patterns.BITCOIN_URI.matcher(body).matches() ||Patterns.BITCOINCASH_URI.matcher(body).matches() || Patterns.MONERO_URI.matcher(body).matches()) { + if (Patterns.BITCOIN_URI.matcher(body).matches() ||Patterns.BITCOINCASH_URI.matcher(body).matches() || Patterns.MONERO_URI.matcher(body).matches() || Patterns.WOWNERO_URI.matcher(body).matches()) { wholeIsKnownURI = Uri.parse(body.replace(":", "://")); // hack to make query parser work } diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 831fc27b0..08497ae30 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -862,6 +862,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp binding.command.setText(uri.getSchemeSpecificPart()); binding.command.setCompoundDrawablesRelativeWithIntrinsicBounds(getDrawable(R.drawable.monero_24dp), null, null, null); binding.command.setCompoundDrawablePadding(20); + } else if (uri.getScheme().equals("wownero")) { + binding.command.setText(uri.getSchemeSpecificPart()); + binding.command.setCompoundDrawablesRelativeWithIntrinsicBounds(getDrawable(R.drawable.wownero_24dp), null, null, null); + binding.command.setCompoundDrawablePadding(20); } else if (uri.getScheme().equals("https") && "liberapay.com".equals(uri.getHost())) { binding.command.setText(uri.getPath().substring(1)); binding.command.setCompoundDrawablesRelativeWithIntrinsicBounds(getDrawable(R.drawable.liberapay), null, null, null); 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 cd3d9cc03..eb57fa798 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -958,6 +958,11 @@ public class MessageAdapter extends ArrayAdapter { final var formattedAmount = amount == null || amount.equals("") ? "" : amount + " "; viewHolder.download_button.setIconResource(R.drawable.monero_24dp); viewHolder.download_button.setText("Send " + formattedAmount + "Monero"); + } else if ("wownero".equals(uri.getScheme())) { + final var amount = uri.getQueryParameter("tx_amount"); + final var formattedAmount = amount == null || amount.equals("") ? "" : amount + " "; + viewHolder.download_button.setIconResource(R.drawable.wownero_24dp); + viewHolder.download_button.setText("Send " + formattedAmount + "Wownero"); } viewHolder.download_button.setOnClickListener(v -> new FixedURLSpan(message.getRawBody()).onClick(v)); } diff --git a/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java b/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java index 7c053420b..27868abe6 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java @@ -135,6 +135,7 @@ public class MyLinkify { Linkify.addLinks(body, Patterns.BITCOIN_URI, "bitcoin"); Linkify.addLinks(body, Patterns.BITCOINCASH_URI, "bitcoincash"); Linkify.addLinks(body, Patterns.MONERO_URI, "monero"); + Linkify.addLinks(body, Patterns.WOWNERO_URI, "wownero"); Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER); if (includeGeo) { Linkify.addLinks(body, GeoHelper.GEO_URI, "geo"); diff --git a/src/main/java/eu/siacs/conversations/utils/Patterns.java b/src/main/java/eu/siacs/conversations/utils/Patterns.java index b72ad37bb..ad6f34c17 100644 --- a/src/main/java/eu/siacs/conversations/utils/Patterns.java +++ b/src/main/java/eu/siacs/conversations/utils/Patterns.java @@ -51,6 +51,12 @@ public class Patterns { + "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])" + "|(?:\\%[a-fA-F0-9]{2}))+)?"); + public static final Pattern WOWNERO_URI = Pattern + .compile("wownero\\:(?:W(?:[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{96}|[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{106}|[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{187}))(?:\\?(?:(?:[" + + Patterns.GOOD_IRI_CHAR + + "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])" + + "|(?:\\%[a-fA-F0-9]{2}))+)?"); + /** * Regular expression to match all IANA top-level domains. * List accurate as of 2011/07/18. List taken from: diff --git a/src/monocleschat/res/drawable/wownero_24dp.xml b/src/monocleschat/res/drawable/wownero_24dp.xml new file mode 100644 index 000000000..4ad3ca9b8 --- /dev/null +++ b/src/monocleschat/res/drawable/wownero_24dp.xml @@ -0,0 +1,5 @@ + + +