New Conversation notifications
This commit is contained in:
parent
6478ed121c
commit
38862a78d1
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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) {}
|
||||
};
|
||||
|
||||
|
||||
|
@ -1257,6 +1257,23 @@ void GameController::NotifyAuthUserChanged(Client * sender)
|
||||
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)
|
||||
{
|
||||
class UpdateConfirmation: public ConfirmDialogueCallback {
|
||||
|
@ -142,6 +142,7 @@ public:
|
||||
|
||||
virtual void NotifyUpdateAvailable(Client * sender);
|
||||
virtual void NotifyAuthUserChanged(Client * sender);
|
||||
virtual void NotifyNewNotification(Client * sender, std::pair<std::string, std::string> notification);
|
||||
void RunUpdater();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user