XmppUri: Parse 'message action' query

This commit is contained in:
Marc Schink 2017-12-05 21:46:48 +01:00
parent edf3c41e58
commit 0fac4be94d
2 changed files with 27 additions and 10 deletions

View File

@ -876,7 +876,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
return true; return true;
} }
List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account); List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account);
if (invite.isMuc()) { if (invite.isAction(XmppUri.ACTION_JOIN)) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid()); Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
if (muc != null) { if (muc != null) {
switchToConversation(muc,invite.getBody(),false); switchToConversation(muc,invite.getBody(),false);
@ -1202,9 +1202,5 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
return false; return false;
} }
public boolean isMuc() {
return muc;
}
} }
} }

View File

@ -14,14 +14,17 @@ import eu.siacs.conversations.xmpp.jid.Jid;
public class XmppUri { public class XmppUri {
protected String jid; protected String jid;
protected boolean muc;
protected List<Fingerprint> fingerprints = new ArrayList<>(); protected List<Fingerprint> fingerprints = new ArrayList<>();
private String body; private String body;
private String action;
protected boolean safeSource = true; protected boolean safeSource = true;
public static final String OMEMO_URI_PARAM = "omemo-sid-"; public static final String OMEMO_URI_PARAM = "omemo-sid-";
public static final String OTR_URI_PARAM = "otr-fingerprint"; public static final String OTR_URI_PARAM = "otr-fingerprint";
public static final String ACTION_JOIN = "join";
public static final String ACTION_MESSAGE = "message";
public XmppUri(String uri) { public XmppUri(String uri) {
try { try {
parse(Uri.parse(uri)); parse(Uri.parse(uri));
@ -63,11 +66,21 @@ public class XmppUri {
// sample : https://conversations.im/i/foo/bar.com // sample : https://conversations.im/i/foo/bar.com
jid = segments.get(1) + "@" + segments.get(2); jid = segments.get(1) + "@" + segments.get(2);
} }
muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0)); if (segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0))) {
action = ACTION_JOIN;
}
fingerprints = parseFingerprints(uri.getQuery(),'&'); fingerprints = parseFingerprints(uri.getQuery(),'&');
} else if ("xmpp".equalsIgnoreCase(scheme)) { } else if ("xmpp".equalsIgnoreCase(scheme)) {
// sample: xmpp:foo@bar.com // sample: xmpp:foo@bar.com
muc = isMuc(uri.getQuery());
final String query = uri.getQuery();
if (hasAction(query, ACTION_JOIN)) {
this.action = ACTION_JOIN;
} else if (hasAction(query, ACTION_MESSAGE)) {
this.action = ACTION_MESSAGE;
}
if (uri.getAuthority() != null) { if (uri.getAuthority() != null) {
jid = uri.getAuthority(); jid = uri.getAuthority();
} else { } else {
@ -138,16 +151,24 @@ public class XmppUri {
return null; return null;
} }
protected boolean isMuc(String query) { private boolean hasAction(String query, String action) {
for(String pair : query == null ? new String[0] : query.split(";")) { for(String pair : query == null ? new String[0] : query.split(";")) {
final String[] parts = pair.split("=",2); final String[] parts = pair.split("=",2);
if (parts.length == 1 && "join".equals(parts[0])) { if (parts.length == 1 && parts[0].equals(action)) {
return true; return true;
} }
} }
return false; return false;
} }
public boolean isAction(final String action) {
if (this.action == null) {
return false;
}
return this.action.equals(action);
}
public Jid getJid() { public Jid getJid() {
try { try {
return this.jid == null ? null :Jid.fromString(this.jid.toLowerCase()); return this.jid == null ? null :Jid.fromString(this.jid.toLowerCase());