Added: Handling requests to add and remove contact

This commit is contained in:
Konrad 2017-04-18 14:02:14 +02:00
parent 4a99000f16
commit 76dd7fe47f
2 changed files with 36 additions and 0 deletions

View File

@ -138,6 +138,9 @@ IdentityHandler::IdentityHandler(StateTokenServer *sts, RsNotify *notify, RsIden
addResourceHandler("own_ids", this, &IdentityHandler::handleOwnIdsRequest);
addResourceHandler("notown_ids", this, &IdentityHandler::handleNotOwnIdsRequest);
addResourceHandler("add_contact", this, &IdentityHandler::handleAddContact);
addResourceHandler("remove_contact", this, &IdentityHandler::handleRemoveContact);
addResourceHandler("create_identity", this, &IdentityHandler::handleCreateIdentity);
addResourceHandler("delete_identity", this, &IdentityHandler::handleDeleteIdentity);
}
@ -314,6 +317,36 @@ void IdentityHandler::handleOwnIdsRequest(Request & /*req*/, Response &resp)
else resp.setFail();
}
void IdentityHandler::handleAddContact(Request& req, Response& resp)
{
std::string gxs_id;
req.mStream << makeKeyValueReference("gxs_id", gxs_id);
mRsIdentity->setAsRegularContact(RsGxsId(gxs_id), true);
{
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
mStateTokenServer->replaceToken(mStateToken);
}
resp.setOk();
}
void IdentityHandler::handleRemoveContact(Request& req, Response& resp)
{
std::string gxs_id;
req.mStream << makeKeyValueReference("gxs_id", gxs_id);
mRsIdentity->setAsRegularContact(RsGxsId(gxs_id), false);
{
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
mStateTokenServer->replaceToken(mStateToken);
}
resp.setOk();
}
ResponseTask* IdentityHandler::handleOwn(Request & /* req */, Response &resp)
{
StateToken state;

View File

@ -26,6 +26,9 @@ private:
void handleNotOwnIdsRequest(Request& req, Response& resp);
void handleOwnIdsRequest(Request& req, Response& resp);
void handleAddContact(Request& req, Response& resp);
void handleRemoveContact(Request& req, Response& resp);
ResponseTask *handleOwn(Request& req, Response& resp);
ResponseTask *handleCreateIdentity(Request& req, Response& resp);
ResponseTask *handleDeleteIdentity(Request& req, Response& resp);