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

@ -13,7 +13,7 @@ import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
public class PresenceParser extends AbstractParser implements
OnPresencePacketReceived {
public PresenceParser(XmppConnectionService service) {
super(service);
}
@ -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,30 +57,34 @@ public class PresenceParser extends AbstractParser implements
} else {
Contact contact = account.getRoster().getContact(packet.getFrom());
if (type == null) {
if (fromParts.length == 2) {
int sizeBefore = contact.getPresences().size();
contact.updatePresence(fromParts[1],
Presences.parseShow(packet.findChild("show")));
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
if (pgp != null) {
Element x = packet.findChild("x", "jabber:x:signed");
if (x != null) {
Element status = packet.findChild("status");
String msg;
if (status != null) {
msg = status.getContent();
} else {
msg = "";
}
contact.setPgpKeyId(pgp.fetchKeyId(account, msg,
x.getContent()));
}
}
boolean online = sizeBefore < contact.getPresences().size();
updateLastseen(packet, account, true);
mXmppConnectionService.onContactStatusChanged
.onContactStatusChanged(contact, online);
String presence;
if (fromParts.length >= 2) {
presence = fromParts[1];
} else {
presence = "";
}
int sizeBefore = contact.getPresences().size();
contact.updatePresence(presence,
Presences.parseShow(packet.findChild("show")));
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
if (pgp != null) {
Element x = packet.findChild("x", "jabber:x:signed");
if (x != null) {
Element status = packet.findChild("status");
String msg;
if (status != null) {
msg = status.getContent();
} else {
msg = "";
}
contact.setPgpKeyId(pgp.fetchKeyId(account, msg,
x.getContent()));
}
}
boolean online = sizeBefore < contact.getPresences().size();
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);
}