package de.thedevstack.conversationsplus.xmpp.muc; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Conversation; import de.thedevstack.conversationsplus.persistance.DatabaseBackend; import de.thedevstack.conversationsplus.utils.UiUpdateHelper; import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; import de.thedevstack.conversationsplus.xml.Element; import de.thedevstack.conversationsplus.xmpp.jid.Jid; /** */ public class MucPacketParser { private static class Invite { Jid jid; String password; Invite(Jid jid, String password) { this.jid = jid; this.password = password; } public boolean execute(Account account) { if (jid != null) { Conversation conversation = XmppConnectionServiceAccessor.xmppConnectionService.findOrCreateConversation(account, jid, true); if (!conversation.getMucOptions().online()) { conversation.getMucOptions().setPassword(password); DatabaseBackend.getInstance().updateConversation(conversation); XmppConnectionServiceAccessor.xmppConnectionService.joinMuc(conversation); UiUpdateHelper.updateConversationUi(); } return true; } return false; } } private static Invite extractInvite(Element message) { Element x = message.findChild("x", "http://jabber.org/protocol/muc#user"); if (x != null) { Element invite = x.findChild("invite"); if (invite != null) { Element pw = x.findChild("password"); return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent(): null); } } else { x = message.findChild("x","jabber:x:conference"); if (x != null) { return new Invite(x.getAttributeAsJid("jid"),x.getAttribute("password")); } } return null; } public static boolean extractAndExecuteInvite(Account account, Element packet) { Invite invite = extractInvite(packet); if (invite != null && invite.execute(account)) { return true; } return false; } }