mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-07 08:35:16 -04:00
Expose libresapi for distant chat
Added macro to deprecate symbols usage in a crossplatform way. Deprecated Request::mMethod and related stuff that make implementation more complex without advantage. Added /chat/{initiate_distant_chat, distant_chat_status, close_distant_chat} to libresapi. Solved subtle bug in ChatId::ChatId(std::string str) that caused zeroed DistantChatPeerId being created.
This commit is contained in:
parent
f8de12d3d3
commit
9eef412b44
9 changed files with 179 additions and 82 deletions
|
@ -155,6 +155,9 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs,
|
|||
addResourceHandler("receive_status", this, &ChatHandler::handleReceiveStatus);
|
||||
addResourceHandler("send_status", this, &ChatHandler::handleSendStatus);
|
||||
addResourceHandler("unread_msgs", this, &ChatHandler::handleUnreadMsgs);
|
||||
addResourceHandler("initiate_distant_chat", this, &ChatHandler::handleInitiateDistantChatConnexion);
|
||||
addResourceHandler("distant_chat_status", this, &ChatHandler::handleDistantChatStatus);
|
||||
addResourceHandler("close_distant_chat", this, &ChatHandler::handleCloseDistantChatConnexion);
|
||||
}
|
||||
|
||||
ChatHandler::~ChatHandler()
|
||||
|
@ -928,12 +931,14 @@ void ChatHandler::handleMessages(Request &req, Response &resp)
|
|||
return;
|
||||
}
|
||||
std::map<ChatId, std::list<Msg> >::iterator mit = mMsgs.find(id);
|
||||
if(mit == mMsgs.end())
|
||||
{
|
||||
resp.mStateToken = mMsgStateToken; // even set state token, if not found yet, maybe later messages arrive and then the chat id will be found
|
||||
resp.setFail("chat with id=\""+req.mPath.top()+"\" not found");
|
||||
return;
|
||||
}
|
||||
if(mit == mMsgs.end())
|
||||
{
|
||||
/* set state token, even if not found yet, maybe later messages arrive
|
||||
* and then the chat id will be found */
|
||||
resp.mStateToken = mMsgStateToken;
|
||||
resp.setFail("chat with id=\""+req.mPath.top()+"\" not found");
|
||||
return;
|
||||
}
|
||||
resp.mStateToken = mMsgStateToken;
|
||||
handlePaginationRequest(req, resp, mit->second);
|
||||
}
|
||||
|
@ -954,7 +959,6 @@ void ChatHandler::handleSendMessage(Request &req, Response &resp)
|
|||
resp.setOk();
|
||||
else
|
||||
resp.setFail("failed to send message");
|
||||
|
||||
}
|
||||
|
||||
void ChatHandler::handleMarkChatAsRead(Request &req, Response &resp)
|
||||
|
@ -1125,4 +1129,63 @@ void ChatHandler::handleUnreadMsgs(Request &/*req*/, Response &resp)
|
|||
resp.mStateToken = mUnreadMsgsStateToken;
|
||||
}
|
||||
|
||||
void ChatHandler::handleInitiateDistantChatConnexion(Request& req, Response& resp)
|
||||
{
|
||||
std::string own_gxs_hex, remote_gxs_hex;
|
||||
|
||||
req.mStream << makeKeyValueReference("own_gxs_hex", own_gxs_hex)
|
||||
<< makeKeyValueReference("remote_gxs_hex", remote_gxs_hex);
|
||||
|
||||
RsGxsId sender_id(own_gxs_hex);
|
||||
if(sender_id.isNull())
|
||||
{
|
||||
resp.setFail("own_gxs_hex is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
RsGxsId receiver_id(remote_gxs_hex);
|
||||
if(receiver_id.isNull())
|
||||
{
|
||||
resp.setFail("remote_gxs_hex is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
DistantChatPeerId distant_chat_id;
|
||||
uint32_t error_code;
|
||||
|
||||
if(mRsMsgs->initiateDistantChatConnexion(receiver_id, sender_id, distant_chat_id, error_code))
|
||||
resp.setOk();
|
||||
else resp.setFail("Failed to initiate distant chat");
|
||||
|
||||
ChatId chat_id(distant_chat_id);
|
||||
resp.mDataStream << makeKeyValue("chat_id", chat_id.toStdString())
|
||||
<< makeKeyValueReference("error_code", error_code);
|
||||
}
|
||||
|
||||
void ChatHandler::handleDistantChatStatus(Request& req, Response& resp)
|
||||
{
|
||||
std::string distant_chat_hex;
|
||||
req.mStream << makeKeyValueReference("chat_id", distant_chat_hex);
|
||||
|
||||
ChatId id(distant_chat_hex);
|
||||
DistantChatPeerInfo info;
|
||||
if(mRsMsgs->getDistantChatStatus(id.toDistantChatId(), info)) resp.setOk();
|
||||
else resp.setFail("Failed to get status for distant chat");
|
||||
|
||||
resp.mDataStream << makeKeyValue("own_gxs_hex", info.own_id.toStdString())
|
||||
<< makeKeyValue("remote_gxs_hex", info.to_id.toStdString())
|
||||
<< makeKeyValue("chat_id", info.peer_id.toStdString())
|
||||
<< makeKeyValue("status", info.status);
|
||||
}
|
||||
|
||||
void ChatHandler::handleCloseDistantChatConnexion(Request& req, Response& resp)
|
||||
{
|
||||
std::string distant_chat_hex;
|
||||
req.mStream << makeKeyValueReference("distant_chat_hex", distant_chat_hex);
|
||||
|
||||
DistantChatPeerId chat_id(distant_chat_hex);
|
||||
if (mRsMsgs->closeDistantChatConnexion(chat_id)) resp.setOk();
|
||||
else resp.setFail("Failed to close distant chat");
|
||||
}
|
||||
|
||||
} // namespace resource_api
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue