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();
}
} else if (presences.size() == 1) {
String presence = presences.toResourceArray()[0];
try {
conversation.setNextCounterpart(Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), presence));
} catch (IllegalArgumentException e) {
conversation.setNextCounterpart(null);
}
final String presence = presences.toResourceArray()[0];
conversation.setNextCounterpart(PresenceSelector.getNextCounterpart(contact, presence));
listener.onPresenceSelected();
} else {
PresenceSelector.showPresenceSelectionDialog(this, conversation, listener);

View File

@ -106,12 +106,21 @@ public class PresenceSelector {
builder.setPositiveButton(
R.string.ok,
(dialog, which) -> onFullJidSelected.onFullJidSelected(
Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), resourceArray[selectedResource.get()])
getNextCounterpart(contact, resourceArray[selectedResource.get()])
)
);
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) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(conversation.getContact().getJid().toString());