diff options
Diffstat (limited to 'Swift/Controllers/Chat')
| -rw-r--r-- | Swift/Controllers/Chat/ChatController.cpp | 6 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 17 |
2 files changed, 20 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 8c132d0..bedc427 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -169,19 +169,23 @@ bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) { void ChatController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) { if (messageEvent->isReadable()) { chatWindow_->flash(); lastWasPresence_ = false; } boost::shared_ptr<Message> message = messageEvent->getStanza(); JID from = message->getFrom(); if (!from.equals(toJID_, JID::WithResource)) { if (toJID_.equals(from, JID::WithoutResource) && toJID_.isBare()){ - setToJID(from); + // Bind controller to a full JID if message contains body text or is a typing chat state. + ChatState::ref chatState = message->getPayload<ChatState>(); + if (!message->getBody().empty() || (chatState && chatState->getChatState() == ChatState::Composing)) { + setToJID(from); + } } } chatStateTracker_->handleMessageReceived(message); chatStateNotifier_->receivedMessageFromContact(!!message->getPayload<ChatState>()); // handle XEP-0184 Message Receipts // incomming receipts if (boost::shared_ptr<DeliveryReceipt> receipt = message->getPayload<DeliveryReceipt>()) { SWIFT_LOG(debug) << "received receipt for id: " << receipt->getReceivedID() << std::endl; diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index e11d14b..343f490 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -744,19 +744,24 @@ ChatController* ChatsManager::getChatControllerOrCreate(const JID &contact) { ChatController* ChatsManager::getChatControllerIfExists(const JID &contact, bool rebindIfNeeded) { if (chatControllers_.find(contact) == chatControllers_.end()) { if (mucRegistry_->isMUC(contact.toBare())) { return NULL; } //Need to look for an unbound window to bind first JID bare(contact.toBare()); if (chatControllers_.find(bare) != chatControllers_.end()) { - rebindControllerJID(bare, contact); + if (rebindIfNeeded) { + rebindControllerJID(bare, contact); + } + else { + return chatControllers_[bare]; + } } else { foreach (JIDChatControllerPair pair, chatControllers_) { if (pair.first.toBare() == contact.toBare()) { if (rebindIfNeeded) { rebindControllerJID(pair.first, contact); return chatControllers_[contact]; } else { return pair.second; } @@ -903,19 +908,27 @@ void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) { } else { handleJoinMUCRequest(invite->getJID(), boost::optional<std::string>(), boost::optional<std::string>(), false, false, true); return; } } //if not a mucroom if (!event->isReadable() && !isInvite && !isMediatedInvite) { /* Only route such messages if a window exists, don't open new windows for them.*/ - ChatController* controller = getChatControllerIfExists(jid); + + // Do not bind a controller to a full JID, for delivery receipts or chat state notifications. + bool bindControllerToJID = false; + ChatState::ref chatState = message->getPayload<ChatState>(); + if (!message->getBody().empty() || (chatState && chatState->getChatState() == ChatState::Composing)) { + bindControllerToJID = true; + } + + ChatController* controller = getChatControllerIfExists(jid, bindControllerToJID); if (controller) { controller->handleIncomingMessage(event); } } else { getChatControllerOrCreate(jid)->handleIncomingMessage(event); } } void ChatsManager::handleMUCSelectedAfterSearch(const JID& muc) { |
Swift