2015-04-29 11:57:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ResourceRouter.h"
|
|
|
|
#include "StateTokenServer.h"
|
|
|
|
#include <retroshare/rsnotify.h>
|
2015-07-29 15:02:10 +02:00
|
|
|
#include <retroshare/rsmsgs.h>
|
2015-04-29 11:57:56 +00:00
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
class RsPeers;
|
|
|
|
class RsIdentity;
|
2015-04-29 11:57:56 +00:00
|
|
|
|
|
|
|
namespace resource_api
|
|
|
|
{
|
|
|
|
|
2016-12-07 20:09:14 +01:00
|
|
|
class UnreadMsgNotify
|
|
|
|
{
|
2015-07-29 15:02:10 +02:00
|
|
|
public:
|
2016-12-07 20:09:14 +01:00
|
|
|
virtual void notifyUnreadMsgCountChanged(const RsPeerId& peer, uint32_t count) = 0;
|
2015-07-29 15:02:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ChatHandler: public ResourceRouter, NotifyClient, Tickable
|
2015-04-29 11:57:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-07-29 15:02:10 +02:00
|
|
|
ChatHandler(StateTokenServer* sts, RsNotify* notify, RsMsgs* msgs, RsPeers* peers, RsIdentity *identity, UnreadMsgNotify* unread);
|
2015-04-29 11:57:56 +00:00
|
|
|
virtual ~ChatHandler();
|
|
|
|
|
|
|
|
// from NotifyClient
|
|
|
|
// note: this may get called from the own and from foreign threads
|
2015-07-29 15:02:10 +02:00
|
|
|
virtual void notifyChatMessage(const ChatMessage& msg);
|
2016-04-08 01:31:36 +02:00
|
|
|
virtual void notifyChatCleared(const ChatId& chat_id);
|
2015-04-29 11:57:56 +00:00
|
|
|
|
2016-02-14 14:57:41 +01:00
|
|
|
// typing label for peer, broadcast and distant chat
|
|
|
|
virtual void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */);
|
|
|
|
|
|
|
|
//typing label for lobby chat, peer join and leave messages
|
|
|
|
virtual void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ ,
|
|
|
|
const RsGxsId& /* nickname */,const std::string& /* any string */);
|
|
|
|
|
2017-07-06 14:07:33 +02:00
|
|
|
virtual void notifyListChange(int list, int type);
|
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
// from tickable
|
|
|
|
virtual void tick();
|
2015-04-29 11:57:56 +00:00
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
public:
|
|
|
|
class Triple
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Triple(): first(-1), second(-1), third(-1){}
|
|
|
|
double first;
|
|
|
|
double second;
|
|
|
|
double third;
|
|
|
|
};
|
2015-04-29 11:57:56 +00:00
|
|
|
|
|
|
|
class Msg{
|
|
|
|
public:
|
2015-07-29 15:02:10 +02:00
|
|
|
bool read;
|
2015-04-29 11:57:56 +00:00
|
|
|
bool incoming;
|
|
|
|
bool was_send;
|
|
|
|
//std::string chat_type;
|
|
|
|
std::string author_id; // peer or gxs id or "system" for system messages
|
|
|
|
std::string author_name;
|
|
|
|
std::string msg; // plain text only!
|
2015-07-29 15:02:10 +02:00
|
|
|
std::vector<Triple> links;
|
|
|
|
uint32_t recv_time;
|
|
|
|
uint32_t send_time;
|
|
|
|
|
|
|
|
uint32_t id;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Lobby{
|
|
|
|
public:
|
2015-10-01 18:49:39 +02:00
|
|
|
Lobby(): id(0), subscribed(false), auto_subscribe(false), is_private(false), is_broadcast(false){}
|
2015-07-29 15:02:10 +02:00
|
|
|
ChatLobbyId id;
|
|
|
|
std::string name;
|
|
|
|
std::string topic;
|
|
|
|
bool subscribed;
|
|
|
|
bool auto_subscribe;
|
|
|
|
bool is_private;
|
2015-10-01 18:49:39 +02:00
|
|
|
bool is_broadcast;
|
2015-07-29 15:02:10 +02:00
|
|
|
|
2015-12-05 17:00:57 +01:00
|
|
|
RsGxsId gxs_id;// for subscribed lobbies: the id we use to write messages
|
2015-07-29 15:02:10 +02:00
|
|
|
|
|
|
|
bool operator==(const Lobby& l) const
|
|
|
|
{
|
|
|
|
return id == l.id
|
|
|
|
&& name == l.name
|
|
|
|
&& topic == l.topic
|
|
|
|
&& subscribed == l.subscribed
|
|
|
|
&& auto_subscribe == l.auto_subscribe
|
|
|
|
&& is_private == l.is_private
|
2015-12-05 17:00:57 +01:00
|
|
|
&& is_broadcast == l.is_broadcast
|
|
|
|
&& gxs_id == l.gxs_id;
|
2015-07-29 15:02:10 +02:00
|
|
|
}
|
2015-04-29 11:57:56 +00:00
|
|
|
};
|
|
|
|
|
2016-02-07 14:09:33 +01:00
|
|
|
class LobbyParticipantsInfo{
|
|
|
|
public:
|
|
|
|
StateToken state_token;
|
|
|
|
std::map<RsGxsId, time_t> participants;
|
|
|
|
};
|
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
class ChatInfo{
|
|
|
|
public:
|
|
|
|
bool is_broadcast;
|
2015-11-30 00:02:44 -05:00
|
|
|
bool is_distant_chat_id;
|
2015-07-29 15:02:10 +02:00
|
|
|
bool is_lobby;
|
|
|
|
bool is_peer;
|
|
|
|
std::string remote_author_id;
|
|
|
|
std::string remote_author_name;
|
|
|
|
};
|
|
|
|
|
2016-02-14 14:57:41 +01:00
|
|
|
class TypingLabelInfo{
|
|
|
|
public:
|
|
|
|
time_t timestamp;
|
|
|
|
std::string status;
|
|
|
|
StateToken state_token;
|
|
|
|
// only for lobbies
|
|
|
|
RsGxsId author_id;
|
|
|
|
};
|
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
private:
|
|
|
|
void handleWildcard(Request& req, Response& resp);
|
|
|
|
void handleLobbies(Request& req, Response& resp);
|
2017-04-14 17:44:17 +02:00
|
|
|
void handleCreateLobby(Request& req, Response& resp);
|
2015-07-29 15:02:10 +02:00
|
|
|
void handleSubscribeLobby(Request& req, Response& resp);
|
|
|
|
void handleUnsubscribeLobby(Request& req, Response& resp);
|
2017-03-29 16:06:39 +02:00
|
|
|
void handleAutoSubsribeLobby(Request& req, Response& resp);
|
2017-07-06 14:05:48 +02:00
|
|
|
void handleInviteToLobby(Request& req, Response& resp);
|
2017-07-06 14:07:33 +02:00
|
|
|
void handleGetInvitationsToLobby(Request& req, Response& resp);
|
2017-07-06 14:08:50 +02:00
|
|
|
void handleAnswerToInvitation(Request& req, Response& resp);
|
2016-04-08 01:31:36 +02:00
|
|
|
void handleClearLobby(Request& req, Response& resp);
|
2016-02-07 14:09:33 +01:00
|
|
|
ResponseTask* handleLobbyParticipants(Request& req, Response& resp);
|
2015-07-29 15:02:10 +02:00
|
|
|
void handleMessages(Request& req, Response& resp);
|
|
|
|
void handleSendMessage(Request& req, Response& resp);
|
|
|
|
void handleMarkChatAsRead(Request& req, Response& resp);
|
|
|
|
void handleInfo(Request& req, Response& resp);
|
2016-02-14 14:57:41 +01:00
|
|
|
ResponseTask *handleReceiveStatus(Request& req, Response& resp);
|
2015-07-29 15:02:10 +02:00
|
|
|
void handleSendStatus(Request& req, Response& resp);
|
|
|
|
void handleUnreadMsgs(Request& req, Response& resp);
|
2016-12-07 20:09:14 +01:00
|
|
|
void handleInitiateDistantChatConnexion(Request& req, Response& resp);
|
|
|
|
void handleDistantChatStatus(Request& req, Response& resp);
|
|
|
|
void handleCloseDistantChatConnexion(Request& req, Response& resp);
|
2015-07-29 15:02:10 +02:00
|
|
|
|
2015-09-09 11:53:01 +02:00
|
|
|
void getPlainText(const std::string& in, std::string &out, std::vector<Triple> &links);
|
2016-02-14 14:57:41 +01:00
|
|
|
// last parameter is only used for lobbies!
|
|
|
|
void locked_storeTypingInfo(const ChatId& chat_id, std::string status, RsGxsId lobby_gxs_id = RsGxsId());
|
2015-09-09 11:53:01 +02:00
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
StateTokenServer* mStateTokenServer;
|
|
|
|
RsNotify* mNotify;
|
|
|
|
RsMsgs* mRsMsgs;
|
|
|
|
RsPeers* mRsPeers;
|
|
|
|
RsIdentity* mRsIdentity;
|
|
|
|
UnreadMsgNotify* mUnreadMsgNotify;
|
|
|
|
|
|
|
|
RsMutex mMtx;
|
|
|
|
|
|
|
|
StateToken mMsgStateToken;
|
|
|
|
std::list<ChatMessage> mRawMsgs;
|
|
|
|
std::map<ChatId, std::list<Msg> > mMsgs;
|
|
|
|
|
|
|
|
std::map<ChatId, ChatInfo> mChatInfo;
|
|
|
|
|
2016-02-14 14:57:41 +01:00
|
|
|
std::map<ChatId, TypingLabelInfo> mTypingLabelInfo;
|
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
StateToken mLobbiesStateToken;
|
|
|
|
std::vector<Lobby> mLobbies;
|
|
|
|
|
2016-02-07 14:09:33 +01:00
|
|
|
std::map<ChatLobbyId, LobbyParticipantsInfo> mLobbyParticipantsInfos;
|
|
|
|
|
2015-07-29 15:02:10 +02:00
|
|
|
StateToken mUnreadMsgsStateToken;
|
2017-07-06 14:07:33 +02:00
|
|
|
StateToken mInvitationsStateToken;
|
2015-04-29 11:57:56 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
} // namespace resource_api
|