mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #927 from Emotyco/libresapi_lobbies_invitation
Added to libresapi: Handling lobbies invitations
This commit is contained in:
commit
fcec555cd0
@ -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);
|
||||
@ -169,6 +170,9 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs,
|
||||
addResourceHandler("unsubscribe_lobby", this, &ChatHandler::handleUnsubscribeLobby);
|
||||
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("answer_to_invitation", this, &ChatHandler::handleAnswerToInvitation);
|
||||
addResourceHandler("lobby_participants", this, &ChatHandler::handleLobbyParticipants);
|
||||
addResourceHandler("messages", this, &ChatHandler::handleMessages);
|
||||
addResourceHandler("send_message", this, &ChatHandler::handleSendMessage);
|
||||
@ -229,6 +233,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 **********/
|
||||
@ -936,6 +949,70 @@ void ChatHandler::handleClearLobby(Request &req, Response &resp)
|
||||
resp.setOk();
|
||||
}
|
||||
|
||||
void ChatHandler::handleInviteToLobby(Request& req, Response& resp)
|
||||
{
|
||||
std::string chat_id;
|
||||
std::string pgp_id;
|
||||
req.mStream << makeKeyValueReference("chat_id", chat_id);
|
||||
req.mStream << makeKeyValueReference("pgp_id", pgp_id);
|
||||
|
||||
ChatId chatId(chat_id);
|
||||
RsPgpId pgpId(pgp_id);
|
||||
|
||||
std::list<RsPeerId> peerIds;
|
||||
mRsPeers->getAssociatedSSLIds(pgpId, peerIds);
|
||||
|
||||
for(std::list<RsPeerId>::iterator it = peerIds.begin(); it != peerIds.end(); it++)
|
||||
mRsMsgs->invitePeerToLobby(chatId.toLobbyId(), (*it));
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void ChatHandler::handleAnswerToInvitation(Request& req, Response& resp)
|
||||
{
|
||||
ChatLobbyId lobbyId = 0;
|
||||
req.mStream << makeKeyValueReference("lobby_id", lobbyId);
|
||||
|
||||
bool join;
|
||||
req.mStream << makeKeyValueReference("join", join);
|
||||
|
||||
std::string gxs_id;
|
||||
req.mStream << makeKeyValueReference("gxs_id", gxs_id);
|
||||
RsGxsId gxsId(gxs_id);
|
||||
|
||||
if(join)
|
||||
{
|
||||
if(rsMsgs->acceptLobbyInvite(lobbyId, gxsId))
|
||||
resp.setOk();
|
||||
else
|
||||
resp.setFail();
|
||||
}
|
||||
else
|
||||
{
|
||||
rsMsgs->denyLobbyInvite(lobbyId);
|
||||
resp.setOk();
|
||||
}
|
||||
}
|
||||
|
||||
ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp)
|
||||
{
|
||||
RS_STACK_MUTEX(mMtx); /********** LOCKED **********/
|
||||
|
@ -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();
|
||||
|
||||
@ -122,6 +124,9 @@ private:
|
||||
void handleSubscribeLobby(Request& req, Response& resp);
|
||||
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 handleAnswerToInvitation(Request& req, Response& resp);
|
||||
void handleClearLobby(Request& req, Response& resp);
|
||||
ResponseTask* handleLobbyParticipants(Request& req, Response& resp);
|
||||
void handleMessages(Request& req, Response& resp);
|
||||
@ -162,6 +167,7 @@ private:
|
||||
std::map<ChatLobbyId, LobbyParticipantsInfo> mLobbyParticipantsInfos;
|
||||
|
||||
StateToken mUnreadMsgsStateToken;
|
||||
StateToken mInvitationsStateToken;
|
||||
|
||||
};
|
||||
} // namespace resource_api
|
||||
|
Loading…
Reference in New Issue
Block a user