diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.cpp | 22 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/EventNotifier.cpp | 7 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/ChatWindow.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/MockChatWindow.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/EventController.cpp | 4 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/MUCInviteEvent.h | 31 |
7 files changed, 64 insertions, 8 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp index f590ffd..8523591 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.cpp +++ b/Swift/Controllers/Chat/ChatControllerBase.cpp @@ -29,6 +29,7 @@ #include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h> #include <Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h> #include <Swiften/Avatars/AvatarManager.h> +#include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h> namespace Swift { @@ -91,8 +92,8 @@ void ChatControllerBase::setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> void ChatControllerBase::handleAllMessagesRead() { if (!unreadMessages_.empty()) { - foreach (boost::shared_ptr<MessageEvent> messageEvent, unreadMessages_) { - messageEvent->read(); + foreach (boost::shared_ptr<StanzaEvent> stanzaEvent, unreadMessages_) { + stanzaEvent->conclude(); } unreadMessages_.clear(); chatWindow_->setUnreadMessageCount(0); @@ -267,9 +268,20 @@ std::string ChatControllerBase::getErrorMessage(boost::shared_ptr<ErrorPayload> return defaultMessage; } +void ChatControllerBase::handleGeneralMUCInvitation(MUCInviteEvent::ref event) { + unreadMessages_.push_back(event); + chatWindow_->show(); + chatWindow_->setUnreadMessageCount(unreadMessages_.size()); + onUnreadCountChanged(); + chatWindow_->addMUCInvitation(senderDisplayNameFromMessage(event->getInviter()), event->getRoomJID(), event->getReason(), event->getPassword(), event->getDirect()); + eventController_->handleIncomingEvent(event); +} + void ChatControllerBase::handleMUCInvitation(Message::ref message) { MUCInvitationPayload::ref invite = message->getPayload<MUCInvitationPayload>(); - chatWindow_->addMUCInvitation(invite->getJID(), invite->getReason(), invite->getPassword()); + + MUCInviteEvent::ref inviteEvent = boost::make_shared<MUCInviteEvent>(toJID_, invite->getJID(), invite->getReason(), invite->getPassword(), true); + handleGeneralMUCInvitation(inviteEvent); } void ChatControllerBase::handleMediatedMUCInvitation(Message::ref message) { @@ -283,7 +295,9 @@ void ChatControllerBase::handleMediatedMUCInvitation(Message::ref message) { if (message->getPayload<MUCUserPayload>()->getPassword()) { password = *message->getPayload<MUCUserPayload>()->getPassword(); } - chatWindow_->addMUCInvitation(from, reason, password, false); + + MUCInviteEvent::ref inviteEvent = boost::make_shared<MUCInviteEvent>(invite.from, from, reason, password, false); + handleGeneralMUCInvitation(inviteEvent); } diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h index e1034d6..a4d23c0 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.h +++ b/Swift/Controllers/Chat/ChatControllerBase.h @@ -20,6 +20,7 @@ #include <string> #include "Swiften/Elements/DiscoInfo.h" #include "Swift/Controllers/XMPPEvents/MessageEvent.h" +#include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h> #include "Swiften/JID/JID.h" #include "Swiften/Elements/SecurityLabelsCatalog.h" #include "Swiften/Elements/ErrorPayload.h" @@ -84,10 +85,11 @@ namespace Swift { void handleDayChangeTick(); void handleMUCInvitation(Message::ref message); void handleMediatedMUCInvitation(Message::ref message); + void handleGeneralMUCInvitation(MUCInviteEvent::ref event); protected: JID selfJID_; - std::vector<boost::shared_ptr<MessageEvent> > unreadMessages_; + std::vector<boost::shared_ptr<StanzaEvent> > unreadMessages_; StanzaChannel* stanzaChannel_; IQRouter* iqRouter_; ChatWindowFactory* chatWindowFactory_; diff --git a/Swift/Controllers/EventNotifier.cpp b/Swift/Controllers/EventNotifier.cpp index e643ab3..a4edabf 100644 --- a/Swift/Controllers/EventNotifier.cpp +++ b/Swift/Controllers/EventNotifier.cpp @@ -18,6 +18,7 @@ #include "Swift/Controllers/XMPPEvents/MessageEvent.h" #include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" #include "Swift/Controllers/XMPPEvents/ErrorEvent.h" +#include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h" #include "Swift/Controllers/Settings/SettingsProvider.h" namespace Swift { @@ -55,6 +56,12 @@ void EventNotifier::handleEventAdded(boost::shared_ptr<StanzaEvent> event) { else if(boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event)) { notifier->showMessage(Notifier::SystemMessage, QT_TRANSLATE_NOOP("", "Error"), errorEvent->getText(), boost::filesystem::path(), boost::function<void()>()); } + else if (boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event)) { + std::string title = mucInviteEvent->getInviter(); + std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% has invited you to enter the %2% room")) % nickResolver->jidToNick(mucInviteEvent->getInviter()) % mucInviteEvent->getRoomJID()); + // FIXME: not show avatar or greyed out avatar for mediated invites + notifier->showMessage(Notifier::SystemMessage, title, message, avatarManager->getAvatarPath(mucInviteEvent->getInviter()), boost::bind(&EventNotifier::handleNotificationActivated, this, mucInviteEvent->getInviter())); + } } diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h index e7246c6..9305314 100644 --- a/Swift/Controllers/UIInterfaces/ChatWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatWindow.h @@ -57,7 +57,7 @@ namespace Swift { virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) = 0; virtual void setFileTransferProgress(std::string, const int percentageDone) = 0; virtual void setFileTransferStatus(std::string, const FileTransferState state, const std::string& msg = "") = 0; - virtual void addMUCInvitation(const JID& jid, const std::string& reason, const std::string& password, bool direct = true) = 0; + virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct = true) = 0; // message receipts virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) = 0; diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h index dab1e90..f92bd8b 100644 --- a/Swift/Controllers/UnitTest/MockChatWindow.h +++ b/Swift/Controllers/UnitTest/MockChatWindow.h @@ -50,7 +50,7 @@ namespace Swift { void setAvailableOccupantActions(const std::vector<OccupantAction>&/* actions*/) {} void setSubject(const std::string& /*subject*/) {} virtual void showRoomConfigurationForm(Form::ref) {} - virtual void addMUCInvitation(const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool = true) {}; + virtual void addMUCInvitation(const std::string& /*senderName*/, const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool = true) {}; virtual void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&) {} virtual void setAvailableRoomActions(const std::vector<RoomAction> &) {}; diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp index 98fd634..0808aa0 100644 --- a/Swift/Controllers/XMPPEvents/EventController.cpp +++ b/Swift/Controllers/XMPPEvents/EventController.cpp @@ -13,6 +13,7 @@ #include "Swift/Controllers/XMPPEvents/MessageEvent.h" #include "Swift/Controllers/XMPPEvents/ErrorEvent.h" #include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" +#include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h" namespace Swift { @@ -29,7 +30,8 @@ void EventController::handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceE boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(sourceEvent); boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent); boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(sourceEvent); - if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent) { + boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent); + if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent) { events_.push_back(sourceEvent); sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent)); onEventQueueLengthChange(events_.size()); diff --git a/Swift/Controllers/XMPPEvents/MUCInviteEvent.h b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h new file mode 100644 index 0000000..0b430cd --- /dev/null +++ b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +namespace Swift { + + class MUCInviteEvent : public StanzaEvent { + public: + typedef boost::shared_ptr<MUCInviteEvent> ref; + + public: + MUCInviteEvent(const JID& inviter, const JID& roomJID, const std::string& reason, const std::string& password, bool direct) : inviter_(inviter), roomJID_(roomJID), reason_(reason), password_(password), direct_(direct) {} + + const JID& getInviter() const { return inviter_; } + const JID& getRoomJID() const { return roomJID_; } + const std::string& getReason() const { return reason_; } + const std::string& getPassword() const { return password_; } + bool getDirect() const { return direct_; } + + private: + JID inviter_; + JID roomJID_; + std::string reason_; + std::string password_; + bool direct_; + }; +} |