summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/ChatController.cpp32
-rw-r--r--Swift/Controllers/ChatController.h6
-rw-r--r--Swift/Controllers/ChatControllerBase.cpp29
-rw-r--r--Swift/Controllers/ChatControllerBase.h3
4 files changed, 36 insertions, 34 deletions
diff --git a/Swift/Controllers/ChatController.cpp b/Swift/Controllers/ChatController.cpp
index a8b8ab1..32fc0c2 100644
--- a/Swift/Controllers/ChatController.cpp
+++ b/Swift/Controllers/ChatController.cpp
@@ -1,5 +1,7 @@
#include "Swift/Controllers/ChatController.h"
+#include <boost/bind.hpp>
+
#include "Swiften/Avatars/AvatarManager.h"
#include "Swift/Controllers/ChatWindow.h"
#include "Swift/Controllers/ChatWindowFactory.h"
@@ -13,6 +15,7 @@ namespace Swift {
ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager)
: ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager) {
nickResolver_ = nickResolver;
+ presenceOracle_->onPresenceChange.connect(boost::bind(&ChatController::handlePresenceChange, this, _1, _2));
}
bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) {
@@ -36,4 +39,33 @@ String ChatController::senderDisplayNameFromMessage(const JID& from) {
return nickResolver_->jidToNick(from);
}
+String ChatController::getStatusChangeString(boost::shared_ptr<Presence> presence) {
+ String nick = senderDisplayNameFromMessage(presence->getFrom());
+ if (presence->getType() == Presence::Unavailable) {
+ return nick + " has gone offline.";
+ } else if (presence->getType() == Presence::Available) {
+ StatusShow::Type show = presence->getShow();
+ if (show == StatusShow::Online || show == StatusShow::FFC) {
+ return nick + " has become available.";
+ } else if (show == StatusShow::Away || show == StatusShow::XA) {
+ return nick + " has gone away.";
+ } else if (show == StatusShow::DND) {
+ return nick + " is now busy.";
+ }
+ }
+
+ return "";
+}
+
+void ChatController::handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> previousPresence) {
+ if (!(toJID_.isBare() && newPresence->getFrom().equals(toJID_, JID::WithoutResource)) && newPresence->getFrom() != toJID_) {
+ return;
+ }
+ String newStatusChangeString = getStatusChangeString(newPresence);
+ if (!previousPresence || newStatusChangeString != getStatusChangeString(previousPresence)) {
+ chatWindow_->addSystemMessage(newStatusChangeString);
+ }
+}
+
+
}
diff --git a/Swift/Controllers/ChatController.h b/Swift/Controllers/ChatController.h
index ea870b7..2103d25 100644
--- a/Swift/Controllers/ChatController.h
+++ b/Swift/Controllers/ChatController.h
@@ -10,9 +10,9 @@ namespace Swift {
public:
ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager*);
- //boost::signal<void (const JID&, const JID&)> onJIDChanged;
-
- protected:
+ private:
+ void handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> previousPresence);
+ String getStatusChangeString(boost::shared_ptr<Presence> presence);
bool isIncomingMessageFromMe(boost::shared_ptr<Message> message);
void postSendMessage(const String &body);
void preHandleIncomingMessage(boost::shared_ptr<Message> message);
diff --git a/Swift/Controllers/ChatControllerBase.cpp b/Swift/Controllers/ChatControllerBase.cpp
index cab2361..1780680 100644
--- a/Swift/Controllers/ChatControllerBase.cpp
+++ b/Swift/Controllers/ChatControllerBase.cpp
@@ -16,7 +16,6 @@ ChatControllerBase::ChatControllerBase(const JID& self, StanzaChannel* stanzaCha
chatWindow_ = chatWindowFactory_->createChatWindow(toJID);
chatWindow_->onAllMessagesRead.connect(boost::bind(&ChatControllerBase::handleAllMessagesRead, this));
chatWindow_->onSendMessageRequest.connect(boost::bind(&ChatControllerBase::handleSendMessageRequest, this, _1));
- presenceOracle_->onPresenceChange.connect(boost::bind(&ChatControllerBase::handlePresenceChange, this, _1, _2));
}
ChatControllerBase::~ChatControllerBase() {
@@ -37,34 +36,6 @@ void ChatControllerBase::setAvailableServerFeatures(boost::shared_ptr<DiscoInfo>
}
}
-String ChatControllerBase::getStatusChangeString(boost::shared_ptr<Presence> presence) {
- String nick = senderDisplayNameFromMessage(presence->getFrom());
- if (presence->getType() == Presence::Unavailable) {
- return nick + " has gone offline.";
- } else if (presence->getType() == Presence::Available) {
- StatusShow::Type show = presence->getShow();
- if (show == StatusShow::Online || show == StatusShow::FFC) {
- return nick + " has become available.";
- } else if (show == StatusShow::Away || show == StatusShow::XA) {
- return nick + " has gone away.";
- } else if (show == StatusShow::DND) {
- return nick + " is now busy.";
- }
- }
-
- return "";
-}
-
-void ChatControllerBase::handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> previousPresence) {
- if (!(toJID_.isBare() && newPresence->getFrom().equals(toJID_, JID::WithoutResource)) && newPresence->getFrom() != toJID_) {
- return;
- }
- String newStatusChangeString = getStatusChangeString(newPresence);
- if (previousPresence.get() == NULL || newStatusChangeString != getStatusChangeString(previousPresence)) {
- chatWindow_->addSystemMessage(newStatusChangeString);
- }
-}
-
void ChatControllerBase::handleAllMessagesRead() {
foreach (boost::shared_ptr<MessageEvent> messageEvent, unreadMessages_) {
messageEvent->read();
diff --git a/Swift/Controllers/ChatControllerBase.h b/Swift/Controllers/ChatControllerBase.h
index b849c2b..144572b 100644
--- a/Swift/Controllers/ChatControllerBase.h
+++ b/Swift/Controllers/ChatControllerBase.h
@@ -34,14 +34,13 @@ namespace Swift {
virtual void postSendMessage(const String&) {};
virtual String senderDisplayNameFromMessage(const JID& from) = 0;
- void handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> previousPresence);
virtual bool isIncomingMessageFromMe(boost::shared_ptr<Message>) = 0;
virtual void preHandleIncomingMessage(boost::shared_ptr<Message>) {};
virtual void preSendMessageRequest(boost::shared_ptr<Message>) {};
+
private:
void handleSendMessageRequest(const String &body);
- String getStatusChangeString(boost::shared_ptr<Presence> presence);
void handleAllMessagesRead();
void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, const boost::optional<Error>& error);
String getErrorMessage(boost::shared_ptr<Error>);