From 24afb2e086b62719fec45a5eeb04a7ba24918220 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Thu, 9 Feb 2012 20:22:04 +0000
Subject: Fixes for mediated invites


diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index f8f30ff..db71397 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -273,10 +273,7 @@ void ChatControllerBase::handleMUCInvitation(Message::ref message) {
 
 void ChatControllerBase::handleMediatedMUCInvitation(Message::ref message) {
 	MUCUserPayload::Invite invite = *message->getPayload<MUCUserPayload>()->getInvite();
-	JID from;
-	if (invite.from.isValid()) {
-		from = invite.from;
-	}
+	JID from = message->getFrom();
 	std::string reason;
 	if (!invite.reason.empty()) {
 		reason = invite.reason;
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index ff00bc1..c19c524 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -575,13 +575,17 @@ void ChatsManager::handleSearchMUCRequest() {
 void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) {
 	JID jid = message->getFrom();
 	boost::shared_ptr<MessageEvent> event(new MessageEvent(message));
-	bool isInvite = message->getPayload<MUCInvitationPayload>() || (message->getPayload<MUCUserPayload>() && message->getPayload<MUCUserPayload>()->getInvite());
-	if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !message->hasSubject()) {
+	bool isInvite = message->getPayload<MUCInvitationPayload>();
+	bool isMediatedInvite = (message->getPayload<MUCUserPayload>() && message->getPayload<MUCUserPayload>()->getInvite());
+	if (isMediatedInvite) {
+		jid = (*message->getPayload<MUCUserPayload>()->getInvite()).from;
+	}
+	if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !isMediatedInvite && !message->hasSubject()) {
 		return;
 	}
 
 	// Try to deliver it to a MUC
-	if (message->getType() == Message::Groupchat || message->getType() == Message::Error || (isInvite && message->getType() == Message::Normal)) {
+	if (message->getType() == Message::Groupchat || message->getType() == Message::Error /*|| (isInvite && message->getType() == Message::Normal)*/) {
 		std::map<JID, MUCController*>::iterator i = mucControllers_.find(jid.toBare());
 		if (i != mucControllers_.end()) {
 			i->second->handleIncomingMessage(event);
-- 
cgit v0.10.2-6-g49f6