handle bare jid presences. fixes for otr

This commit is contained in:
iNPUTmice 2014-08-11 13:46:32 +02:00
parent 9960cb819e
commit f247abc2dc
5 changed files with 52 additions and 35 deletions

View file

@ -154,13 +154,16 @@ public class OtrEngine implements OtrEngineHost {
@Override @Override
public void injectMessage(SessionID session, String body) throws OtrException { public void injectMessage(SessionID session, String body) throws OtrException {
MessagePacket packet = new MessagePacket(); MessagePacket packet = new MessagePacket();
packet.setFrom(account.getFullJid()); //sender packet.setFrom(account.getFullJid());
packet.setTo(session.getAccountID()+"/"+session.getUserID()); //reciepient if (session.getUserID().isEmpty()) {
packet.setTo(session.getAccountID());
} else {
packet.setTo(session.getAccountID()+"/"+session.getUserID());
}
packet.setBody(body); packet.setBody(body);
packet.addChild("private","urn:xmpp:carbons:2"); packet.addChild("private","urn:xmpp:carbons:2");
packet.addChild("no-copy","urn:xmpp:hints"); packet.addChild("no-copy","urn:xmpp:hints");
packet.setType(MessagePacket.TYPE_CHAT); packet.setType(MessagePacket.TYPE_CHAT);
//Log.d(LOGTAG,packet.toString());
account.getXmppConnection().sendMessagePacket(packet); account.getXmppConnection().sendMessagePacket(packet);
} }

View file

@ -224,7 +224,7 @@ public class Message extends AbstractEntity {
} }
public void setPresence(String presence) { public void setPresence(String presence) {
if (presence == null) { if (presence == null || presence.isEmpty()) {
this.counterpart = this.counterpart.split("/")[0]; this.counterpart = this.counterpart.split("/")[0];
} else { } else {
this.counterpart = this.counterpart.split("/")[0] + "/" + presence; this.counterpart = this.counterpart.split("/")[0] + "/" + presence;

View file

@ -63,6 +63,8 @@ public abstract class AbstractParser {
String presence = null; String presence = null;
if (fromParts.length >= 2) { if (fromParts.length >= 2) {
presence = fromParts[1]; presence = fromParts[1];
} else {
presence = "";
} }
Contact contact = account.getRoster().getContact(from); Contact contact = account.getRoster().getContact(from);
long timestamp = getTimestamp(packet); long timestamp = getTimestamp(packet);

View file

@ -58,25 +58,31 @@ public class MessageParser extends AbstractParser implements
String[] fromParts = packet.getFrom().split("/"); String[] fromParts = packet.getFrom().split("/");
Conversation conversation = mXmppConnectionService Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false); .findOrCreateConversation(account, fromParts[0], false);
String presence;
if (fromParts.length >= 2) {
presence = fromParts[1];
} else {
presence = "";
}
updateLastseen(packet, account, true); updateLastseen(packet, account, true);
String body = packet.getBody(); String body = packet.getBody();
if (!conversation.hasValidOtrSession()) { if (!conversation.hasValidOtrSession()) {
if (properlyAddressed) { if (properlyAddressed) {
conversation.startOtrSession( conversation.startOtrSession(
mXmppConnectionService.getApplicationContext(), mXmppConnectionService.getApplicationContext(),
fromParts[1], false); presence, false);
} else { } else {
return null; return null;
} }
} else { } else {
String foreignPresence = conversation.getOtrSession() String foreignPresence = conversation.getOtrSession()
.getSessionID().getUserID(); .getSessionID().getUserID();
if (!foreignPresence.equals(fromParts[1])) { if (!foreignPresence.equals(presence)) {
conversation.endOtrIfNeeded(); conversation.endOtrIfNeeded();
if (properlyAddressed) { if (properlyAddressed) {
conversation.startOtrSession( conversation.startOtrSession(
mXmppConnectionService.getApplicationContext(), mXmppConnectionService.getApplicationContext(),
fromParts[1], false); presence, false);
} else { } else {
return null; return null;
} }

View file

@ -21,13 +21,13 @@ public class PresenceParser extends AbstractParser implements
public void parseConferencePresence(PresencePacket packet, Account account) { public void parseConferencePresence(PresencePacket packet, Account account) {
PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine(); PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine();
if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) { if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) {
Conversation muc = mXmppConnectionService.find(account,packet Conversation muc = mXmppConnectionService.find(account, packet
.getAttribute("from").split("/")[0]); .getAttribute("from").split("/")[0]);
if (muc != null) { if (muc != null) {
muc.getMucOptions().processPacket(packet, mPgpEngine); muc.getMucOptions().processPacket(packet, mPgpEngine);
} }
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) { } else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
Conversation muc = mXmppConnectionService.find(account,packet Conversation muc = mXmppConnectionService.find(account, packet
.getAttribute("from").split("/")[0]); .getAttribute("from").split("/")[0]);
if (muc != null) { if (muc != null) {
muc.getMucOptions().processPacket(packet, mPgpEngine); muc.getMucOptions().processPacket(packet, mPgpEngine);
@ -37,7 +37,8 @@ public class PresenceParser extends AbstractParser implements
} }
public void parseContactPresence(PresencePacket packet, Account account) { public void parseContactPresence(PresencePacket packet, Account account) {
PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator(); PresenceGenerator mPresenceGenerator = mXmppConnectionService
.getPresenceGenerator();
if (packet.getFrom() == null) { if (packet.getFrom() == null) {
return; return;
} }
@ -56,9 +57,14 @@ public class PresenceParser extends AbstractParser implements
} else { } else {
Contact contact = account.getRoster().getContact(packet.getFrom()); Contact contact = account.getRoster().getContact(packet.getFrom());
if (type == null) { if (type == null) {
if (fromParts.length == 2) { String presence;
if (fromParts.length >= 2) {
presence = fromParts[1];
} else {
presence = "";
}
int sizeBefore = contact.getPresences().size(); int sizeBefore = contact.getPresences().size();
contact.updatePresence(fromParts[1], contact.updatePresence(presence,
Presences.parseShow(packet.findChild("show"))); Presences.parseShow(packet.findChild("show")));
PgpEngine pgp = mXmppConnectionService.getPgpEngine(); PgpEngine pgp = mXmppConnectionService.getPgpEngine();
if (pgp != null) { if (pgp != null) {
@ -79,7 +85,6 @@ public class PresenceParser extends AbstractParser implements
updateLastseen(packet, account, true); updateLastseen(packet, account, true);
mXmppConnectionService.onContactStatusChanged mXmppConnectionService.onContactStatusChanged
.onContactStatusChanged(contact, online); .onContactStatusChanged(contact, online);
}
} else if (type.equals("unavailable")) { } else if (type.equals("unavailable")) {
if (fromParts.length != 2) { if (fromParts.length != 2) {
contact.clearPresences(); contact.clearPresences();
@ -90,7 +95,8 @@ public class PresenceParser extends AbstractParser implements
.onContactStatusChanged(contact, false); .onContactStatusChanged(contact, false);
} else if (type.equals("subscribe")) { } else if (type.equals("subscribe")) {
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) { if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
mXmppConnectionService.sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact)); mXmppConnectionService.sendPresencePacket(account,
mPresenceGenerator.sendPresenceUpdatesTo(contact));
} else { } else {
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST); contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
} }