switched to direct invites. fixes #284

iNPUTmice created

Change summary

src/eu/siacs/conversations/generator/MessageGenerator.java     | 10 ++
src/eu/siacs/conversations/parser/MessageParser.java           | 15 +++
src/eu/siacs/conversations/services/XmppConnectionService.java | 16 ---
src/eu/siacs/conversations/ui/XmppActivity.java                |  2 
4 files changed, 27 insertions(+), 16 deletions(-)

Detailed changes

src/eu/siacs/conversations/generator/MessageGenerator.java 🔗

@@ -128,4 +128,14 @@ public class MessageGenerator {
 		packet.setFrom(conversation.getAccount().getJid());
 		return packet;
 	}
+	
+	public MessagePacket invite(Conversation conversation, String contact) {
+		MessagePacket packet = new MessagePacket();
+		packet.setType(MessagePacket.TYPE_NORMAL);
+		packet.setTo(contact);
+		packet.setFrom(conversation.getAccount().getFullJid());
+		Element x = packet.addChild("x", "jabber:x:conference");
+		x.setAttribute("jid", conversation.getContactJid().split("/")[0]);
+		return packet;
+	}
 }

src/eu/siacs/conversations/parser/MessageParser.java 🔗

@@ -221,8 +221,8 @@ public class MessageParser extends AbstractParser implements
 			updateLastseen(packet, account, false);
 			mXmppConnectionService.markMessage(account, fromParts[0], id,
 					Message.STATUS_SEND_RECEIVED);
-		} else if (packet.hasChild("x")) {
-			Element x = packet.findChild("x");
+		} else if (packet.hasChild("x","http://jabber.org/protocol/muc#user")) {
+			Element x = packet.findChild("x","http://jabber.org/protocol/muc#user");
 			if (x.hasChild("invite")) {
 				Conversation conversation = mXmppConnectionService
 						.findOrCreateConversation(account,
@@ -233,6 +233,17 @@ public class MessageParser extends AbstractParser implements
 				}	
 			}
 
+		} else if (packet.hasChild("x", "jabber:x:conference")) {
+			Element x = packet.findChild("x", "jabber:x:conference");
+			String jid = x.getAttribute("jid");
+			if (jid!=null) {
+				Conversation conversation = mXmppConnectionService
+						.findOrCreateConversation(account,jid, true);
+				if (!conversation.getMucOptions().online()) {
+					mXmppConnectionService.joinMuc(conversation);
+					mXmppConnectionService.updateConversationUi();
+				}
+			}
 		}
 	}
 

src/eu/siacs/conversations/services/XmppConnectionService.java 🔗

@@ -1223,19 +1223,9 @@ public class XmppConnectionService extends Service {
 		}).start();
 	}
 
-	public void inviteToConference(Conversation conversation, String contactJid) {
-		Account account = conversation.getAccount();
-		MessagePacket packet = new MessagePacket();
-		packet.setTo(conversation.getContactJid().split("/")[0]);
-		packet.setFrom(account.getFullJid());
-		Element x = new Element("x");
-		x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user");
-		Element invite = new Element("invite");
-		invite.setAttribute("to", contactJid);
-		x.addChild(invite);
-		packet.addChild(x);
-		sendMessagePacket(account,packet);
-		Log.d(LOGTAG,packet.toString());
+	public void invite(Conversation conversation, String contact) {
+		MessagePacket packet = mMessageGenerator.invite(conversation, contact);
+		sendMessagePacket(conversation.getAccount(),packet);
 	}
 
 	public boolean markMessage(Account account, String recipient, String uuid,

src/eu/siacs/conversations/ui/XmppActivity.java 🔗

@@ -349,7 +349,7 @@ public abstract class XmppActivity extends Activity {
 			String conversationUuid = data.getStringExtra("conversation");
 			Conversation conversation = xmppConnectionService.findConversationByUuid(conversationUuid);
 			if (conversation.getMode() == Conversation.MODE_MULTI) {
-				xmppConnectionService.inviteToConference(conversation, contactJid);
+				xmppConnectionService.invite(conversation, contactJid);
 			}
 			Log.d("xmppService","inviting "+contactJid+" to "+conversation.getName(true));
 		}