summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/ChatController.cpp')
-rw-r--r--Swift/Controllers/ChatController.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/Swift/Controllers/ChatController.cpp b/Swift/Controllers/ChatController.cpp
new file mode 100644
index 0000000..8c0b8bb
--- /dev/null
+++ b/Swift/Controllers/ChatController.cpp
@@ -0,0 +1,38 @@
+#include "Swift/Controllers/ChatController.h"
+
+#include "Swift/Controllers/ChatWindow.h"
+#include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swift/Controllers/NickResolver.h"
+
+namespace Swift {
+
+/**
+ * The controller does not gain ownership of the stanzaChannel, nor the factory.
+ */
+ChatController::ChatController(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle)
+ : ChatControllerBase(stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle) {
+ nickResolver_ = nickResolver;
+}
+
+bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) {
+ return false;
+}
+
+void ChatController::preHandleIncomingMessage(boost::shared_ptr<Message> message) {
+ JID from = message->getFrom();
+ if (!from.equals(toJID_, JID::WithResource)) {
+ if (toJID_.equals(from, JID::WithoutResource) && toJID_.isBare()){
+ toJID_ = from;
+ }
+ }
+}
+
+void ChatController::postSendMessage(const String& body) {
+ chatWindow_->addMessage(body, "me", true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel() : boost::optional<SecurityLabel>());
+}
+
+String ChatController::senderDisplayNameFromMessage(JID from) {
+ return nickResolver_->jidToNick(from);
+}
+
+}