aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/muc/MucPacketParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/muc/MucPacketParser.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/muc/MucPacketParser.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/muc/MucPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/muc/MucPacketParser.java
new file mode 100644
index 00000000..d7ec6b38
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/muc/MucPacketParser.java
@@ -0,0 +1,62 @@
+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;
+ }
+}