mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-09 01:25:17 -04:00
webui: added chat
This commit is contained in:
parent
1939ea9f54
commit
a9ef48d133
14 changed files with 1621 additions and 44 deletions
|
@ -3,48 +3,124 @@
|
|||
#include "ResourceRouter.h"
|
||||
#include "StateTokenServer.h"
|
||||
#include <retroshare/rsnotify.h>
|
||||
#include <retroshare/rsmsgs.h>
|
||||
|
||||
class RsMsgs;
|
||||
class RsPeers;
|
||||
class RsIdentity;
|
||||
|
||||
namespace resource_api
|
||||
{
|
||||
|
||||
class ChatHandler: public ResourceRouter, NotifyClient
|
||||
class UnreadMsgNotify{
|
||||
public:
|
||||
virtual void notifyUnreadMsgCountChanged(const RsPeerId& peer, uint32_t count) = 0;
|
||||
};
|
||||
|
||||
class ChatHandler: public ResourceRouter, NotifyClient, Tickable
|
||||
{
|
||||
public:
|
||||
ChatHandler(StateTokenServer* sts, RsNotify* notify, RsMsgs* msgs);
|
||||
ChatHandler(StateTokenServer* sts, RsNotify* notify, RsMsgs* msgs, RsPeers* peers, RsIdentity *identity, UnreadMsgNotify* unread);
|
||||
virtual ~ChatHandler();
|
||||
|
||||
// from NotifyClient
|
||||
// note: this may get called from the own and from foreign threads
|
||||
virtual void notifyChatMessage();
|
||||
virtual void notifyChatMessage(const ChatMessage& msg);
|
||||
|
||||
private:
|
||||
void handleWildcard(Request& req, Response& resp);
|
||||
// from tickable
|
||||
virtual void tick();
|
||||
|
||||
StateTokenServer* mStateTokenServer;
|
||||
RsNotify* mNotify;
|
||||
RsMsgs* mRsMsgs;
|
||||
|
||||
RsMutex mMtx;
|
||||
StateToken mStateToken; // mutex protected
|
||||
|
||||
// msgs flow like this:
|
||||
// chatservice -> rawMsgs -> processedMsgs -> deletion
|
||||
|
||||
std::map<ChatId, std::list<ChatMessage> > mRawMsgs;
|
||||
public:
|
||||
class Triple
|
||||
{
|
||||
public:
|
||||
Triple(): first(-1), second(-1), third(-1){}
|
||||
double first;
|
||||
double second;
|
||||
double third;
|
||||
};
|
||||
|
||||
class Msg{
|
||||
public:
|
||||
bool read;
|
||||
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!
|
||||
std::vector<Triple> links;
|
||||
uint32_t recv_time;
|
||||
uint32_t send_time;
|
||||
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
std::map<ChatId, std::list<Msg> > mProcessedMsgs;
|
||||
class Lobby{
|
||||
public:
|
||||
Lobby(): id(0), subscribed(false), auto_subscribe(false), is_private(false){}
|
||||
ChatLobbyId id;
|
||||
std::string name;
|
||||
std::string topic;
|
||||
bool subscribed;
|
||||
bool auto_subscribe;
|
||||
bool is_private;
|
||||
|
||||
RsGxsId gxs_id;// for subscribed lobbies: the id we use to write messages
|
||||
|
||||
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
|
||||
&& gxs_id == l.gxs_id;
|
||||
}
|
||||
};
|
||||
|
||||
class ChatInfo{
|
||||
public:
|
||||
bool is_broadcast;
|
||||
bool is_gxs_id;
|
||||
bool is_lobby;
|
||||
bool is_peer;
|
||||
std::string remote_author_id;
|
||||
std::string remote_author_name;
|
||||
};
|
||||
|
||||
private:
|
||||
void handleWildcard(Request& req, Response& resp);
|
||||
void handleLobbies(Request& req, Response& resp);
|
||||
void handleSubscribeLobby(Request& req, Response& resp);
|
||||
void handleUnsubscribeLobby(Request& req, Response& resp);
|
||||
void handleMessages(Request& req, Response& resp);
|
||||
void handleSendMessage(Request& req, Response& resp);
|
||||
void handleMarkChatAsRead(Request& req, Response& resp);
|
||||
void handleInfo(Request& req, Response& resp);
|
||||
void handleTypingLabel(Request& req, Response& resp);
|
||||
void handleSendStatus(Request& req, Response& resp);
|
||||
void handleUnreadMsgs(Request& req, Response& resp);
|
||||
|
||||
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;
|
||||
|
||||
StateToken mLobbiesStateToken;
|
||||
std::vector<Lobby> mLobbies;
|
||||
|
||||
StateToken mUnreadMsgsStateToken;
|
||||
|
||||
};
|
||||
} // namespace resource_api
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue