diff --git a/libresapi/src/api/ChatHandler.cpp b/libresapi/src/api/ChatHandler.cpp index 6809e2435..7aed53dc1 100644 --- a/libresapi/src/api/ChatHandler.cpp +++ b/libresapi/src/api/ChatHandler.cpp @@ -161,6 +161,7 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs, mMsgStateToken = mStateTokenServer->getNewToken(); mLobbiesStateToken = mStateTokenServer->getNewToken(); mUnreadMsgsStateToken = mStateTokenServer->getNewToken(); + mInvitationsStateToken = mStateTokenServer->getNewToken(); addResourceHandler("*", this, &ChatHandler::handleWildcard); addResourceHandler("lobbies", this, &ChatHandler::handleLobbies); @@ -170,6 +171,7 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs, addResourceHandler("autosubscribe_lobby", this, &ChatHandler::handleAutoSubsribeLobby); addResourceHandler("clear_lobby", this, &ChatHandler::handleClearLobby); addResourceHandler("invite_to_lobby", this, &ChatHandler::handleInviteToLobby); + addResourceHandler("get_invitations_to_lobby", this, &ChatHandler::handleGetInvitationsToLobby); addResourceHandler("lobby_participants", this, &ChatHandler::handleLobbyParticipants); addResourceHandler("messages", this, &ChatHandler::handleMessages); addResourceHandler("send_message", this, &ChatHandler::handleSendMessage); @@ -230,6 +232,15 @@ void ChatHandler::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type, } } +void ChatHandler::notifyListChange(int list, int type) +{ + if(list == NOTIFY_LIST_CHAT_LOBBY_INVITATION) + { + RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + mStateTokenServer->replaceToken(mInvitationsStateToken); + } +} + void ChatHandler::tick() { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ @@ -956,6 +967,25 @@ void ChatHandler::handleInviteToLobby(Request& req, Response& resp) resp.setOk(); } +void ChatHandler::handleGetInvitationsToLobby(Request& req, Response& resp) +{ + std::list invites; + mRsMsgs->getPendingChatLobbyInvites(invites); + + resp.mDataStream.getStreamToMember(); + for(std::list::const_iterator it = invites.begin(); it != invites.end(); ++it) + { + resp.mDataStream.getStreamToMember() + << makeKeyValue("peer_id", (*it).peer_id.toStdString()) + << makeKeyValue("lobby_id", (*it).lobby_id) + << makeKeyValue("lobby_name", (*it).lobby_name) + << makeKeyValue("lobby_topic", (*it).lobby_topic); + } + + resp.mStateToken = mInvitationsStateToken; + resp.setOk(); +} + ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp) { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ diff --git a/libresapi/src/api/ChatHandler.h b/libresapi/src/api/ChatHandler.h index 8f237b401..f8f5461e5 100644 --- a/libresapi/src/api/ChatHandler.h +++ b/libresapi/src/api/ChatHandler.h @@ -35,6 +35,8 @@ public: virtual void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ , const RsGxsId& /* nickname */,const std::string& /* any string */); + virtual void notifyListChange(int list, int type); + // from tickable virtual void tick(); @@ -123,6 +125,7 @@ private: void handleUnsubscribeLobby(Request& req, Response& resp); void handleAutoSubsribeLobby(Request& req, Response& resp); void handleInviteToLobby(Request& req, Response& resp); + void handleGetInvitationsToLobby(Request& req, Response& resp); void handleClearLobby(Request& req, Response& resp); ResponseTask* handleLobbyParticipants(Request& req, Response& resp); void handleMessages(Request& req, Response& resp); @@ -163,6 +166,7 @@ private: std::map mLobbyParticipantsInfos; StateToken mUnreadMsgsStateToken; + StateToken mInvitationsStateToken; }; } // namespace resource_api