From f75e6bf7df7285f70eb6abce7684fb8d98f99dfb Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 4 Jan 2023 15:10:53 -0500 Subject: [PATCH] Add roster item after registering with a service And make sure once it comes "online" for us that we refresh command list, if relevant. --- .../siacs/conversations/entities/Conversation.java | 12 +++++++++--- .../services/XmppConnectionService.java | 11 +++++++++-- .../siacs/conversations/ui/ConversationFragment.java | 4 ++++ .../conversations/ui/ConversationsActivity.java | 7 ++++++- .../java/eu/siacs/conversations/ui/XmppFragment.java | 1 + 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index e7e098815eaf1c1541c634fb11f945770588f2e4..af9577526146e8f37d55440727b1e60e1d56aa22 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -1308,7 +1308,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public void startCommand(Element command, XmppConnectionService xmppConnectionService) { show(); - CommandSession session = new CommandSession(command.getAttribute("name"), xmppConnectionService); + CommandSession session = new CommandSession(command.getAttribute("name"), command.getAttribute("node"), xmppConnectionService); final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); packet.setTo(command.getAttributeAsJid("jid")); @@ -2045,6 +2045,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl protected boolean loading = false; protected Timer loadingTimer = new Timer(); protected String mTitle; + protected String mNode; protected CommandPageBinding mBinding = null; protected IqPacket response = null; protected Element responseElement = null; @@ -2055,9 +2056,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl protected GridLayoutManager layoutManager; protected WebView actionToWebview = null; - CommandSession(String title, XmppConnectionService xmppConnectionService) { + CommandSession(String title, String node, XmppConnectionService xmppConnectionService) { loading(); mTitle = title; + mNode = node; this.xmppConnectionService = xmppConnectionService; if (mPager != null) setupLayoutManager(); actionsAdapter = new ArrayAdapter(xmppConnectionService, R.layout.simple_list_item) { @@ -2103,6 +2105,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl Element command = iq.findChild("command", "http://jabber.org/protocol/commands"); if (iq.getType() == IqPacket.TYPE.RESULT && command != null) { + if (mNode.equals("jabber:iq:register") && command.getAttribute("status").equals("completed")) { + xmppConnectionService.createContact(getAccount().getRoster().getContact(iq.getFrom()), true); + } + for (Element el : command.getChildren()) { if (el.getName().equals("actions") && el.getNamespace().equals("http://jabber.org/protocol/commands")) { for (Element action : el.getChildren()) { @@ -2367,7 +2373,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); packet.setTo(response.getFrom()); final Element c = packet.addChild("command", Namespace.COMMANDS); - c.setAttribute("node", command.getAttribute("node")); + c.setAttribute("node", mNode); c.setAttribute("sessionid", command.getAttribute("sessionid")); c.setAttribute("action", action); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 7eac0d2285d01bef1dc06c879e4ffc00562e99d0..57f47ae58c57148667a268b6a349427a202b482d 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -4271,8 +4271,12 @@ public class XmppConnectionService extends Service { } public void updateConversationUi() { + updateConversationUi(false); + } + + public void updateConversationUi(boolean newCaps) { for (OnConversationUpdate listener : threadSafeList(this.mOnConversationUpdates)) { - listener.onConversationUpdate(); + listener.onConversationUpdate(newCaps); } } @@ -4801,6 +4805,7 @@ public class XmppConnectionService extends Service { contact.registerAsPhoneAccount(this); mQuickConversationsService.considerSyncBackground(false); } + updateConversationUi(true); } else { final IqPacket request = new IqPacket(IqPacket.TYPE.GET); request.setTo(jid); @@ -4822,6 +4827,7 @@ public class XmppConnectionService extends Service { contact.registerAsPhoneAccount(this); mQuickConversationsService.considerSyncBackground(false); } + updateConversationUi(true); if (cb != null) cb.run(); } else { Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + discoveryResult.getVer()); @@ -5017,7 +5023,8 @@ public class XmppConnectionService extends Service { } public interface OnConversationUpdate { - void onConversationUpdate(); + default void onConversationUpdate() { onConversationUpdate(false); } + default void onConversationUpdate(boolean newCaps) { onConversationUpdate(); } } public interface OnJingleRtpConnectionUpdate { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 123f154b3456ea7b9011facb49e5c4f040422313..7d4524600cef11543f08aa6eacc9aee5fb1844dd 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -2641,6 +2641,10 @@ public class ConversationFragment extends XmppFragment return true; } + public void refreshForNewCaps() { + refreshCommands(); + } + protected void refreshCommands() { if (commandAdapter == null) return; diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index 07c0d74859f365dbb6a84f58708331746ab08383..4ee603b615eb85f7c84d2b91bbdce88c43e4b921 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -119,6 +119,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio private ActivityConversationsBinding binding; private boolean mActivityPaused = true; private final AtomicBoolean mRedirectInProcess = new AtomicBoolean(false); + private boolean refreshForNewCaps = false; private static boolean isViewOrShareIntent(Intent i) { Log.d(Config.LOGTAG, "action: " + (i == null ? null : i.getAction())); @@ -138,6 +139,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) { refreshFragment(id); } + refreshForNewCaps = false; } @Override @@ -256,6 +258,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio final Fragment fragment = getFragmentManager().findFragmentById(id); if (fragment instanceof XmppFragment) { ((XmppFragment) fragment).refresh(); + if (refreshForNewCaps) ((XmppFragment) fragment).refreshForNewCaps(); } } @@ -705,15 +708,17 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio } @Override - public void onConversationUpdate() { + public void onConversationUpdate(boolean newCaps) { if (performRedirectIfNecessary(false)) { return; } + refreshForNewCaps = newCaps; this.refreshUi(); } @Override public void onRosterUpdate() { + refreshForNewCaps = true; this.refreshUi(); } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppFragment.java b/src/main/java/eu/siacs/conversations/ui/XmppFragment.java index 30524d2f5441f3e0405ec38d1807e9a7d3294080..e9844b055df90ae2c3e6b88246c4b34c6da7398d 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppFragment.java @@ -37,6 +37,7 @@ import eu.siacs.conversations.ui.interfaces.OnBackendConnected; public abstract class XmppFragment extends Fragment implements OnBackendConnected { abstract void refresh(); + public void refreshForNewCaps() { } protected void runOnUiThread(Runnable runnable) { final Activity activity = getActivity();