make presence selector work with empty resources (bare jid)

This commit is contained in:
Daniel Gultsch 2020-06-13 09:59:39 +02:00
parent 0dba9f560c
commit fda9e7b51c
2 changed files with 902 additions and 897 deletions

View File

@ -385,12 +385,8 @@ public abstract class XmppActivity extends ActionBarActivity {
listener.onPresenceSelected(); listener.onPresenceSelected();
} }
} else if (presences.size() == 1) { } else if (presences.size() == 1) {
String presence = presences.toResourceArray()[0]; final String presence = presences.toResourceArray()[0];
try { conversation.setNextCounterpart(PresenceSelector.getNextCounterpart(contact, presence));
conversation.setNextCounterpart(Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), presence));
} catch (IllegalArgumentException e) {
conversation.setNextCounterpart(null);
}
listener.onPresenceSelected(); listener.onPresenceSelected();
} else { } else {
PresenceSelector.showPresenceSelectionDialog(this, conversation, listener); PresenceSelector.showPresenceSelectionDialog(this, conversation, listener);

View File

@ -106,12 +106,21 @@ public class PresenceSelector {
builder.setPositiveButton( builder.setPositiveButton(
R.string.ok, R.string.ok,
(dialog, which) -> onFullJidSelected.onFullJidSelected( (dialog, which) -> onFullJidSelected.onFullJidSelected(
Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), resourceArray[selectedResource.get()]) getNextCounterpart(contact, resourceArray[selectedResource.get()])
) )
); );
builder.create().show(); builder.create().show();
} }
public static Jid getNextCounterpart(final Contact contact, final String resource) {
if (resource.isEmpty()) {
return contact.getJid().asBareJid();
} else {
return contact.getJid().withResource(resource);
}
}
public static void warnMutualPresenceSubscription(Activity activity, final Conversation conversation, final OnPresenceSelected listener) { public static void warnMutualPresenceSubscription(Activity activity, final Conversation conversation, final OnPresenceSelected listener) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(conversation.getContact().getJid().toString()); builder.setTitle(conversation.getContact().getJid().toString());