From 38862a78d119d4ac8cd8495436e75d00f3ee896e Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 9 Dec 2012 12:05:27 +0000 Subject: [PATCH] New Conversation notifications --- src/client/Client.cpp | 42 +++++++++++++++++++++++++++++++++++++ src/client/Client.h | 5 +++++ src/client/ClientListener.h | 1 + src/game/GameController.cpp | 17 +++++++++++++++ src/game/GameController.h | 1 + 5 files changed, 66 insertions(+) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index e446f738a..525de7768 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -545,6 +545,17 @@ std::string Client::GetMessageOfTheDay() return messageOfTheDay; } +void Client::AddServerNotification(std::pair notification) +{ + serverNotifications.push_back(notification); + notifyNewNotification(notification); +} + +std::vector > Client::GetServerNotifications() +{ + return serverNotifications; +} + void Client::Tick() { //Check thumbnail queue @@ -579,6 +590,18 @@ void Client::Tick() SetAuthUser(User(0, "")); } + //Notifications from server + json::Array notificationsArray = objDocument["Notifications"]; + for(int j = 0; j < notificationsArray.Size(); j++) + { + json::String notificationLink = notificationsArray[j]["Link"]; + json::String notificationText = notificationsArray[j]["Text"]; + + std::pair item = std::pair(notificationText.Value(), notificationLink.Value()); + AddServerNotification(item); + } + + //MOTD json::String messageOfTheDay = objDocument["MessageOfTheDay"]; this->messageOfTheDay = messageOfTheDay.Value(); @@ -673,6 +696,14 @@ void Client::notifyAuthUserChanged() } } +void Client::notifyNewNotification(std::pair notification) +{ + for (std::vector::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator) + { + (*iterator)->NotifyNewNotification(this, notification); + } +} + void Client::AddListener(ClientListener * listener) { listeners.push_back(listener); @@ -1090,6 +1121,17 @@ LoginStatus Client::Login(std::string username, std::string password, User & use json::String sessionIDTemp = objDocument["SessionID"]; json::String sessionKeyTemp = objDocument["SessionKey"]; json::String userElevationTemp = objDocument["Elevation"]; + + json::Array notificationsArray = objDocument["Notifications"]; + for(int j = 0; j < notificationsArray.Size(); j++) + { + json::String notificationLink = notificationsArray[j]["Link"]; + json::String notificationText = notificationsArray[j]["Text"]; + + std::pair item = std::pair(notificationText.Value(), notificationLink.Value()); + AddServerNotification(item); + } + user.Username = username; user.ID = userIDTemp.Value(); user.SessionID = sessionIDTemp.Value(); diff --git a/src/client/Client.h b/src/client/Client.h index 642fd63d7..bd332739d 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -46,6 +46,7 @@ class ClientListener; class Client: public Singleton { private: std::string messageOfTheDay; + std::vector > serverNotifications; void * versionCheckRequest; bool updateAvailable; @@ -73,6 +74,7 @@ private: void notifyUpdateAvailable(); void notifyAuthUserChanged(); void notifyMessageOfTheDay(); + void notifyNewNotification(std::pair notification); //Config file handle json::Object configDocument; @@ -92,6 +94,9 @@ public: std::vector ReadFile(std::string filename); + void AddServerNotification(std::pair notification); + std::vector > GetServerNotifications(); + void SetMessageOfTheDay(std::string message); std::string GetMessageOfTheDay(); diff --git a/src/client/ClientListener.h b/src/client/ClientListener.h index 07e784c92..68721b150 100644 --- a/src/client/ClientListener.h +++ b/src/client/ClientListener.h @@ -18,6 +18,7 @@ public: virtual void NotifyUpdateAvailable(Client * sender) {} virtual void NotifyAuthUserChanged(Client * sender) {} virtual void NotifyMessageOfTheDay(Client * sender) {} + virtual void NotifyNewNotification(Client * sender, std::pair notification) {} }; diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 154d99b8d..188a233b5 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -1257,6 +1257,23 @@ void GameController::NotifyAuthUserChanged(Client * sender) gameModel->SetUser(newUser); } +void GameController::NotifyNewNotification(Client * sender, std::pair notification) +{ + class LinkNotification : public Notification + { + std::string link; + public: + LinkNotification(std::string link_, std::string message) : link(link_), Notification(message) {} + virtual ~LinkNotification() {} + + virtual void Action() + { + OpenURI(link); + } + }; + gameModel->AddNotification(new LinkNotification(notification.second, notification.first)); +} + void GameController::NotifyUpdateAvailable(Client * sender) { class UpdateConfirmation: public ConfirmDialogueCallback { diff --git a/src/game/GameController.h b/src/game/GameController.h index 984cfd6db..d44a2952d 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -142,6 +142,7 @@ public: virtual void NotifyUpdateAvailable(Client * sender); virtual void NotifyAuthUserChanged(Client * sender); + virtual void NotifyNewNotification(Client * sender, std::pair notification); void RunUpdater(); };