From cd934f39a31edfb2c708400aba8ce6aa4df952f1 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 4 Jul 2024 20:46:16 -0500 Subject: [PATCH] New option to invite MUC participant to chat --- .../ui/util/MucDetailsContextMenuHelper.java | 17 ++++++++++++++++- .../siacs/conversations/ui/util/MyLinkify.java | 2 +- .../eu/siacs/conversations/utils/XmppUri.java | 14 ++++++++++++++ src/main/res/menu/muc_details_context.xml | 4 ++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java index 3bcde67bc..1e6881fd9 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java @@ -36,7 +36,7 @@ import eu.siacs.conversations.ui.MucUsersActivity; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.Jid; - +import eu.siacs.conversations.xml.Element; public final class MucDetailsContextMenuHelper { private static final int ACTION_BAN = 0; @@ -113,6 +113,7 @@ public final class MucDetailsContextMenuHelper { final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false); final boolean isGroupChat = mucOptions.isPrivateAndNonAnonymous(); MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message); + MenuItem shareContactDetails = menu.findItem(R.id.share_contact_details); MenuItem blockAvatar = menu.findItem(R.id.action_block_avatar); if (user != null && user.getAvatar() != null) { @@ -170,9 +171,11 @@ public final class MucDetailsContextMenuHelper { } managePermissions.setVisible(managePermissionsVisible); sendPrivateMessage.setVisible(user.isOnline() && !isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); + shareContactDetails.setVisible(user.isOnline() && !isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); } else { sendPrivateMessage.setVisible(user != null && user.isOnline()); sendPrivateMessage.setEnabled(user != null && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); + shareContactDetails.setVisible(user != null && user.isOnline() && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); } } @@ -291,6 +294,18 @@ public final class MucDetailsContextMenuHelper { } activity.privateMsgInMuc(conversation, user.getName()); return true; + case R.id.share_contact_details: + final var message = new Message(conversation, "/me invites you to chat " + conversation.getAccount().getShareableUri(), conversation.getNextEncryption()); + Message.configurePrivateMessage(message, user.getFullJid()); + /* This triggers a gajim bug right now https://dev.gajim.org/gajim/gajim/-/issues/11900 + final var rosterx = new Element("x", "http://jabber.org/protocol/rosterx"); + final var ritem = rosterx.addChild("item"); + ritem.setAttribute("action", "add"); + ritem.setAttribute("name", conversation.getMucOptions().getSelf().getNick()); + ritem.setAttribute("jid", conversation.getAccount().getJid().asBareJid().toEscapedString()); + message.addPayload(rosterx);*/ + activity.xmppConnectionService.sendMessage(message); + return true; case R.id.invite: if (user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) { activity.xmppConnectionService.directInvite(conversation, jid.asBareJid()); 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 ef33fac14..1217a6e18 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java @@ -158,7 +158,7 @@ public class MyLinkify { } else { ListItem item = account.getBookmark(jid); if (item == null) item = roster.getContact(jid); - display = item.getDisplayName() + xmppUri.parameterString(); + display = item.getDisplayName() + xmppUri.displayParameterString(); } body.replace( body.getSpanStart(urlspan), diff --git a/src/main/java/eu/siacs/conversations/utils/XmppUri.java b/src/main/java/eu/siacs/conversations/utils/XmppUri.java index 9d7236ddf..ecd809010 100644 --- a/src/main/java/eu/siacs/conversations/utils/XmppUri.java +++ b/src/main/java/eu/siacs/conversations/utils/XmppUri.java @@ -245,6 +245,20 @@ public class XmppUri { return s.toString(); } + public String displayParameterString() { + final StringBuilder s = new StringBuilder(); + for (Map.Entry param : parameters.entrySet()) { + if (param.getValue() == null || param.getValue().isEmpty()) continue; + if (param.getKey().startsWith(OMEMO_URI_PARAM)) continue; + + s.append(";"); + s.append(param.getKey()); + s.append("="); + s.append(param.getValue()); + } + return s.toString(); + } + public List getFingerprints() { return this.fingerprints; } diff --git a/src/main/res/menu/muc_details_context.xml b/src/main/res/menu/muc_details_context.xml index 0b524a18d..e75f77c98 100644 --- a/src/main/res/menu/muc_details_context.xml +++ b/src/main/res/menu/muc_details_context.xml @@ -28,6 +28,10 @@ android:id="@+id/send_private_message" android:title="@string/send_private_message" android:visible="false" /> +