fixed direct invites

This commit is contained in:
Daniel Gultsch 2015-04-21 18:36:11 +02:00
parent e9783b80d1
commit 3a627f72fb
1 changed files with 28 additions and 12 deletions

View File

@ -391,15 +391,17 @@ public class MessageParser extends AbstractParser implements
private void parseNonMessage(Element packet, Account account) { private void parseNonMessage(Element packet, Account account) {
final Jid from = packet.getAttributeAsJid("from"); final Jid from = packet.getAttributeAsJid("from");
if (account.getJid().equals(from)) {
return;
}
if (extractChatState(from == null ? null : mXmppConnectionService.find(account,from), packet)) { if (extractChatState(from == null ? null : mXmppConnectionService.find(account,from), packet)) {
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
} }
Element invite = extractInvite(packet); Invite invite = extractInvite(packet);
if (invite != null) { if (invite != null && invite.jid != null) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, from, true); Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, invite.jid, true);
if (!conversation.getMucOptions().online()) { if (!conversation.getMucOptions().online()) {
Element password = invite.findChild("password"); conversation.getMucOptions().setPassword(invite.password);
conversation.getMucOptions().setPassword(password == null ? null : password.getContent());
mXmppConnectionService.databaseBackend.updateConversation(conversation); mXmppConnectionService.databaseBackend.updateConversation(conversation);
mXmppConnectionService.joinMuc(conversation); mXmppConnectionService.joinMuc(conversation);
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
@ -439,17 +441,31 @@ public class MessageParser extends AbstractParser implements
} }
} }
private Element extractInvite(Element message) { private class Invite {
Jid jid;
String password;
Invite(Jid jid, String password) {
this.jid = jid;
this.password = password;
}
}
private Invite extractInvite(Element message) {
Element x = message.findChild("x","http://jabber.org/protocol/muc#user"); Element x = message.findChild("x","http://jabber.org/protocol/muc#user");
if (x == null) { if (x != null) {
x = message.findChild("x","jabber:x:conference"); Element invite = x.findChild("invite");
if (invite != null) {
Element pw = x.findChild("password");
return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent(): null);
} }
if (x != null && x.hasChild("invite")) {
return x;
} else { } else {
return null; x = message.findChild("x","jabber:x:conference");
if (x != null) {
return new Invite(x.getAttributeAsJid("jid"),x.getAttribute("password"));
} }
} }
return null;
}
private void parseEvent(final Element event, final Jid from, final Account account) { private void parseEvent(final Element event, final Jid from, final Account account) {
Element items = event.findChild("items"); Element items = event.findChild("items");