New Conversation notifications

This commit is contained in:
Simon Robertshaw 2012-12-09 12:05:27 +00:00
parent 6478ed121c
commit 38862a78d1
5 changed files with 66 additions and 0 deletions

View File

@ -545,6 +545,17 @@ std::string Client::GetMessageOfTheDay()
return messageOfTheDay; 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() void Client::Tick()
{ {
//Check thumbnail queue //Check thumbnail queue
@ -579,6 +590,18 @@ void Client::Tick()
SetAuthUser(User(0, "")); 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 //MOTD
json::String messageOfTheDay = objDocument["MessageOfTheDay"]; json::String messageOfTheDay = objDocument["MessageOfTheDay"];
this->messageOfTheDay = messageOfTheDay.Value(); 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) void Client::AddListener(ClientListener * listener)
{ {
listeners.push_back(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 sessionIDTemp = objDocument["SessionID"];
json::String sessionKeyTemp = objDocument["SessionKey"]; json::String sessionKeyTemp = objDocument["SessionKey"];
json::String userElevationTemp = objDocument["Elevation"]; 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.Username = username;
user.ID = userIDTemp.Value(); user.ID = userIDTemp.Value();
user.SessionID = sessionIDTemp.Value(); user.SessionID = sessionIDTemp.Value();

View File

@ -46,6 +46,7 @@ class ClientListener;
class Client: public Singleton<Client> { class Client: public Singleton<Client> {
private: private:
std::string messageOfTheDay; std::string messageOfTheDay;
std::vector<std::pair<std::string, std::string> > serverNotifications;
void * versionCheckRequest; void * versionCheckRequest;
bool updateAvailable; bool updateAvailable;
@ -73,6 +74,7 @@ private:
void notifyUpdateAvailable(); void notifyUpdateAvailable();
void notifyAuthUserChanged(); void notifyAuthUserChanged();
void notifyMessageOfTheDay(); void notifyMessageOfTheDay();
void notifyNewNotification(std::pair<std::string, std::string> notification);
//Config file handle //Config file handle
json::Object configDocument; json::Object configDocument;
@ -92,6 +94,9 @@ public:
std::vector<unsigned char> ReadFile(std::string filename); 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); void SetMessageOfTheDay(std::string message);
std::string GetMessageOfTheDay(); std::string GetMessageOfTheDay();

View File

@ -18,6 +18,7 @@ public:
virtual void NotifyUpdateAvailable(Client * sender) {} virtual void NotifyUpdateAvailable(Client * sender) {}
virtual void NotifyAuthUserChanged(Client * sender) {} virtual void NotifyAuthUserChanged(Client * sender) {}
virtual void NotifyMessageOfTheDay(Client * sender) {} virtual void NotifyMessageOfTheDay(Client * sender) {}
virtual void NotifyNewNotification(Client * sender, std::pair<std::string, std::string> notification) {}
}; };

View File

@ -1257,6 +1257,23 @@ void GameController::NotifyAuthUserChanged(Client * sender)
gameModel->SetUser(newUser); gameModel->SetUser(newUser);
} }
void GameController::NotifyNewNotification(Client * sender, std::pair<std::string, std::string> 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) void GameController::NotifyUpdateAvailable(Client * sender)
{ {
class UpdateConfirmation: public ConfirmDialogueCallback { class UpdateConfirmation: public ConfirmDialogueCallback {

View File

@ -142,6 +142,7 @@ public:
virtual void NotifyUpdateAvailable(Client * sender); virtual void NotifyUpdateAvailable(Client * sender);
virtual void NotifyAuthUserChanged(Client * sender); virtual void NotifyAuthUserChanged(Client * sender);
virtual void NotifyNewNotification(Client * sender, std::pair<std::string, std::string> notification);
void RunUpdater(); void RunUpdater();
}; };