diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-12-09 12:05:27 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-12-09 12:05:27 (GMT) |
| commit | 38862a78d119d4ac8cd8495436e75d00f3ee896e (patch) | |
| tree | ea1e21878adde1bda829454049c73e92f1cab513 /src/client | |
| parent | 6478ed121ce17cf7d7beaab2deb1953da63d283d (diff) | |
| download | powder-38862a78d119d4ac8cd8495436e75d00f3ee896e.zip powder-38862a78d119d4ac8cd8495436e75d00f3ee896e.tar.gz | |
New Conversation notifications
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Client.cpp | 42 | ||||
| -rw-r--r-- | src/client/Client.h | 5 | ||||
| -rw-r--r-- | src/client/ClientListener.h | 1 |
3 files changed, 48 insertions, 0 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index e446f73..525de77 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<std::string, std::string> notification) +{ + serverNotifications.push_back(notification); + notifyNewNotification(notification); +} + +std::vector<std::pair<std::string, std::string> > 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<std::string, std::string> item = std::pair<std::string, std::string>(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<std::string, std::string> notification) +{ + for (std::vector<ClientListener*>::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<std::string, std::string> item = std::pair<std::string, std::string>(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 642fd63..bd33273 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -46,6 +46,7 @@ class ClientListener; class Client: public Singleton<Client> { private: std::string messageOfTheDay; + std::vector<std::pair<std::string, std::string> > serverNotifications; void * versionCheckRequest; bool updateAvailable; @@ -73,6 +74,7 @@ private: void notifyUpdateAvailable(); void notifyAuthUserChanged(); void notifyMessageOfTheDay(); + void notifyNewNotification(std::pair<std::string, std::string> notification); //Config file handle json::Object configDocument; @@ -92,6 +94,9 @@ public: std::vector<unsigned char> ReadFile(std::string filename); + void AddServerNotification(std::pair<std::string, std::string> notification); + std::vector<std::pair<std::string, std::string> > GetServerNotifications(); + void SetMessageOfTheDay(std::string message); std::string GetMessageOfTheDay(); diff --git a/src/client/ClientListener.h b/src/client/ClientListener.h index 07e784c..68721b1 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<std::string, std::string> notification) {} }; |
