diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatController.cpp | 60 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatController.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 8 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/ChatWindow.h | 2 |
4 files changed, 32 insertions, 45 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 306ee9e..8c132d0 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -3,49 +3,51 @@ * All rights reserved. * See the COPYING file for more information. */ #include <Swift/Controllers/Chat/ChatController.h> +#include <stdio.h> + #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> -#include <stdio.h> #include <Swiften/Avatars/AvatarManager.h> #include <Swiften/Base/Algorithm.h> #include <Swiften/Base/DateTime.h> +#include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> #include <Swiften/Base/format.h> -#include <Swiften/Base/Log.h> #include <Swiften/Chat/ChatStateNotifier.h> #include <Swiften/Chat/ChatStateTracker.h> #include <Swiften/Client/ClientBlockListManager.h> #include <Swiften/Client/NickResolver.h> #include <Swiften/Client/StanzaChannel.h> #include <Swiften/Disco/EntityCapsProvider.h> +#include <Swiften/Disco/FeatureOracle.h> #include <Swiften/Elements/DeliveryReceipt.h> #include <Swiften/Elements/DeliveryReceiptRequest.h> #include <Swiften/Elements/Idle.h> #include <Swiften/FileTransfer/FileTransferManager.h> -#include <Swift/Controllers/Intl.h> -#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h> -#include <Swift/Controllers/XMPPEvents/EventController.h> +#include <Swift/Controllers/Chat/ChatMessageParser.h> #include <Swift/Controllers/FileTransfer/FileTransferController.h> +#include <Swift/Controllers/Highlighter.h> +#include <Swift/Controllers/Intl.h> +#include <Swift/Controllers/SettingConstants.h> #include <Swift/Controllers/StatusUtil.h> -#include <Swift/Controllers/UIEvents/UIEventStream.h> -#include <Swift/Controllers/UIEvents/SendFileUIEvent.h> #include <Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h> #include <Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h> -#include <Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h> -#include <Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h> #include <Swift/Controllers/UIEvents/InviteToMUCUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h> #include <Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h> -#include <Swift/Controllers/SettingConstants.h> -#include <Swift/Controllers/Highlighter.h> -#include <Swift/Controllers/Chat/ChatMessageParser.h> +#include <Swift/Controllers/UIEvents/SendFileUIEvent.h> +#include <Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h> +#include <Swift/Controllers/XMPPEvents/EventController.h> namespace Swift { /** * The controller does not gain ownership of the stanzaChannel, nor the factory. */ @@ -122,34 +124,18 @@ JID ChatController::getBaseJID() { void ChatController::cancelReplaces() { lastWasPresence_ = false; } void ChatController::handleBareJIDCapsChanged(const JID& /*jid*/) { - DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_); - if (disco) { - if (disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) { - chatWindow_->setCorrectionEnabled(ChatWindow::Yes); - } else { - chatWindow_->setCorrectionEnabled(ChatWindow::No); - } - if (disco->hasFeature(DiscoInfo::MessageDeliveryReceiptsFeature)) { - contactSupportsReceipts_ = ChatWindow::Yes; - } else { - contactSupportsReceipts_ = ChatWindow::No; - } - if (FileTransferManager::isSupportedBy(disco)) { - chatWindow_->setFileTransferEnabled(ChatWindow::Yes); - } else { - chatWindow_->setFileTransferEnabled(ChatWindow::No); - } - } else { - SWIFT_LOG(debug) << "No disco info :(" << std::endl; - chatWindow_->setCorrectionEnabled(ChatWindow::Maybe); - contactSupportsReceipts_ = ChatWindow::Maybe; - } + FeatureOracle featureOracle(entityCapsProvider_, presenceOracle_); + + chatWindow_->setCorrectionEnabled(featureOracle.isMessageCorrectionSupported(toJID_)); + chatWindow_->setFileTransferEnabled(featureOracle.isFileTransferSupported(toJID_)); + contactSupportsReceipts_ = featureOracle.isMessageReceiptsSupported(toJID_); + checkForDisplayingDisplayReceiptsAlert(); } void ChatController::setToJID(const JID& jid) { chatStateNotifier_->setContact(jid); ChatControllerBase::setToJID(jid); @@ -227,13 +213,13 @@ void ChatController::postHandleIncomingMessage(boost::shared_ptr<MessageEvent> m } } void ChatController::preSendMessageRequest(boost::shared_ptr<Message> message) { chatStateNotifier_->addChatStateRequest(message); - if (userWantsReceipts_ && (contactSupportsReceipts_ != ChatWindow::No) && message) { + if (userWantsReceipts_ && (contactSupportsReceipts_ != No) && message) { message->addPayload(boost::make_shared<DeliveryReceiptRequest>()); } } void ChatController::setContactIsReceivingPresence(bool isReceivingPresence) { receivingPresenceFromUs_ = isReceivingPresence; @@ -245,15 +231,15 @@ void ChatController::handleSettingChanged(const std::string& settingPath) { checkForDisplayingDisplayReceiptsAlert(); } } void ChatController::checkForDisplayingDisplayReceiptsAlert() { boost::optional<ChatWindow::AlertID> newDeliverReceiptAlert; - if (userWantsReceipts_ && (contactSupportsReceipts_ == ChatWindow::No)) { + if (userWantsReceipts_ && (contactSupportsReceipts_ == No)) { newDeliverReceiptAlert = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat doesn't support delivery receipts.")); - } else if (userWantsReceipts_ && (contactSupportsReceipts_ == ChatWindow::Maybe)) { + } else if (userWantsReceipts_ && (contactSupportsReceipts_ == Maybe)) { newDeliverReceiptAlert = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat may not support delivery receipts. You might not receive delivery receipts for the messages you send.")); } else { if (deliveryReceiptAlert_) { chatWindow_->removeAlert(*deliveryReceiptAlert_); deliveryReceiptAlert_.reset(); } diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h index 317a836..a1f40be 100644 --- a/Swift/Controllers/Chat/ChatController.h +++ b/Swift/Controllers/Chat/ChatController.h @@ -3,17 +3,18 @@ * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <Swift/Controllers/Chat/ChatControllerBase.h> - #include <map> #include <string> +#include <Swiften/Base/Tristate.h> + +#include <Swift/Controllers/Chat/ChatControllerBase.h> #include <Swift/Controllers/UIInterfaces/ChatWindow.h> namespace Swift { class AvatarManager; class ChatStateNotifier; class ChatStateTracker; @@ -92,13 +93,13 @@ namespace Swift { std::string lastStatusChangeString_; std::map<boost::shared_ptr<Stanza>, std::string> unackedStanzas_; std::map<std::string, std::string> requestedReceipts_; StatusShow::Type lastShownStatus_; UIEventStream* eventStream_; - ChatWindow::Tristate contactSupportsReceipts_; + Tristate contactSupportsReceipts_; bool receivingPresenceFromUs_; bool userWantsReceipts_; std::map<std::string, FileTransferController*> ftControllers; SettingsProvider* settings_; std::string lastWbID_; diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 054f896..6794846 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -12,14 +12,14 @@ #include <boost/regex.hpp> #include <boost/algorithm/string.hpp> #include <Swiften/Avatars/AvatarManager.h> #include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Base/format.h> +#include <Swiften/Base/Tristate.h> #include <Swiften/Client/BlockList.h> #include <Swiften/Client/ClientBlockListManager.h> #include <Swiften/Client/StanzaChannel.h> #include <Swiften/Disco/EntityCapsProvider.h> #include <Swiften/Elements/Delay.h> #include <Swiften/MUC/MUC.h> @@ -227,24 +227,24 @@ void MUCController::handleActionRequestedOnOccupant(ChatWindow::OccupantAction a case ChatWindow::AddContact: if (occupant.getRealJID()) events_->send(boost::make_shared<RequestAddUserDialogUIEvent>(realJID, occupant.getNick()));break; case ChatWindow::ShowProfile: events_->send(boost::make_shared<ShowProfileForRosterItemUIEvent>(mucJID));break; } } void MUCController::handleBareJIDCapsChanged(const JID& /*jid*/) { - ChatWindow::Tristate support = ChatWindow::Yes; + Tristate support = Yes; bool any = false; foreach (const std::string& nick, currentOccupants_) { DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_.toBare().toString() + "/" + nick); if (disco && disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) { any = true; } else { - support = ChatWindow::Maybe; + support = Maybe; } } if (!any) { - support = ChatWindow::No; + support = No; } chatWindow_->setCorrectionEnabled(support); } /** * Join the MUC if not already in it. diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h index 765f16a..b1e2a11 100644 --- a/Swift/Controllers/UIInterfaces/ChatWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatWindow.h @@ -11,12 +11,13 @@ #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/make_shared.hpp> #include <boost/optional.hpp> #include <boost/shared_ptr.hpp> +#include <Swiften/Base/Tristate.h> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Elements/ChatState.h> #include <Swiften/Elements/Form.h> #include <Swiften/Elements/MUCOccupant.h> #include <Swiften/Elements/SecurityLabelsCatalog.h> #include <Swiften/MUC/MUCBookmark.h> @@ -83,13 +84,12 @@ namespace Swift { std::string text; }; enum AckState {Pending, Received, Failed}; enum ReceiptState {ReceiptRequested, ReceiptReceived, ReceiptFailed}; - enum Tristate {Yes, No, Maybe}; enum OccupantAction {Kick, Ban, MakeModerator, MakeParticipant, MakeVisitor, AddContact, ShowProfile}; enum RoomAction {ChangeSubject, Configure, Affiliations, Destroy, Invite}; enum FileTransferState {WaitingForAccept, Negotiating, Transferring, Canceled, Finished, FTFailed}; enum WhiteboardSessionState {WhiteboardAccepted, WhiteboardTerminated, WhiteboardRejected}; enum BlockingState {BlockingUnsupported, IsBlocked, IsUnblocked}; enum Direction { UnknownDirection, DefaultDirection }; |