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
public void injectMessage(SessionID session, String body) throws OtrException {
MessagePacket packet = new MessagePacket();
packet.setFrom(account.getFullJid()); //sender
packet.setTo(session.getAccountID()+"/"+session.getUserID()); //reciepient
packet.setFrom(account.getFullJid());
if (session.getUserID().isEmpty()) {
packet.setTo(session.getAccountID());
} else {
packet.setTo(session.getAccountID()+"/"+session.getUserID());
}
packet.setBody(body);
packet.addChild("private","urn:xmpp:carbons:2");
packet.addChild("no-copy","urn:xmpp:hints");
packet.setType(MessagePacket.TYPE_CHAT);
//Log.d(LOGTAG,packet.toString());
account.getXmppConnection().sendMessagePacket(packet);
}

View file

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

View file

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

View file

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

View file

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