Added: Handling requests to get lobbies invitations

This commit is contained in:
Konrad 2017-07-06 14:07:33 +02:00
parent aca6233dbf
commit c9bfe4b526
2 changed files with 34 additions and 0 deletions

View File

@ -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<ChatLobbyInvite> invites;
mRsMsgs->getPendingChatLobbyInvites(invites);
resp.mDataStream.getStreamToMember();
for(std::list<ChatLobbyInvite>::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 **********/

View File

@ -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<ChatLobbyId, LobbyParticipantsInfo> mLobbyParticipantsInfos;
StateToken mUnreadMsgsStateToken;
StateToken mInvitationsStateToken;
};
} // namespace resource_api