diff --git a/src/chat/distantchat.cc b/src/chat/distantchat.cc index e90d83de3..27b2dd40e 100644 --- a/src/chat/distantchat.cc +++ b/src/chat/distantchat.cc @@ -33,7 +33,6 @@ #include "rsitems/rsmsgitems.h" -#include "retroshare/rsmsgs.h" #include "retroshare/rsidentity.h" #include "retroshare/rsiface.h" diff --git a/src/chat/distantchat.h b/src/chat/distantchat.h index eda55da49..a46a7547c 100644 --- a/src/chat/distantchat.h +++ b/src/chat/distantchat.h @@ -23,7 +23,7 @@ #pragma once #include -#include +#include #include class RsGixs ; diff --git a/src/chat/distributedchat.h b/src/chat/distributedchat.h index e7b9ee33a..411da81c1 100644 --- a/src/chat/distributedchat.h +++ b/src/chat/distributedchat.h @@ -22,7 +22,7 @@ #pragma once #include -#include +#include #include typedef RsPeerId ChatLobbyVirtualPeerId ; diff --git a/src/chat/p3chatservice.cc b/src/chat/p3chatservice.cc index 1f76ad6f9..9eddf9b60 100644 --- a/src/chat/p3chatservice.cc +++ b/src/chat/p3chatservice.cc @@ -47,10 +47,232 @@ * #define CHAT_DEBUG 1 ****/ +RsChats *rsChats = nullptr; + static const uint32_t MAX_MESSAGE_SECURITY_SIZE = 31000 ; // Max message size to forward other friends static const uint32_t MAX_AVATAR_JPEG_SIZE = 32767; // Maximum size in bytes for an avatar. Too large packets // don't transfer correctly and can kill the system. - // Images are 96x96, which makes approx. 27000 bytes uncompressed. +ChatId::ChatId(): + type(TYPE_NOT_SET), + lobby_id(0) +{ + +} + +ChatId::ChatId(RsPeerId id): + lobby_id(0) +{ + type = TYPE_PRIVATE; + peer_id = id; +} + +ChatId::ChatId(DistantChatPeerId id): + lobby_id(0) +{ + type = TYPE_PRIVATE_DISTANT; + distant_chat_id = id; +} + +ChatId::ChatId(ChatLobbyId id): + lobby_id(0) +{ + type = TYPE_LOBBY; + lobby_id = id; +} + +ChatId::ChatId(std::string str) : lobby_id(0) +{ + type = TYPE_NOT_SET; + if(str.empty()) return; + + if(str[0] == 'P') + { + type = TYPE_PRIVATE; + peer_id = RsPeerId(str.substr(1)); + } + else if(str[0] == 'D') + { + type = TYPE_PRIVATE_DISTANT; + distant_chat_id = DistantChatPeerId(str.substr(1)); + } + else if(str[0] == 'L') + { + if(sizeof(ChatLobbyId) != 8) + { + std::cerr << "ChatId::ChatId(std::string) Error: sizeof(ChatLobbyId) != 8. please report this" << std::endl; + return; + } + str = str.substr(1); + if(str.size() != 16) + return; + ChatLobbyId id = 0; + for(int i = 0; i<16; i++) + { + uint8_t c = str[i]; + if(c <= '9') + c -= '0'; + else + c -= 'A' - 10; + id = id << 4; + id |= c; + } + type = TYPE_LOBBY; + lobby_id = id; + } + else if(str[0] == 'B') + { + type = TYPE_BROADCAST; + } +} + +ChatId ChatId::makeBroadcastId() +{ + ChatId id; + id.type = TYPE_BROADCAST; + return id; +} + +std::string ChatId::toStdString() const +{ + std::string str; + if(type == TYPE_PRIVATE) + { + str += "P"; + str += peer_id.toStdString(); + } + else if(type == TYPE_PRIVATE_DISTANT) + { + str += "D"; + str += distant_chat_id.toStdString(); + } + else if(type == TYPE_LOBBY) + { + if(sizeof(ChatLobbyId) != 8) + { + std::cerr << "ChatId::toStdString() Error: sizeof(ChatLobbyId) != 8. please report this" << std::endl; + return ""; + } + str += "L"; + + ChatLobbyId id = lobby_id; + for(int i = 0; i<16; i++) + { + uint8_t c = id >>(64-4); + if(c > 9) + c += 'A' - 10; + else + c += '0'; + str += c; + id = id << 4; + } + } + else if(type == TYPE_BROADCAST) + { + str += "B"; + } + return str; +} + +bool ChatId::operator <(const ChatId& other) const +{ + if(type != other.type) + return type < other.type; + else + { + switch(type) + { + case TYPE_NOT_SET: + return false; + case TYPE_PRIVATE: + return peer_id < other.peer_id; + case TYPE_PRIVATE_DISTANT: + return distant_chat_id < other.distant_chat_id; + case TYPE_LOBBY: + return lobby_id < other.lobby_id; + case TYPE_BROADCAST: + return false; + default: + return false; + } + } +} + +bool ChatId::isSameEndpoint(const ChatId &other) const +{ + if(type != other.type) + return false; + else + { + switch(type) + { + case TYPE_NOT_SET: + return false; + case TYPE_PRIVATE: + return peer_id == other.peer_id; + case TYPE_PRIVATE_DISTANT: + return distant_chat_id == other.distant_chat_id; + case TYPE_LOBBY: + return lobby_id == other.lobby_id; + case TYPE_BROADCAST: + return true; + default: + return false; + } + } +} + +bool ChatId::isNotSet() const +{ + return type == TYPE_NOT_SET; +} +bool ChatId::isPeerId() const +{ + return type == TYPE_PRIVATE; +} +bool ChatId::isDistantChatId() const +{ + return type == TYPE_PRIVATE_DISTANT; +} +bool ChatId::isLobbyId() const +{ + return type == TYPE_LOBBY; +} +bool ChatId::isBroadcast() const +{ + return type == TYPE_BROADCAST; +} +RsPeerId ChatId::toPeerId() const +{ + if(type == TYPE_PRIVATE) + return peer_id; + else + { + std::cerr << "ChatId Warning: conversation to RsPeerId requested, but type is different. Current value=\"" << toStdString() << "\"" << std::endl; + return RsPeerId(); + } +} + +DistantChatPeerId ChatId::toDistantChatId() const +{ + if(type == TYPE_PRIVATE_DISTANT) + return distant_chat_id; + else + { + std::cerr << "ChatId Warning: conversation to DistantChatPeerId requested, but type is different. Current value=\"" << toStdString() << "\"" << std::endl; + return DistantChatPeerId(); + } +} +ChatLobbyId ChatId::toLobbyId() const +{ + if(type == TYPE_LOBBY) + return lobby_id; + else + { + std::cerr << "ChatId Warning: conversation to ChatLobbyId requested, but type is different. Current value=\"" << toStdString() << "\"" << std::endl; + return 0; + } +} + p3ChatService::p3ChatService( p3ServiceControl *sc, p3IdService *pids, p3LinkMgr *lm, p3HistoryMgr *historyMgr, @@ -253,9 +475,101 @@ void p3ChatService::sendStatusString( const ChatId& id, } } -void p3ChatService::clearChatLobby(const ChatId& id) +void p3ChatService::clearChatLobby(const ChatId& /*id */) +{ + RsWarn() << __PRETTY_FUNCTION__ << " not implemented, and shouldn't be called." ; +} + +bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& own_id) +{ + return DistributedChatService::joinVisibleChatLobby(lobby_id,own_id); +} +bool p3ChatService::getChatLobbyInfo(const ChatLobbyId& id,ChatLobbyInfo& info) { + return DistributedChatService::getChatLobbyInfo(id,info); } +void p3ChatService::getListOfNearbyChatLobbies(std::vector& public_lobbies) +{ + DistributedChatService::getListOfNearbyChatLobbies(public_lobbies); +} +void p3ChatService::invitePeerToLobby(const ChatLobbyId &lobby_id, const RsPeerId &peer_id) +{ + DistributedChatService::invitePeerToLobby(lobby_id,peer_id); +} +bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& id,const RsGxsId& gxs_id) +{ + return DistributedChatService::acceptLobbyInvite(id,gxs_id) ; +} +void p3ChatService::getChatLobbyList(std::list& lids) +{ + DistributedChatService::getChatLobbyList(lids) ; +} + +bool p3ChatService::denyLobbyInvite(const ChatLobbyId &id) +{ + return DistributedChatService::denyLobbyInvite(id); +} +void p3ChatService::getPendingChatLobbyInvites(std::list &invites) +{ + DistributedChatService::getPendingChatLobbyInvites(invites); +} + + +void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& lobby_id) +{ + DistributedChatService::unsubscribeChatLobby(lobby_id) ; +} +void p3ChatService::sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id) +{ + DistributedChatService::sendLobbyStatusPeerLeaving(lobby_id) ; +} + +bool p3ChatService::setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) +{ + return DistributedChatService::setIdentityForChatLobby(lobby_id,nick) ; +} +bool p3ChatService::getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick_name) +{ + return DistributedChatService::getIdentityForChatLobby(lobby_id,nick_name) ; +} +bool p3ChatService::setDefaultIdentityForChatLobby(const RsGxsId& nick) +{ + return DistributedChatService::setDefaultIdentityForChatLobby(nick) ; +} +void p3ChatService::getDefaultIdentityForChatLobby(RsGxsId& nick_name) +{ + DistributedChatService::getDefaultIdentityForChatLobby(nick_name) ; +} +void p3ChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe) +{ + DistributedChatService::setLobbyAutoSubscribe(lobby_id, autoSubscribe); +} + +bool p3ChatService::getLobbyAutoSubscribe(const ChatLobbyId& lobby_id) +{ + return DistributedChatService::getLobbyAutoSubscribe(lobby_id); +} +bool p3ChatService::setDistantChatPermissionFlags(uint32_t flags) +{ + return DistantChatService::setDistantChatPermissionFlags(flags) ; +} +uint32_t p3ChatService::getDistantChatPermissionFlags() +{ + return DistantChatService::getDistantChatPermissionFlags() ; +} +bool p3ChatService::getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info) +{ + return DistantChatService::getDistantChatStatus(pid,info) ; +} +bool p3ChatService::closeDistantChatConnexion(const DistantChatPeerId &pid) +{ + return DistantChatService::closeDistantChatConnexion(pid) ; +} +ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set& invited_friends,ChatLobbyFlags privacy_type) +{ + return DistributedChatService::createChatLobby(lobby_name,lobby_identity,lobby_topic,invited_friends,privacy_type) ; +} + void p3ChatService::sendChatItem(RsChatItem *item) { @@ -310,7 +624,7 @@ bool p3ChatService::isOnline(const RsPeerId& pid) { // check if the id is a tunnel id or a peer id. DistantChatPeerInfo dcpinfo; - if(getDistantChatStatus(DistantChatPeerId(pid),dcpinfo)) + if(DistantChatService::getDistantChatStatus(DistantChatPeerId(pid),dcpinfo)) return dcpinfo.status == RS_DISTANT_CHAT_STATUS_CAN_TALK; else return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid); } @@ -640,11 +954,11 @@ bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci) // Remove too big messages if (ci->chatFlags & RS_CHAT_FLAG_LOBBY) { - uint32_t maxMessageSize = getMaxMessageSecuritySize(RS_CHAT_TYPE_LOBBY); + uint32_t maxMessageSize = rsChats->getMaxMessageSecuritySize(RS_CHAT_TYPE_LOBBY); if (maxMessageSize > 0 && ci->message.length() > maxMessageSize) { std::ostringstream os; - os << getMaxMessageSecuritySize(RS_CHAT_TYPE_LOBBY); + os << rsChats->getMaxMessageSecuritySize(RS_CHAT_TYPE_LOBBY); ci->message = "**** Security warning: Message bigger than "; ci->message += os.str(); @@ -1007,7 +1321,7 @@ void p3ChatService::initChatMessage(RsChatMsgItem *c, ChatMessage &m) } } -void p3ChatService::setOwnCustomStateString(const std::string& s) +void p3ChatService::setCustomStateString(const std::string& s) { std::set onlineList; { @@ -1046,7 +1360,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s) IndicateConfigChanged(); } -void p3ChatService::setOwnNodeAvatarJpegData(const unsigned char *data,int size) +void p3ChatService::setOwnNodeAvatarData(const unsigned char *data,int size) { { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1131,7 +1445,7 @@ std::string p3ChatService::getOwnCustomStateString() RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ return _custom_status_string ; } -void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size) +void p3ChatService::getOwnNodeAvatarData(unsigned char *& data,int& size) { // should be a Mutex here. RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1175,7 +1489,7 @@ std::string p3ChatService::getCustomStateString(const RsPeerId& peer_id) return std::string() ; } -void p3ChatService::getAvatarJpegData(const RsPeerId& peer_id,unsigned char *& data,int& size) +void p3ChatService::getAvatarData(const RsPeerId& peer_id,unsigned char *& data,int& size) { { // should be a Mutex here. diff --git a/src/chat/p3chatservice.h b/src/chat/p3chatservice.h index 56c625671..a196e535c 100644 --- a/src/chat/p3chatservice.h +++ b/src/chat/p3chatservice.h @@ -27,12 +27,11 @@ #include #include -#include "rsitems/rsmsgitems.h" #include "services/p3service.h" #include "pqi/pqiservicemonitor.h" #include "chat/distantchat.h" #include "chat/distributedchat.h" -#include "retroshare/rsmsgs.h" +#include "retroshare/rschats.h" #include "gxstrans/p3gxstrans.h" #include "util/rsdeprecate.h" @@ -66,6 +65,7 @@ struct RsChatMessageEvent : RsEvent * @see NotifyBase */ class p3ChatService : + public RsChats, public p3Service, public DistantChatService, public DistributedChatService, public p3Config, public pqiServiceMonitor, GxsTransClient { @@ -73,7 +73,7 @@ class p3ChatService : p3ChatService(p3ServiceControl *cs, p3IdService *pids, p3LinkMgr *cm, p3HistoryMgr *historyMgr, p3GxsTrans& gxsTransService ); - virtual RsServiceInfo getServiceInfo(); + virtual RsServiceInfo getServiceInfo()override; /***** overloaded from p3Service *****/ /*! @@ -83,24 +83,23 @@ class p3ChatService : * : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar * @see NotifyBase */ - virtual int tick(); + virtual int tick()override; /*************** pqiMonitor callback ***********************/ - virtual void statusChange(const std::list &plist); + virtual void statusChange(const std::list &plist)override; /*! * public chat sent to all peers */ void sendPublicChat(const std::string &msg); - /********* RsMsgs ***********/ /*! * Send a chat message. * @param destination where to send the chat message * @param msg the message * @see ChatId */ - bool sendChat(ChatId destination, std::string msg); + bool sendChat(ChatId destination, std::string msg)override; /*! * chat is sent to specifc peer @@ -112,13 +111,40 @@ class p3ChatService : * can be used to send 'immediate' status msgs, these status updates are * meant for immediate use by peer (not saved by rs) e.g currently used to * update user when a peer 'is typing' during a chat */ - void sendStatusString( const ChatId& id, const std::string& status_str ); + void sendStatusString( const ChatId& id, const std::string& status_str )override; /** * @brief clearChatLobby: Signal chat was cleared by GUI. * @param id: Chat id cleared. */ - virtual void clearChatLobby(const ChatId& id); + + /** methods that will call the DistributedChatService parent + */ + virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set& invited_friends,ChatLobbyFlags privacy_type) override; + virtual bool joinVisibleChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& own_id) override; + virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) override; + virtual void getChatLobbyList(std::list& lids) override; + virtual void clearChatLobby(const ChatId& id)override; + virtual bool getChatLobbyInfo(const ChatLobbyId& id,ChatLobbyInfo& info) override; + virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) override; + virtual void invitePeerToLobby(const ChatLobbyId &lobby_id, const RsPeerId &peer_id) override; + virtual bool denyLobbyInvite(const ChatLobbyId &id) override ; + virtual bool acceptLobbyInvite(const ChatLobbyId& id,const RsGxsId& gxs_id) override; + virtual void getPendingChatLobbyInvites(std::list &invites) override; + virtual void sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id) override; + virtual bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) override; + virtual bool getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick_name) override; + virtual bool setDefaultIdentityForChatLobby(const RsGxsId& nick) override; + virtual void getDefaultIdentityForChatLobby(RsGxsId& nick_name) override; + virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe) override; + virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id) override; + + /** methods that will call the DistantChatService parent + */ + virtual bool setDistantChatPermissionFlags(uint32_t flags) override; + virtual uint32_t getDistantChatPermissionFlags() override; + virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info) override; + virtual bool closeDistantChatConnexion(const DistantChatPeerId &pid) override; /*! * send to all peers online @@ -130,42 +156,42 @@ class p3ChatService : * this retrieves custom status for a peers, generate a requests to the peer * @param peer_id the id of the peer you want status string for */ - std::string getCustomStateString(const RsPeerId& peer_id) ; + virtual std::string getCustomStateString(const RsPeerId& peer_id) override; /*! * sets the client's custom status, generates 'status available' item sent to all online peers */ - void setOwnCustomStateString(const std::string&) ; + virtual void setCustomStateString(const std::string&) override; /*! * @return client's custom string */ - std::string getOwnCustomStateString() ; + virtual std::string getOwnCustomStateString() override; /*! gets the peer's avatar in jpeg format, if available. Null otherwise. Also asks the peer to send * its avatar, if not already available. Creates a new unsigned char array. It's the caller's * responsibility to delete this ones used. */ - void getAvatarJpegData(const RsPeerId& peer_id,unsigned char *& data,int& size) ; + void getAvatarData(const RsPeerId& peer_id,unsigned char *& data,int& size) override; /*! * Sets the avatar data and size for client's account * @param data is copied, so should be destroyed by the caller */ - void setOwnNodeAvatarJpegData(const unsigned char *data,int size) ; + void setOwnNodeAvatarData(const unsigned char *data,int size) override; /*! * Gets the avatar data for clients account * data is in jpeg format */ - void getOwnAvatarJpegData(unsigned char *& data,int& size) ; + void getOwnNodeAvatarData(unsigned char *& data,int& size) override; /*! * Return the max message size for security forwarding * @param type RS_CHAT_TYPE_... * return 0 unlimited */ - static uint32_t getMaxMessageSecuritySize(int type); + uint32_t getMaxMessageSecuritySize(int type)override; /*! * Checks message security, especially remove billion laughs attacks @@ -182,37 +208,36 @@ class p3ChatService : const RsGxsId& from_gxs_id, DistantChatPeerId &pid, uint32_t& error_code, - bool notify = true ); + bool notify = true )override; /// @see GxsTransClient::receiveGxsTransMail(...) virtual bool receiveGxsTransMail( const RsGxsId& authorId, const RsGxsId& recipientId, - const uint8_t* data, uint32_t dataSize ); + const uint8_t* data, uint32_t dataSize )override; /// @see GxsTransClient::notifySendMailStatus(...) virtual bool notifyGxsTransSendStatus( RsGxsTransId mailId, - GxsTransSendStatus status ); - + GxsTransSendStatus status )override; protected: /************* from p3Config *******************/ - virtual RsSerialiser *setupSerialiser() ; + virtual RsSerialiser *setupSerialiser() override; /*! * chat msg items and custom status are saved */ - virtual bool saveList(bool& cleanup, std::list&) ; - virtual void saveDone(); - virtual bool loadList(std::list& load) ; + virtual bool saveList(bool& cleanup, std::list&) override; + virtual void saveDone()override; + virtual bool loadList(std::list& load) override; // accepts virtual peer id bool isOnline(const RsPeerId &pid) ; /// This is to be used by subclasses/parents to call IndicateConfigChanged() - virtual void triggerConfigSave() { IndicateConfigChanged() ; } + virtual void triggerConfigSave()override { IndicateConfigChanged() ; } /// Same, for storing messages in incoming list - RS_DEPRECATED virtual void locked_storeIncomingMsg(RsChatMsgItem *) ; + RS_DEPRECATED virtual void locked_storeIncomingMsg(RsChatMsgItem *) override; private: RsMutex mChatMtx; @@ -222,9 +247,9 @@ class p3ChatService : // Receive chat queue void receiveChatQueue(); - void handleIncomingItem(RsItem *); // called by the former, and turtle handler for incoming encrypted items + void handleIncomingItem(RsItem *)override; // called by the former, and turtle handler for incoming encrypted items - virtual void sendChatItem(RsChatItem *) ; + virtual void sendChatItem(RsChatItem *) override; void initChatMessage(RsChatMsgItem *c, ChatMessage& msg); @@ -239,7 +264,7 @@ class p3ChatService : void receiveStateString(const RsPeerId& id,const std::string& s) ; /// methods for handling various Chat items. - virtual bool handleRecvChatMsgItem(RsChatMsgItem *&item) ; // NULL-ifies the item if memory ownership is taken + virtual bool handleRecvChatMsgItem(RsChatMsgItem *&item)override ; // NULL-ifies the item if memory ownership is taken void handleRecvChatStatusItem(RsChatStatusItem *item) ; void handleRecvChatAvatarItem(RsChatAvatarItem *item) ; diff --git a/src/chat/rschatitems.cc b/src/chat/rschatitems.cc index 13d272c4e..6d365449e 100644 --- a/src/chat/rschatitems.cc +++ b/src/chat/rschatitems.cc @@ -21,7 +21,6 @@ *******************************************************************************/ #include -#include "retroshare/rsmsgs.h" #include "util/rstime.h" #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" diff --git a/src/chat/rschatitems.h b/src/chat/rschatitems.h index aca3a411a..f491dc63f 100644 --- a/src/chat/rschatitems.h +++ b/src/chat/rschatitems.h @@ -34,7 +34,7 @@ #include "serialiser/rstlvidset.h" #include "serialiser/rstlvfileitem.h" -#include "retroshare/rsmsgs.h" +#include "retroshare/rschats.h" /* chat Flags */ const uint32_t RS_CHAT_FLAG_PRIVATE = 0x0001; diff --git a/src/libretroshare.pro b/src/libretroshare.pro index 6c0c9d298..8d64c3205 100644 --- a/src/libretroshare.pro +++ b/src/libretroshare.pro @@ -134,7 +134,9 @@ PUBLIC_HEADERS = retroshare/rsdisc.h \ retroshare/rsiface.h \ retroshare/rsinit.h \ retroshare/rsplugin.h \ - retroshare/rsmsgs.h \ + retroshare/rschats.h \ + retroshare/rsmail.h \ + retroshare/rschat.h \ retroshare/rspeers.h \ retroshare/rsstatus.h \ retroshare/rsturtle.h \ @@ -440,7 +442,7 @@ HEADERS += pqi/authssl.h \ HEADERS += rsserver/p3face.h \ rsserver/p3history.h \ - rsserver/p3msgs.h \ +# rsserver/p3msgs.h \ rsserver/p3peers.h \ rsserver/p3status.h \ rsserver/rsaccounts.h \ @@ -613,7 +615,7 @@ SOURCES += rsserver/p3face-config.cc \ rsserver/p3face-server.cc \ rsserver/p3face-info.cc \ rsserver/p3history.cc \ - rsserver/p3msgs.cc \ +# rsserver/p3msgs.cc \ rsserver/p3peers.cc \ rsserver/p3status.cc \ rsserver/rsinit.cc \ diff --git a/src/pqi/p3historymgr.cc b/src/pqi/p3historymgr.cc index 93498928c..15f9e91da 100644 --- a/src/pqi/p3historymgr.cc +++ b/src/pqi/p3historymgr.cc @@ -26,6 +26,7 @@ #include "rsitems/rsconfigitems.h" #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" +#include "retroshare/rschats.h" #include "rsitems/rsmsgitems.h" #include "rsserver/p3face.h" #include "util/rsstring.h" @@ -94,7 +95,7 @@ void p3HistoryMgr::addMessage(const ChatMessage& cm) else if(cm.chat_id.isDistantChatId()&& mDistantEnable == true) { DistantChatPeerInfo dcpinfo; - if (rsMsgs->getDistantChatStatus(cm.chat_id.toDistantChatId(), dcpinfo)) + if (rsChats->getDistantChatStatus(cm.chat_id.toDistantChatId(), dcpinfo)) { RsIdentityDetails det; RsGxsId writer_id = cm.incoming?(dcpinfo.to_id):(dcpinfo.own_id); diff --git a/src/retroshare/rsevents.h b/src/retroshare/rsevents.h index 7ecbd9a11..840f6b211 100644 --- a/src/retroshare/rsevents.h +++ b/src/retroshare/rsevents.h @@ -98,7 +98,7 @@ enum class RsEventType : uint32_t /// @see RsFiles FILE_TRANSFER = 14, - /// @see RsMsgs + /// @see RsChats CHAT_SERVICE = 15, /// @see rspeers.h diff --git a/src/retroshare/rsmail.h b/src/retroshare/rsmail.h new file mode 100644 index 000000000..0257e9bd7 --- /dev/null +++ b/src/retroshare/rsmail.h @@ -0,0 +1,608 @@ +/******************************************************************************* + * libretroshare/src/retroshare: rsmail.h * + * * + * libretroshare: retroshare core library * + * * + * Copyright (C) 2007-2008 Robert Fernie * + * Copyright (C) 2016-2019 Gioacchino Mazzurco * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public License * + * along with this program. If not, see . * + * * + *******************************************************************************/ +#pragma once + +#include +#include +#include +#include +#include + +#include "retroshare/rstypes.h" +#include "retroshare/rsgxsifacetypes.h" +#include "retroshare/rsevents.h" +#include "util/rsdeprecate.h" +#include "util/rsmemory.h" + +/********************** For Messages and Channels *****************/ + +#define RS_MSG_BOXMASK 0x000f /* Mask for determining Box */ + +#define RS_MSG_OUTGOING 0x0001 /* !Inbox */ +#define RS_MSG_PENDING 0x0002 /* OutBox */ +#define RS_MSG_DRAFT 0x0004 /* Draft */ + +/* ORs of above */ +#define RS_MSG_INBOX 0x00 /* Inbox */ +#define RS_MSG_SENTBOX 0x01 /* Sentbox = OUTGOING */ +#define RS_MSG_OUTBOX 0x03 /* Outbox = OUTGOING + PENDING */ +#define RS_MSG_DRAFTBOX 0x05 /* Draftbox = OUTGOING + DRAFT */ +#define RS_MSG_TRASHBOX 0x20 /* Trashbox = RS_MSG_TRASH */ + +#define RS_MSG_NEW 0x000010 /* New */ +#define RS_MSG_TRASH 0x000020 /* Trash */ +#define RS_MSG_UNREAD_BY_USER 0x000040 /* Unread by user */ +#define RS_MSG_REPLIED 0x000080 /* Message is replied */ +#define RS_MSG_FORWARDED 0x000100 /* Message is forwarded */ +#define RS_MSG_STAR 0x000200 /* Message is marked with a star */ +// system message +#define RS_MSG_USER_REQUEST 0x000400 /* user request */ +#define RS_MSG_FRIEND_RECOMMENDATION 0x000800 /* friend recommendation */ +#define RS_MSG_DISTANT 0x001000 /* message is distant */ +#define RS_MSG_SIGNATURE_CHECKS 0x002000 /* message was signed, and signature checked */ +#define RS_MSG_SIGNED 0x004000 /* message was signed and signature didn't check */ +#define RS_MSG_LOAD_EMBEDDED_IMAGES 0x008000 /* load embedded images */ +#define RS_MSG_PUBLISH_KEY 0x020000 /* publish key */ +#define RS_MSG_SPAM 0x040000 /* Message is marked as spam */ + +#define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_FRIEND_RECOMMENDATION | RS_MSG_PUBLISH_KEY) + +#define RS_MSGTAGTYPE_IMPORTANT 1 +#define RS_MSGTAGTYPE_WORK 2 +#define RS_MSGTAGTYPE_PERSONAL 3 +#define RS_MSGTAGTYPE_TODO 4 +#define RS_MSGTAGTYPE_LATER 5 +#define RS_MSGTAGTYPE_USER 100 + + +typedef std::string RsMailMessageId; // TODO: rebase on t_RsGenericIdType + +/** + * Used to return a tracker id so the API user can keep track of sent mail + * status, it contains mail id, and recipient id + */ +struct RsMailIdRecipientIdPair : RsSerializable +{ + RsMailIdRecipientIdPair(RsMailMessageId mailId, RsGxsId recipientId): + mMailId(mailId), mRecipientId(recipientId) {} + + RsMailMessageId mMailId; + RsGxsId mRecipientId; + + /// @see RsSerializable + void serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext &ctx ) override; + + bool operator<(const RsMailIdRecipientIdPair& other) const; + bool operator==(const RsMailIdRecipientIdPair& other) const; + + RsMailIdRecipientIdPair() = default; + ~RsMailIdRecipientIdPair() override = default; +}; + +namespace Rs +{ +namespace Mail +{ + +enum class BoxName:uint8_t { + BOX_NONE = 0x00, + BOX_INBOX = 0x01, + BOX_OUTBOX = 0x02, + BOX_DRAFTS = 0x03, + BOX_SENT = 0x04, + BOX_TRASH = 0x05, + BOX_ALL = 0x06 + }; + +class MsgAddress: public RsSerializable +{ + public: + MsgAddress() : _type(MSG_ADDRESS_TYPE_UNKNOWN),_mode(MSG_ADDRESS_MODE_UNKNOWN) {} + + typedef enum { MSG_ADDRESS_TYPE_UNKNOWN = 0x00, + MSG_ADDRESS_TYPE_RSPEERID = 0x01, + MSG_ADDRESS_TYPE_RSGXSID = 0x02, + MSG_ADDRESS_TYPE_PLAIN = 0x03 } AddressType; + + typedef enum { MSG_ADDRESS_MODE_UNKNOWN = 0x00, + MSG_ADDRESS_MODE_TO = 0x01, + MSG_ADDRESS_MODE_CC = 0x02, + MSG_ADDRESS_MODE_BCC = 0x03 } AddressMode; + + explicit MsgAddress(const RsGxsId& gid, MsgAddress::AddressMode mmode) + : _type(MSG_ADDRESS_TYPE_RSGXSID), _mode(mmode), _addr_string(gid.toStdString()){} + + explicit MsgAddress(const RsPeerId& pid, MsgAddress::AddressMode mmode) + : _type(MSG_ADDRESS_TYPE_RSPEERID), _mode(mmode), _addr_string(pid.toStdString()){} + + explicit MsgAddress(const std::string& email, MsgAddress::AddressMode mmode) + : _type(MSG_ADDRESS_TYPE_PLAIN), _mode(mmode), _addr_string(email){} + + void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx ) override + { + RS_SERIAL_PROCESS(_type); + RS_SERIAL_PROCESS(_mode); + RS_SERIAL_PROCESS(_addr_string); + } + + MsgAddress::AddressType type() const { return _type ;} + MsgAddress::AddressMode mode() const { return _mode ;} + + RsGxsId toGxsId() const { checkType(MSG_ADDRESS_TYPE_RSGXSID);return RsGxsId (_addr_string);} + RsPeerId toRsPeerId() const { checkType(MSG_ADDRESS_TYPE_RSPEERID);return RsPeerId(_addr_string);} + std::string toEmail() const { checkType(MSG_ADDRESS_TYPE_PLAIN );return _addr_string ;} + std::string toStdString() const { return _addr_string ;} + + void clear() { _addr_string=""; _type=MSG_ADDRESS_TYPE_UNKNOWN; _mode=MSG_ADDRESS_MODE_UNKNOWN;} + void checkType(MsgAddress::AddressType t) const + { + if(t != _type) + RsErr() << "WRONG TYPE in MsgAddress. This is not a good sign. Something's going wrong." ; + } + bool operator<(const MsgAddress& m) const { return _addr_string < m._addr_string; } + private: + AddressType _type ; + AddressMode _mode ; + std::string _addr_string ; +}; + +struct MessageInfo : RsSerializable +{ + MessageInfo(): msgflags(0), size(0), count(0), ts(0) {} + + std::string msgId; + + MsgAddress from; + MsgAddress to; + + unsigned int msgflags; + + std::set destinations; + + std::string title; + std::string msg; + + std::string attach_title; + std::string attach_comment; + std::list files; + + int size; /* total of files */ + int count; /* file count */ + + int ts; + + // RsSerializable interface + void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx ) override + { + RS_SERIAL_PROCESS(msgId); + + RS_SERIAL_PROCESS(from); + RS_SERIAL_PROCESS(to); + RS_SERIAL_PROCESS(destinations); + RS_SERIAL_PROCESS(msgflags); + + RS_SERIAL_PROCESS(title); + RS_SERIAL_PROCESS(msg); + + RS_SERIAL_PROCESS(attach_title); + RS_SERIAL_PROCESS(attach_comment); + RS_SERIAL_PROCESS(files); + + RS_SERIAL_PROCESS(size); + RS_SERIAL_PROCESS(count); + + RS_SERIAL_PROCESS(ts); + } + + ~MessageInfo() override = default; +}; + +typedef std::set MsgTagInfo ; + +struct MsgInfoSummary : RsSerializable +{ + MsgInfoSummary() : msgflags(0), count(0), ts(0) {} + + RsMailMessageId msgId; + MsgAddress from; + MsgAddress to; // specific address the message has been sent to (may be used for e.g. reply) + + uint32_t msgflags; // combination of flags from rsmail.h (RS_MSG_OUTGOING, etc) + MsgTagInfo msgtags; + + std::string title; + int count; /** file count */ + rstime_t ts; + + std::set destinations; // all destinations of the message + + /// @see RsSerializable + void serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext &ctx) override + { + RS_SERIAL_PROCESS(msgId); + RS_SERIAL_PROCESS(from); + RS_SERIAL_PROCESS(to); + + RS_SERIAL_PROCESS(msgflags); + RS_SERIAL_PROCESS(msgtags); + + RS_SERIAL_PROCESS(title); + RS_SERIAL_PROCESS(count); + RS_SERIAL_PROCESS(ts); + + RS_SERIAL_PROCESS(destinations); + } + + ~MsgInfoSummary() override = default; +}; + +//struct MsgTagInfo : RsSerializable +//{ +// virtual ~MsgTagInfo() = default; +// +// std::string msgId; +// std::set tagIds; +// +// // RsSerializable interface +// void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { +// RS_SERIAL_PROCESS(msgId); +// RS_SERIAL_PROCESS(tagIds); +// } +//}; + +struct MsgTagType : RsSerializable +{ + virtual ~MsgTagType() = default; + /* map containing tagId -> pair (text, rgb color) */ + std::map > types; + + // RsSerializable interface + void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { + RS_SERIAL_PROCESS(types); + } +}; + +} //namespace Rs +} //namespace Msgs + +enum class RsMailStatusEventCode: uint8_t +{ + UNKNOWN = 0x00, + NEW_MESSAGE = 0x01, + MESSAGE_REMOVED = 0x02, + MESSAGE_SENT = 0x03, + + /// means the peer received the message + MESSAGE_RECEIVED_ACK = 0x04, + + /// An error occurred attempting to sign the message + SIGNATURE_FAILED = 0x05, + + MESSAGE_CHANGED = 0x06, + TAG_CHANGED = 0x07, +}; + +struct RsMailStatusEvent : RsEvent +{ + RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS) {} + + RsMailStatusEventCode mMailStatusEventCode; + std::set mChangedMsgIds; + + /// @see RsEvent + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mChangedMsgIds); + RS_SERIAL_PROCESS(mMailStatusEventCode); + } + + ~RsMailStatusEvent() override = default; +}; + +enum class RsMailTagEventCode: uint8_t +{ + TAG_ADDED = 0x00, + TAG_CHANGED = 0x01, + TAG_REMOVED = 0x02, +}; + +struct RsMailTagEvent : RsEvent +{ + RsMailTagEvent() : RsEvent(RsEventType::MAIL_TAG) {} + + RsMailTagEventCode mMailTagEventCode; + std::set mChangedMsgTagIds; + + /// @see RsEvent + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mChangedMsgTagIds); + RS_SERIAL_PROCESS(mMailTagEventCode); + } + + ~RsMailTagEvent() override = default; +}; + +// flags to define who we accept to talk to. Each flag *removes* some people. + +#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NONE 0x0000 +#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS 0x0001 +#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY 0x0002 + +class RsMail; +/** + * @brief Pointer to retroshare's message service + * @jsonapi{development} + */ +extern RsMail *rsMail; + +class RsMail +{ +public: + + /** + * @brief getMessageSummaries + * @jsonapi{development} + * @param[in] box + * @param[out] msgList + * @return always true + */ + virtual bool getMessageSummaries(Rs::Mail::BoxName box,std::list &msgList) = 0; + + /** + * @brief getMessage + * @jsonapi{development} + * @param[in] msgId message ID to lookup + * @param[out] msg + * @return true on success + */ + virtual bool getMessage(const std::string &msgId, Rs::Mail::MessageInfo &msg) = 0; + + /** + * @brief sendMail + * @jsonapi{development} + * @param[in] from GXS id of the author + * @param[in] subject Mail subject + * @param[in] mailBody Mail body + * @param[in] to list of To: recipients + * @param[in] cc list of CC: recipients + * @param[in] bcc list of BCC: recipients + * @param[in] attachments list of suggested files + * @param[out] trackingIds storage for tracking ids for each sent mail + * @param[out] errorMsg error message if errors occurred, empty otherwise + * @return number of successfully sent mails + */ + virtual uint32_t sendMail( + const RsGxsId from, + const std::string& subject, + const std::string& mailBody, + const std::set& to = std::set(), + const std::set& cc = std::set(), + const std::set& bcc = std::set(), + const std::vector& attachments = std::vector(), + std::set& trackingIds = + RS_DEFAULT_STORAGE_PARAM(std::set), + std::string& errorMsg = + RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0; + + /** + * @brief getMessageCount + * @jsonapi{development} + * @param[out] nInbox + * @param[out] nInboxNew + * @param[out] nOutbox + * @param[out] nDraftbox + * @param[out] nSentbox + * @param[out] nTrashbox + */ + virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox) = 0; + + /** + * @brief SystemMessage + * @jsonapi{development} + * @param[in] title + * @param[in] message + * @param[in] systemFlag + * @return true on success + */ + virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) = 0; + + /** + * @brief MessageToDraft + * @jsonapi{development} + * @param[in] info + * @param[in] msgParentId + * @return true on success + */ + virtual bool MessageToDraft(Rs::Mail::MessageInfo &info, const std::string &msgParentId) = 0; + + /** + * @brief MessageToTrash + * @jsonapi{development} + * @param[in] msgId Id of the message to mode to trash box + * @param[in] bTrash Move to trash if true, otherwise remove from trash + * @return true on success + */ + virtual bool MessageToTrash(const std::string &msgId, bool bTrash) = 0; + + /** + * @brief getMsgParentId + * @jsonapi{development} + * @param[in] msgId + * @param[out] msgParentId + * @return true on success + */ + virtual bool getMsgParentId(const std::string &msgId, std::string &msgParentId) = 0; + + /** + * @brief MessageDelete + * @jsonapi{development} + * @param[in] msgId + * @return true on success + */ + virtual bool MessageDelete(const std::string &msgId) = 0; + + /** + * @brief MessageRead + * @jsonapi{development} + * @param[in] msgId + * @param[in] unreadByUser + * @return true on success + */ + virtual bool MessageRead(const std::string &msgId, bool unreadByUser) = 0; + + /** + * @brief MessageReplied + * @jsonapi{development} + * @param[in] msgId + * @param[in] replied + * @return true on success + */ + virtual bool MessageReplied(const std::string &msgId, bool replied) = 0; + + /** + * @brief MessageForwarded + * @jsonapi{development} + * @param[in] msgId + * @param[in] forwarded + * @return true on success + */ + virtual bool MessageForwarded(const std::string &msgId, bool forwarded) = 0; + + /** + * @brief MessageStar + * @jsonapi{development} + * @param[in] msgId + * @param[in] mark + * @return true on success + */ + virtual bool MessageStar(const std::string &msgId, bool mark) = 0; + + /** + * @brief MessageJunk + * @jsonapi{development} + * @param[in] msgId + * @param[in] mark + * @return true on success + */ + virtual bool MessageJunk(const std::string &msgId, bool mark) = 0; + + /** + * @brief MessageLoadEmbeddedImages + * @jsonapi{development} + * @param[in] msgId + * @param[in] load + * @return true on success + */ + virtual bool MessageLoadEmbeddedImages(const std::string &msgId, bool load) = 0; + + /* message tagging */ + /** + * @brief getMessageTagTypes + * @jsonapi{development} + * @param[out] tags + * @return always true + */ + virtual bool getMessageTagTypes(Rs::Mail::MsgTagType& tags) = 0; + + /** + * @brief setMessageTagType + * @jsonapi{development} + * @param[in] tagId + * @param[in] text + * @param[in] rgb_color + * @return true on success + */ + virtual bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color) = 0; + + /** + * @brief removeMessageTagType + * @jsonapi{development} + * @param[in] tagId + * @return true on success + */ + virtual bool removeMessageTagType(uint32_t tagId) = 0; + + /** + * @brief getMessageTag + * @jsonapi{development} + * @param[in] msgId + * @param[out] info + * @return true on success + */ + virtual bool getMessageTag(const std::string &msgId, Rs::Mail::MsgTagInfo& info) = 0; + + /** + * @brief setMessageTag + * @jsonapi{development} + * @param[in] msgId + * @param[in] tagId TagID to set/unset. Use set == false && tagId == 0 remove all tags + * @param[in] set + * @return true on success + */ + virtual bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set) = 0; + + /** + * @brief resetMessageStandardTagTypes + * @jsonapi{development} + * @param[out] tags + * @return always true + */ + virtual bool resetMessageStandardTagTypes(Rs::Mail::MsgTagType& tags) = 0; + + /****************************************/ + /* Private distant messages */ + /****************************************/ + + /** + * @brief getDistantMessagingPermissionFlags get the distant messaging permission flags + * @jsonapi{development} + * @return distant messaging permission flags as a uint32_t. + */ + virtual uint32_t getDistantMessagingPermissionFlags() = 0 ; + /** + * @brief setDistantMessagingPermissionFlags set the distant messaging permission flags + * @jsonapi{development} + * @param[in] flags + */ + virtual void setDistantMessagingPermissionFlags(uint32_t flags) = 0 ; + + /** + * @brief MessageSend + * @jsonapi{development} + * @param[in] info + * @return always true + */ + RS_DEPRECATED_FOR(sendMail) + virtual bool MessageSend(Rs::Mail::MessageInfo &info) = 0; + + virtual ~RsMail() = default; +}; diff --git a/src/retroshare/rsmsgs.h b/src/retroshare/rsmsgs.h deleted file mode 100644 index c0103a583..000000000 --- a/src/retroshare/rsmsgs.h +++ /dev/null @@ -1,1206 +0,0 @@ -/******************************************************************************* - * libretroshare/src/retroshare: rsmsgs.h * - * * - * libretroshare: retroshare core library * - * * - * Copyright (C) 2007-2008 Robert Fernie * - * Copyright (C) 2016-2019 Gioacchino Mazzurco * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License as * - * published by the Free Software Foundation, either version 3 of the * - * License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ -#pragma once - -#include -#include -#include -#include -#include - -#include "retroshare/rstypes.h" -#include "retroshare/rsgxsifacetypes.h" -#include "retroshare/rsevents.h" -#include "util/rsdeprecate.h" -#include "util/rsmemory.h" - -/********************** For Messages and Channels *****************/ - -#define RS_MSG_BOXMASK 0x000f /* Mask for determining Box */ - -#define RS_MSG_OUTGOING 0x0001 /* !Inbox */ -#define RS_MSG_PENDING 0x0002 /* OutBox */ -#define RS_MSG_DRAFT 0x0004 /* Draft */ - -/* ORs of above */ -#define RS_MSG_INBOX 0x00 /* Inbox */ -#define RS_MSG_SENTBOX 0x01 /* Sentbox = OUTGOING */ -#define RS_MSG_OUTBOX 0x03 /* Outbox = OUTGOING + PENDING */ -#define RS_MSG_DRAFTBOX 0x05 /* Draftbox = OUTGOING + DRAFT */ -#define RS_MSG_TRASHBOX 0x20 /* Trashbox = RS_MSG_TRASH */ - -#define RS_MSG_NEW 0x000010 /* New */ -#define RS_MSG_TRASH 0x000020 /* Trash */ -#define RS_MSG_UNREAD_BY_USER 0x000040 /* Unread by user */ -#define RS_MSG_REPLIED 0x000080 /* Message is replied */ -#define RS_MSG_FORWARDED 0x000100 /* Message is forwarded */ -#define RS_MSG_STAR 0x000200 /* Message is marked with a star */ -// system message -#define RS_MSG_USER_REQUEST 0x000400 /* user request */ -#define RS_MSG_FRIEND_RECOMMENDATION 0x000800 /* friend recommendation */ -#define RS_MSG_DISTANT 0x001000 /* message is distant */ -#define RS_MSG_SIGNATURE_CHECKS 0x002000 /* message was signed, and signature checked */ -#define RS_MSG_SIGNED 0x004000 /* message was signed and signature didn't check */ -#define RS_MSG_LOAD_EMBEDDED_IMAGES 0x008000 /* load embedded images */ -#define RS_MSG_PUBLISH_KEY 0x020000 /* publish key */ -#define RS_MSG_SPAM 0x040000 /* Message is marked as spam */ - -#define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_FRIEND_RECOMMENDATION | RS_MSG_PUBLISH_KEY) - -#define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01 -#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02 -#define RS_CHAT_LOBBY_EVENT_PEER_JOINED 0x03 -#define RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME 0x04 -#define RS_CHAT_LOBBY_EVENT_KEEP_ALIVE 0x05 - -#define RS_MSGTAGTYPE_IMPORTANT 1 -#define RS_MSGTAGTYPE_WORK 2 -#define RS_MSGTAGTYPE_PERSONAL 3 -#define RS_MSGTAGTYPE_TODO 4 -#define RS_MSGTAGTYPE_LATER 5 -#define RS_MSGTAGTYPE_USER 100 - -//#define RS_CHAT_LOBBY_PRIVACY_LEVEL_CHALLENGE 0 /* Used to accept connection challenges only. */ -//#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC 1 /* lobby is visible by friends. Friends can connect.*/ -//#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE 2 /* lobby invisible by friends. Peers on invitation only .*/ - -#define RS_CHAT_TYPE_PUBLIC 1 -#define RS_CHAT_TYPE_PRIVATE 2 -#define RS_CHAT_TYPE_LOBBY 3 -#define RS_CHAT_TYPE_DISTANT 4 - -const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE( 0x00000001 ) ; -const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_deprecated ( 0x00000002 ) ; -const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PUBLIC ( 0x00000004 ) ; -const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_CHALLENGE ( 0x00000008 ) ; -const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ( 0x00000010 ) ; // requires the signing ID to be PGP-linked. Avoids anonymous crap. - -typedef uint64_t ChatLobbyId ; -typedef uint64_t ChatLobbyMsgId ; -typedef std::string ChatLobbyNickName ; -typedef std::string RsMailMessageId; // TODO: rebase on t_RsGenericIdType - - -/** - * Used to return a tracker id so the API user can keep track of sent mail - * status, it contains mail id, and recipient id - */ -struct RsMailIdRecipientIdPair : RsSerializable -{ - RsMailIdRecipientIdPair(RsMailMessageId mailId, RsGxsId recipientId): - mMailId(mailId), mRecipientId(recipientId) {} - - RsMailMessageId mMailId; - RsGxsId mRecipientId; - - /// @see RsSerializable - void serial_process( - RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext &ctx ) override; - - bool operator<(const RsMailIdRecipientIdPair& other) const; - bool operator==(const RsMailIdRecipientIdPair& other) const; - - RsMailIdRecipientIdPair() = default; - ~RsMailIdRecipientIdPair() override = default; -}; - -namespace Rs -{ -namespace Msgs -{ - -enum class BoxName:uint8_t { - BOX_NONE = 0x00, - BOX_INBOX = 0x01, - BOX_OUTBOX = 0x02, - BOX_DRAFTS = 0x03, - BOX_SENT = 0x04, - BOX_TRASH = 0x05, - BOX_ALL = 0x06 - }; - -class MsgAddress: public RsSerializable -{ - public: - MsgAddress() : _type(MSG_ADDRESS_TYPE_UNKNOWN),_mode(MSG_ADDRESS_MODE_UNKNOWN) {} - - typedef enum { MSG_ADDRESS_TYPE_UNKNOWN = 0x00, - MSG_ADDRESS_TYPE_RSPEERID = 0x01, - MSG_ADDRESS_TYPE_RSGXSID = 0x02, - MSG_ADDRESS_TYPE_PLAIN = 0x03 } AddressType; - - typedef enum { MSG_ADDRESS_MODE_UNKNOWN = 0x00, - MSG_ADDRESS_MODE_TO = 0x01, - MSG_ADDRESS_MODE_CC = 0x02, - MSG_ADDRESS_MODE_BCC = 0x03 } AddressMode; - - explicit MsgAddress(const RsGxsId& gid, MsgAddress::AddressMode mmode) - : _type(MSG_ADDRESS_TYPE_RSGXSID), _mode(mmode), _addr_string(gid.toStdString()){} - - explicit MsgAddress(const RsPeerId& pid, MsgAddress::AddressMode mmode) - : _type(MSG_ADDRESS_TYPE_RSPEERID), _mode(mmode), _addr_string(pid.toStdString()){} - - explicit MsgAddress(const std::string& email, MsgAddress::AddressMode mmode) - : _type(MSG_ADDRESS_TYPE_PLAIN), _mode(mmode), _addr_string(email){} - - void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx ) override - { - RS_SERIAL_PROCESS(_type); - RS_SERIAL_PROCESS(_mode); - RS_SERIAL_PROCESS(_addr_string); - } - - MsgAddress::AddressType type() const { return _type ;} - MsgAddress::AddressMode mode() const { return _mode ;} - - RsGxsId toGxsId() const { checkType(MSG_ADDRESS_TYPE_RSGXSID);return RsGxsId (_addr_string);} - RsPeerId toRsPeerId() const { checkType(MSG_ADDRESS_TYPE_RSPEERID);return RsPeerId(_addr_string);} - std::string toEmail() const { checkType(MSG_ADDRESS_TYPE_PLAIN );return _addr_string ;} - std::string toStdString() const { return _addr_string ;} - - void clear() { _addr_string=""; _type=MSG_ADDRESS_TYPE_UNKNOWN; _mode=MSG_ADDRESS_MODE_UNKNOWN;} - void checkType(MsgAddress::AddressType t) const - { - if(t != _type) - RsErr() << "WRONG TYPE in MsgAddress. This is not a good sign. Something's going wrong." ; - } - bool operator<(const MsgAddress& m) const { return _addr_string < m._addr_string; } - private: - AddressType _type ; - AddressMode _mode ; - std::string _addr_string ; -}; - -struct MessageInfo : RsSerializable -{ - MessageInfo(): msgflags(0), size(0), count(0), ts(0) {} - - std::string msgId; - - MsgAddress from; - MsgAddress to; - - unsigned int msgflags; - - std::set destinations; - - std::string title; - std::string msg; - - std::string attach_title; - std::string attach_comment; - std::list files; - - int size; /* total of files */ - int count; /* file count */ - - int ts; - - // RsSerializable interface - void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx ) override - { - RS_SERIAL_PROCESS(msgId); - - RS_SERIAL_PROCESS(from); - RS_SERIAL_PROCESS(to); - RS_SERIAL_PROCESS(destinations); - RS_SERIAL_PROCESS(msgflags); - - RS_SERIAL_PROCESS(title); - RS_SERIAL_PROCESS(msg); - - RS_SERIAL_PROCESS(attach_title); - RS_SERIAL_PROCESS(attach_comment); - RS_SERIAL_PROCESS(files); - - RS_SERIAL_PROCESS(size); - RS_SERIAL_PROCESS(count); - - RS_SERIAL_PROCESS(ts); - } - - ~MessageInfo() override; -}; - -typedef std::set MsgTagInfo ; - -struct MsgInfoSummary : RsSerializable -{ - MsgInfoSummary() : msgflags(0), count(0), ts(0) {} - - RsMailMessageId msgId; - MsgAddress from; - MsgAddress to; // specific address the message has been sent to (may be used for e.g. reply) - - uint32_t msgflags; // combination of flags from rsmsgs.h (RS_MSG_OUTGOING, etc) - MsgTagInfo msgtags; - - std::string title; - int count; /** file count */ - rstime_t ts; - - std::set destinations; // all destinations of the message - - /// @see RsSerializable - void serial_process( - RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext &ctx) override - { - RS_SERIAL_PROCESS(msgId); - RS_SERIAL_PROCESS(from); - RS_SERIAL_PROCESS(to); - - RS_SERIAL_PROCESS(msgflags); - RS_SERIAL_PROCESS(msgtags); - - RS_SERIAL_PROCESS(title); - RS_SERIAL_PROCESS(count); - RS_SERIAL_PROCESS(ts); - - RS_SERIAL_PROCESS(destinations); - } - - ~MsgInfoSummary() override; -}; - -//struct MsgTagInfo : RsSerializable -//{ -// virtual ~MsgTagInfo() = default; -// -// std::string msgId; -// std::set tagIds; -// -// // RsSerializable interface -// void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { -// RS_SERIAL_PROCESS(msgId); -// RS_SERIAL_PROCESS(tagIds); -// } -//}; - -struct MsgTagType : RsSerializable -{ - virtual ~MsgTagType() = default; - /* map containing tagId -> pair (text, rgb color) */ - std::map > types; - - // RsSerializable interface - void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { - RS_SERIAL_PROCESS(types); - } -}; - -} //namespace Rs -} //namespace Msgs - -enum class RsMailStatusEventCode: uint8_t -{ - UNKNOWN = 0x00, - NEW_MESSAGE = 0x01, - MESSAGE_REMOVED = 0x02, - MESSAGE_SENT = 0x03, - - /// means the peer received the message - MESSAGE_RECEIVED_ACK = 0x04, - - /// An error occurred attempting to sign the message - SIGNATURE_FAILED = 0x05, - - MESSAGE_CHANGED = 0x06, - TAG_CHANGED = 0x07, -}; - -struct RsMailStatusEvent : RsEvent -{ - RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS) {} - - RsMailStatusEventCode mMailStatusEventCode; - std::set mChangedMsgIds; - - /// @see RsEvent - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx) override - { - RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mChangedMsgIds); - RS_SERIAL_PROCESS(mMailStatusEventCode); - } - - ~RsMailStatusEvent() override = default; -}; - -enum class RsMailTagEventCode: uint8_t -{ - TAG_ADDED = 0x00, - TAG_CHANGED = 0x01, - TAG_REMOVED = 0x02, -}; - -struct RsMailTagEvent : RsEvent -{ - RsMailTagEvent() : RsEvent(RsEventType::MAIL_TAG) {} - - RsMailTagEventCode mMailTagEventCode; - std::set mChangedMsgTagIds; - - /// @see RsEvent - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx) override - { - RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mChangedMsgTagIds); - RS_SERIAL_PROCESS(mMailTagEventCode); - } - - ~RsMailTagEvent() override = default; -}; - -#define RS_CHAT_PUBLIC 0x0001 -#define RS_CHAT_PRIVATE 0x0002 -#define RS_CHAT_AVATAR_AVAILABLE 0x0004 - -#define RS_DISTANT_CHAT_STATUS_UNKNOWN 0x0000 -#define RS_DISTANT_CHAT_STATUS_TUNNEL_DN 0x0001 -#define RS_DISTANT_CHAT_STATUS_CAN_TALK 0x0002 -#define RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED 0x0003 - -#define RS_DISTANT_CHAT_ERROR_NO_ERROR 0x0000 -#define RS_DISTANT_CHAT_ERROR_DECRYPTION_FAILED 0x0001 -#define RS_DISTANT_CHAT_ERROR_SIGNATURE_MISMATCH 0x0002 -#define RS_DISTANT_CHAT_ERROR_UNKNOWN_KEY 0x0003 -#define RS_DISTANT_CHAT_ERROR_UNKNOWN_HASH 0x0004 - -#define RS_DISTANT_CHAT_FLAG_SIGNED 0x0001 -#define RS_DISTANT_CHAT_FLAG_SIGNATURE_OK 0x0002 - -// flags to define who we accept to talk to. Each flag *removes* some people. - -#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NONE 0x0000 -#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS 0x0001 -#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY 0x0002 - -#define RS_DISTANT_CHAT_CONTACT_PERMISSION_FLAG_FILTER_NONE 0x0000 -#define RS_DISTANT_CHAT_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS 0x0001 -#define RS_DISTANT_CHAT_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY 0x0002 - -struct DistantChatPeerInfo : RsSerializable -{ - DistantChatPeerInfo() : status(0),pending_items(0) {} - - RsGxsId to_id ; - RsGxsId own_id ; - DistantChatPeerId peer_id ; // this is the tunnel id actually - uint32_t status ; // see the values in rsmsgs.h - uint32_t pending_items; // items not sent, waiting for a tunnel - - ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override - { - RS_SERIAL_PROCESS(to_id); - RS_SERIAL_PROCESS(own_id); - RS_SERIAL_PROCESS(peer_id); - RS_SERIAL_PROCESS(status); - RS_SERIAL_PROCESS(pending_items); - } -}; - -enum class RsChatHistoryChangeFlags: uint8_t -{ - SAME = 0x00, - MOD = 0x01, /* general purpose, check all */ - ADD = 0x02, /* flagged additions */ - DEL = 0x04, /* flagged deletions */ -}; -RS_REGISTER_ENUM_FLAGS_TYPE(RsChatHistoryChangeFlags); - -// Identifier for an chat endpoint like -// neighbour peer, distant peer, chatlobby, broadcast -class ChatId : RsSerializable -{ -public: - ChatId(); - virtual ~ChatId() = default; - - explicit ChatId(RsPeerId id); - explicit ChatId(ChatLobbyId id); - explicit ChatId(DistantChatPeerId id); - explicit ChatId(std::string str); - static ChatId makeBroadcastId(); - - std::string toStdString() const; - bool operator<(const ChatId& other) const; - bool isSameEndpoint(const ChatId& other) const; - - bool operator==(const ChatId& other) const { return isSameEndpoint(other) ; } - - bool isNotSet() const; - bool isPeerId() const; - bool isDistantChatId() const; - bool isLobbyId() const; - bool isBroadcast() const; - - RsPeerId toPeerId() const; - ChatLobbyId toLobbyId() const; - DistantChatPeerId toDistantChatId() const; - - // for the very specific case of transfering a status string - // from the chatservice to the gui, - // this defines from which peer the status string came from - RsPeerId broadcast_status_peer_id; -private: - enum Type : uint8_t - { TYPE_NOT_SET, - TYPE_PRIVATE, // private chat with directly connected friend, peer_id is valid - TYPE_PRIVATE_DISTANT, // private chat with distant peer, gxs_id is valid - TYPE_LOBBY, // chat lobby id, lobby_id is valid - TYPE_BROADCAST // message to/from all connected peers - }; - - Type type; - RsPeerId peer_id; - DistantChatPeerId distant_chat_id; - ChatLobbyId lobby_id; - - // RsSerializable interface -public: - void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { - RS_SERIAL_PROCESS(broadcast_status_peer_id); - RS_SERIAL_PROCESS(type); - RS_SERIAL_PROCESS(peer_id); - RS_SERIAL_PROCESS(distant_chat_id); - RS_SERIAL_PROCESS(lobby_id); - } -}; - -struct ChatMessage : RsSerializable -{ - ChatId chat_id; // id of chat endpoint - RsPeerId broadcast_peer_id; // only used for broadcast chat: source peer id - RsGxsId lobby_peer_gxs_id; // only used for lobbys: nickname of message author - std::string peer_alternate_nickname; // only used when key is unknown. - - unsigned int chatflags; - uint32_t sendTime; - uint32_t recvTime; - std::string msg; - bool incoming; - bool online; // for outgoing messages: was this message send? - //bool system_message; - - ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override - { - RS_SERIAL_PROCESS(chat_id); - RS_SERIAL_PROCESS(broadcast_peer_id); - RS_SERIAL_PROCESS(lobby_peer_gxs_id); - RS_SERIAL_PROCESS(peer_alternate_nickname); - - RS_SERIAL_PROCESS(chatflags); - RS_SERIAL_PROCESS(sendTime); - RS_SERIAL_PROCESS(recvTime); - RS_SERIAL_PROCESS(msg); - RS_SERIAL_PROCESS(incoming); - RS_SERIAL_PROCESS(online); - } -}; - -class ChatLobbyInvite : RsSerializable -{ -public: - virtual ~ChatLobbyInvite() = default; - - ChatLobbyId lobby_id ; - RsPeerId peer_id ; - std::string lobby_name ; - std::string lobby_topic ; - ChatLobbyFlags lobby_flags ; - - // RsSerializable interface -public: - void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { - RS_SERIAL_PROCESS(lobby_id); - RS_SERIAL_PROCESS(peer_id); - RS_SERIAL_PROCESS(lobby_name); - RS_SERIAL_PROCESS(lobby_topic); - RS_SERIAL_PROCESS(lobby_flags); - } -}; - -enum class RsChatServiceEventCode: uint8_t -{ - UNKNOWN = 0x00, - - CHAT_MESSAGE_RECEIVED = 0x01, // new private incoming chat, NOTIFY_LIST_PRIVATE_INCOMING_CHAT - CHAT_STATUS_CHANGED = 0x02, // - CHAT_HISTORY_CHANGED = 0x03, // -}; - -enum class RsChatLobbyEventCode: uint8_t -{ - UNKNOWN = 0x00, - - CHAT_LOBBY_LIST_CHANGED = 0x03, // NOTIFY_LIST_CHAT_LOBBY_LIST , ADD/REMOVE , // new/removed chat lobby - CHAT_LOBBY_INVITE_RECEIVED = 0x04, // NOTIFY_LIST_CHAT_LOBBY_INVITE, received chat lobby invite - CHAT_LOBBY_EVENT_PEER_LEFT = 0x05, // RS_CHAT_LOBBY_EVENT_PEER_LEFT - CHAT_LOBBY_EVENT_PEER_STATUS = 0x06, // RS_CHAT_LOBBY_EVENT_PEER_STATUS - CHAT_LOBBY_EVENT_PEER_JOINED = 0x07, // RS_CHAT_LOBBY_EVENT_PEER_JOINED - CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME = 0x08, // RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME - CHAT_LOBBY_EVENT_KEEP_ALIVE = 0x09, // RS_CHAT_LOBBY_EVENT_KEEP_ALIVE -}; - -enum class RsDistantChatEventCode: uint8_t -{ - TUNNEL_STATUS_UNKNOWN = 0x00, - TUNNEL_STATUS_CAN_TALK = 0x01, - TUNNEL_STATUS_TUNNEL_DN = 0x02, - TUNNEL_STATUS_REMOTELY_CLOSED = 0x03, - TUNNEL_STATUS_CONNECTION_REFUSED = 0x04, -}; - -struct RsChatLobbyEvent : RsEvent // This event handles events internal to the distributed chat system -{ - RsChatLobbyEvent() : RsEvent(RsEventType::CHAT_SERVICE),mEventCode(RsChatLobbyEventCode::UNKNOWN),mLobbyId(0),mTimeShift(0) {} - virtual ~RsChatLobbyEvent() override = default; - - RsChatLobbyEventCode mEventCode; - - uint64_t mLobbyId; - RsGxsId mGxsId; - std::string mStr; - ChatMessage mMsg; - int mTimeShift; - - void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) override { - - RsEvent::serial_process(j,ctx); - - RS_SERIAL_PROCESS(mEventCode); - RS_SERIAL_PROCESS(mLobbyId); - RS_SERIAL_PROCESS(mGxsId); - RS_SERIAL_PROCESS(mStr); - RS_SERIAL_PROCESS(mMsg); - RS_SERIAL_PROCESS(mTimeShift); - } -}; - -struct RsDistantChatEvent : RsEvent // This event handles events internal to the distant chat system -{ - RsDistantChatEvent() : RsEvent(RsEventType::CHAT_SERVICE),mEventCode(RsDistantChatEventCode::TUNNEL_STATUS_UNKNOWN) {} - virtual ~RsDistantChatEvent() override = default; - - RsDistantChatEventCode mEventCode; - DistantChatPeerId mId; - - void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) override { - - RsEvent::serial_process(j,ctx); - - RS_SERIAL_PROCESS(mEventCode); - RS_SERIAL_PROCESS(mId); - } -}; - -struct RsChatServiceEvent : RsEvent // This event handles chat in general: status strings, new messages, etc. -{ - RsChatServiceEvent() : RsEvent(RsEventType::CHAT_SERVICE), mEventCode(RsChatServiceEventCode::UNKNOWN), - mMsgHistoryId(0),mHistoryChangeType(RsChatHistoryChangeFlags::SAME) {} - virtual ~RsChatServiceEvent() override = default; - - RsChatServiceEventCode mEventCode; - - std::string mStr; - ChatId mCid; - ChatMessage mMsg; - uint32_t mMsgHistoryId; - RsChatHistoryChangeFlags mHistoryChangeType; // ChatHistoryChangeFlags::ADD/DEL/MOD - - void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) override { - - RsEvent::serial_process(j,ctx); - - RS_SERIAL_PROCESS(mEventCode); - RS_SERIAL_PROCESS(mStr); - RS_SERIAL_PROCESS(mCid); - RS_SERIAL_PROCESS(mMsg); - RS_SERIAL_PROCESS(mMsgHistoryId); - RS_SERIAL_PROCESS(mHistoryChangeType); - } -}; - -struct VisibleChatLobbyRecord : RsSerializable -{ - VisibleChatLobbyRecord(): - lobby_id(0), total_number_of_peers(0), last_report_time(0) {} - virtual ~VisibleChatLobbyRecord() override = default; - - ChatLobbyId lobby_id ; // unique id of the lobby - std::string lobby_name ; // name to use for this lobby - std::string lobby_topic ; // topic to use for this lobby - std::set participating_friends ; // list of direct friend who participate. - - uint32_t total_number_of_peers ; // total number of particpating peers. Might not be - rstime_t last_report_time ; // last time the lobby was reported. - ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE - - /// @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) override { - RS_SERIAL_PROCESS(lobby_id); - RS_SERIAL_PROCESS(lobby_name); - RS_SERIAL_PROCESS(lobby_topic); - RS_SERIAL_PROCESS(participating_friends); - - RS_SERIAL_PROCESS(total_number_of_peers); - RS_SERIAL_PROCESS(last_report_time); - RS_SERIAL_PROCESS(lobby_flags); - } -}; - -class ChatLobbyInfo : RsSerializable -{ -public: - virtual ~ChatLobbyInfo() = default; - - ChatLobbyId lobby_id ; // unique id of the lobby - std::string lobby_name ; // name to use for this lobby - std::string lobby_topic ; // topic to use for this lobby - std::set participating_friends ; // list of direct friend who participate. Used to broadcast sent messages. - RsGxsId gxs_id ; // ID to sign messages - - ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE - std::map gxs_ids ; // list of non direct friend who participate. Used to display only. - rstime_t last_activity ; // last recorded activity. Useful for removing dead lobbies. - - virtual void clear() { gxs_ids.clear(); lobby_id = 0; lobby_name.clear(); lobby_topic.clear(); participating_friends.clear(); } - - // RsSerializable interface -public: - void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { - RS_SERIAL_PROCESS(lobby_id); - RS_SERIAL_PROCESS(lobby_name); - RS_SERIAL_PROCESS(lobby_topic); - RS_SERIAL_PROCESS(participating_friends); - RS_SERIAL_PROCESS(gxs_id); - - RS_SERIAL_PROCESS(lobby_flags); - RS_SERIAL_PROCESS(gxs_ids); - RS_SERIAL_PROCESS(last_activity); - } -}; - - -class RsMsgs; -/** - * @brief Pointer to retroshare's message service - * @jsonapi{development} - */ -extern RsMsgs* rsMsgs; - -class RsMsgs -{ -public: - - /** - * @brief getMessageSummaries - * @jsonapi{development} - * @param[in] box - * @param[out] msgList - * @return always true - */ - virtual bool getMessageSummaries(Rs::Msgs::BoxName box,std::list &msgList) = 0; - - /** - * @brief getMessage - * @jsonapi{development} - * @param[in] msgId message ID to lookup - * @param[out] msg - * @return true on success - */ - virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0; - - /** - * @brief sendMail - * @jsonapi{development} - * @param[in] from GXS id of the author - * @param[in] subject Mail subject - * @param[in] mailBody Mail body - * @param[in] to list of To: recipients - * @param[in] cc list of CC: recipients - * @param[in] bcc list of BCC: recipients - * @param[in] attachments list of suggested files - * @param[out] trackingIds storage for tracking ids for each sent mail - * @param[out] errorMsg error message if errors occurred, empty otherwise - * @return number of successfully sent mails - */ - virtual uint32_t sendMail( - const RsGxsId from, - const std::string& subject, - const std::string& mailBody, - const std::set& to = std::set(), - const std::set& cc = std::set(), - const std::set& bcc = std::set(), - const std::vector& attachments = std::vector(), - std::set& trackingIds = - RS_DEFAULT_STORAGE_PARAM(std::set), - std::string& errorMsg = - RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0; - - /** - * @brief getMessageCount - * @jsonapi{development} - * @param[out] nInbox - * @param[out] nInboxNew - * @param[out] nOutbox - * @param[out] nDraftbox - * @param[out] nSentbox - * @param[out] nTrashbox - */ - virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox) = 0; - - /** - * @brief SystemMessage - * @jsonapi{development} - * @param[in] title - * @param[in] message - * @param[in] systemFlag - * @return true on success - */ - virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) = 0; - - /** - * @brief MessageToDraft - * @jsonapi{development} - * @param[in] info - * @param[in] msgParentId - * @return true on success - */ - virtual bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId) = 0; - - /** - * @brief MessageToTrash - * @jsonapi{development} - * @param[in] msgId Id of the message to mode to trash box - * @param[in] bTrash Move to trash if true, otherwise remove from trash - * @return true on success - */ - virtual bool MessageToTrash(const std::string &msgId, bool bTrash) = 0; - - /** - * @brief getMsgParentId - * @jsonapi{development} - * @param[in] msgId - * @param[out] msgParentId - * @return true on success - */ - virtual bool getMsgParentId(const std::string &msgId, std::string &msgParentId) = 0; - - /** - * @brief MessageDelete - * @jsonapi{development} - * @param[in] msgId - * @return true on success - */ - virtual bool MessageDelete(const std::string &msgId) = 0; - - /** - * @brief MessageRead - * @jsonapi{development} - * @param[in] msgId - * @param[in] unreadByUser - * @return true on success - */ - virtual bool MessageRead(const std::string &msgId, bool unreadByUser) = 0; - - /** - * @brief MessageReplied - * @jsonapi{development} - * @param[in] msgId - * @param[in] replied - * @return true on success - */ - virtual bool MessageReplied(const std::string &msgId, bool replied) = 0; - - /** - * @brief MessageForwarded - * @jsonapi{development} - * @param[in] msgId - * @param[in] forwarded - * @return true on success - */ - virtual bool MessageForwarded(const std::string &msgId, bool forwarded) = 0; - - /** - * @brief MessageStar - * @jsonapi{development} - * @param[in] msgId - * @param[in] mark - * @return true on success - */ - virtual bool MessageStar(const std::string &msgId, bool mark) = 0; - - /** - * @brief MessageJunk - * @jsonapi{development} - * @param[in] msgId - * @param[in] mark - * @return true on success - */ - virtual bool MessageJunk(const std::string &msgId, bool mark) = 0; - - /** - * @brief MessageLoadEmbeddedImages - * @jsonapi{development} - * @param[in] msgId - * @param[in] load - * @return true on success - */ - virtual bool MessageLoadEmbeddedImages(const std::string &msgId, bool load) = 0; - - /* message tagging */ - /** - * @brief getMessageTagTypes - * @jsonapi{development} - * @param[out] tags - * @return always true - */ - virtual bool getMessageTagTypes(Rs::Msgs::MsgTagType& tags) = 0; - - /** - * @brief setMessageTagType - * @jsonapi{development} - * @param[in] tagId - * @param[in] text - * @param[in] rgb_color - * @return true on success - */ - virtual bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color) = 0; - - /** - * @brief removeMessageTagType - * @jsonapi{development} - * @param[in] tagId - * @return true on success - */ - virtual bool removeMessageTagType(uint32_t tagId) = 0; - - /** - * @brief getMessageTag - * @jsonapi{development} - * @param[in] msgId - * @param[out] info - * @return true on success - */ - virtual bool getMessageTag(const std::string &msgId, Rs::Msgs::MsgTagInfo& info) = 0; - - /** - * @brief setMessageTag - * @jsonapi{development} - * @param[in] msgId - * @param[in] tagId TagID to set/unset. Use set == false && tagId == 0 remove all tags - * @param[in] set - * @return true on success - */ - virtual bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set) = 0; - - /** - * @brief resetMessageStandardTagTypes - * @jsonapi{development} - * @param[out] tags - * @return always true - */ - virtual bool resetMessageStandardTagTypes(Rs::Msgs::MsgTagType& tags) = 0; - - /****************************************/ - /* Private distant messages */ - /****************************************/ - - /** - * @brief getDistantMessagingPermissionFlags get the distant messaging permission flags - * @jsonapi{development} - * @return distant messaging permission flags as a uint32_t. - */ - virtual uint32_t getDistantMessagingPermissionFlags() = 0 ; - /** - * @brief setDistantMessagingPermissionFlags set the distant messaging permission flags - * @jsonapi{development} - * @param[in] flags - */ - virtual void setDistantMessagingPermissionFlags(uint32_t flags) = 0 ; - - /****************************************/ - /* Chat */ - /****************************************/ - // sendChat for broadcast, private, lobby and private distant chat - // note: for lobby chat, you first have to subscribe to a lobby - // for private distant chat, it is reqired to have an active distant chat session - - /** - * @brief sendChat send a chat message to a given id - * @jsonapi{development} - * @param[in] id id to send the message - * @param[in] msg message to send - * @return true on success - */ - virtual bool sendChat(ChatId id, std::string msg) = 0; - - /** - * @brief getMaxMessageSecuritySize get the maximum size of a chat message - * @jsonapi{development} - * @param[in] type chat type - * @return maximum size or zero for infinite - */ - virtual uint32_t getMaxMessageSecuritySize(int type) = 0; - - /** - * @brief sendStatusString send a status string - * @jsonapi{development} - * @param[in] id chat id to send the status string to - * @param[in] status_string status string - */ - virtual void sendStatusString(const ChatId &id, const std::string &status_string) = 0; - - /** - * @brief clearChatLobby clear a chat lobby - * @jsonapi{development} - * @param[in] id chat lobby id to clear - */ - virtual void clearChatLobby(const ChatId &id) = 0; - - /** - * @brief setCustomStateString set your custom status message - * @jsonapi{development} - * @param[in] status_string status message - */ - virtual void setCustomStateString(const std::string &status_string) = 0; - - /** - * @brief getCustomStateString get your custom status message - * @return status message - */ - virtual std::string getCustomStateString() = 0; - - /** - * @brief getCustomStateString get the custom status message from a peer - * @jsonapi{development} - * @param[in] peer_id peer id to the peer you want to get the status message from - * @return status message - */ - virtual std::string getCustomStateString(const RsPeerId &peer_id) = 0; - -// get avatar data for peer pid -virtual void getAvatarData(const RsPeerId& pid,unsigned char *& data,int& size) = 0 ; -// set own avatar data -virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ; -virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ; - - /****************************************/ - /* Chat lobbies */ - /****************************************/ - /** - * @brief joinVisibleChatLobby join a lobby that is visible - * @jsonapi{development} - * @param[in] lobby_id lobby to join to - * @param[in] own_id chat id to use - * @return true on success - */ - virtual bool joinVisibleChatLobby(const ChatLobbyId &lobby_id, const RsGxsId &own_id) = 0 ; - - /** - * @brief getChatLobbyList get ids of subscribed lobbies - * @jsonapi{development} - * @param[out] cl_list lobby list - */ - virtual void getChatLobbyList(std::list &cl_list) = 0; - - /** - * @brief getChatLobbyInfo get lobby info of a subscribed chat lobby. Returns true if lobby id is valid. - * @jsonapi{development} - * @param[in] id id to get infos from - * @param[out] info lobby infos - * @return true on success - */ - virtual bool getChatLobbyInfo(const ChatLobbyId &id, ChatLobbyInfo &info) = 0 ; - - /** - * @brief getListOfNearbyChatLobbies get info about all lobbies, subscribed and unsubscribed - * @jsonapi{development} - * @param[out] public_lobbies list of all visible lobbies - */ - virtual void getListOfNearbyChatLobbies(std::vector &public_lobbies) = 0 ; - - /** - * @brief invitePeerToLobby invite a peer to join a lobby - * @jsonapi{development} - * @param[in] lobby_id lobby it to invite into - * @param[in] peer_id peer to invite - */ - virtual void invitePeerToLobby(const ChatLobbyId &lobby_id, const RsPeerId &peer_id) = 0; - - /** - * @brief acceptLobbyInvite accept a chat invite - * @jsonapi{development} - * @param[in] id chat lobby id you were invited into and you want to join - * @param[in] identity chat identity to use - * @return true on success - */ - virtual bool acceptLobbyInvite(const ChatLobbyId &id, const RsGxsId &identity) = 0 ; - - /** - * @brief denyLobbyInvite deny a chat lobby invite - * @jsonapi{development} - * @param[in] id chat lobby id you were invited into - * @return true on success - */ - virtual bool denyLobbyInvite(const ChatLobbyId &id) = 0 ; - - /** - * @brief getPendingChatLobbyInvites get a list of all pending chat lobby invites - * @jsonapi{development} - * @param[out] invites list of all pending chat lobby invites - */ - virtual void getPendingChatLobbyInvites(std::list &invites) = 0; - - /** - * @brief unsubscribeChatLobby leave a chat lobby - * @jsonapi{development} - * @param[in] lobby_id lobby to leave - */ - virtual void unsubscribeChatLobby(const ChatLobbyId &lobby_id) = 0; - - /** - * @brief sendLobbyStatusPeerLeaving notify friend nodes that we're leaving a subscribed lobby - * @jsonapi{development} - * @param[in] lobby_id lobby to leave - */ - virtual void sendLobbyStatusPeerLeaving(const ChatLobbyId& lobby_id) = 0; - - /** - * @brief setIdentityForChatLobby set the chat identit - * @jsonapi{development} - * @param[in] lobby_id lobby to change the chat idnetity for - * @param[in] nick new chat identity - * @return true on success - */ - virtual bool setIdentityForChatLobby(const ChatLobbyId &lobby_id, const RsGxsId &nick) = 0; - - /** - * @brief getIdentityForChatLobby - * @jsonapi{development} - * @param[in] lobby_id lobby to get the chat id from - * @param[out] nick chat identity - * @return true on success - */ - virtual bool getIdentityForChatLobby(const ChatLobbyId &lobby_id, RsGxsId &nick) = 0 ; - - /** - * @brief setDefaultIdentityForChatLobby set the default identity used for chat lobbies - * @jsonapi{development} - * @param[in] nick chat identitiy to use - * @return true on success - */ - virtual bool setDefaultIdentityForChatLobby(const RsGxsId &nick) = 0; - - /** - * @brief getDefaultIdentityForChatLobby get the default identity used for chat lobbies - * @jsonapi{development} - * @param[out] id chat identitiy to use - */ - virtual void getDefaultIdentityForChatLobby(RsGxsId &id) = 0 ; - - /** - * @brief setLobbyAutoSubscribe enable or disable auto subscribe for a chat lobby - * @jsonapi{development} - * @param[in] lobby_id lobby to auto (un)subscribe - * @param[in] autoSubscribe set value for auto subscribe - */ - virtual void setLobbyAutoSubscribe(const ChatLobbyId &lobby_id, const bool autoSubscribe) = 0 ; - - /** - * @brief getLobbyAutoSubscribe get current value of auto subscribe - * @jsonapi{development} - * @param[in] lobby_id lobby to get value from - * @return wether lobby has auto subscribe enabled or disabled - */ - virtual bool getLobbyAutoSubscribe(const ChatLobbyId &lobby_id) = 0 ; - - /** - * @brief createChatLobby create a new chat lobby - * @jsonapi{development} - * @param[in] lobby_name lobby name - * @param[in] lobby_identity chat id to use for new lobby - * @param[in] lobby_topic lobby toppic - * @param[in] invited_friends list of friends to invite - * @param[in] lobby_privacy_type flag for new chat lobby - * @return chat id of new lobby - */ - virtual ChatLobbyId createChatLobby(const std::string &lobby_name, const RsGxsId &lobby_identity, const std::string &lobby_topic, const std::set &invited_friends, ChatLobbyFlags lobby_privacy_type) = 0 ; - -/****************************************/ -/* Distant chat */ -/****************************************/ - - virtual uint32_t getDistantChatPermissionFlags()=0 ; - virtual bool setDistantChatPermissionFlags(uint32_t flags)=0 ; - - /** - * @brief initiateDistantChatConnexion initiate a connexion for a distant chat - * @jsonapi{development} - * @param[in] to_pid RsGxsId to start the connection - * @param[in] from_pid owned RsGxsId who start the connection - * @param[out] pid distant chat id - * @param[out] error_code if the connection can't be stablished - * @param[in] notify notify remote that the connection is stablished - * @return true on success. If you try to initate a connection already started it will return the pid of it. - */ - virtual bool initiateDistantChatConnexion( - const RsGxsId& to_pid, const RsGxsId& from_pid, - DistantChatPeerId& pid, uint32_t& error_code, - bool notify = true ) = 0; - - /** - * @brief getDistantChatStatus receives distant chat info to a given distant chat id - * @jsonapi{development} - * @param[in] pid distant chat id - * @param[out] info distant chat info - * @return true on success - */ - virtual bool getDistantChatStatus(const DistantChatPeerId& pid, DistantChatPeerInfo& info)=0; - - /** - * @brief closeDistantChatConnexion - * @jsonapi{development} - * @param[in] pid distant chat id to close the connection - * @return true on success - */ - virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0; - - /** - * @brief MessageSend - * @jsonapi{development} - * @param[in] info - * @return always true - */ - RS_DEPRECATED_FOR(sendMail) - virtual bool MessageSend(Rs::Msgs::MessageInfo &info) = 0; - - virtual ~RsMsgs(); -}; diff --git a/src/retroshare/rsplugin.h b/src/retroshare/rsplugin.h index d9c94e4d4..c1a79fd3a 100644 --- a/src/retroshare/rsplugin.h +++ b/src/retroshare/rsplugin.h @@ -41,7 +41,8 @@ class RsReputations ; class RsTurtle ; class RsGxsTunnelService ; class RsDht ; -class RsMsgs ; +class RsMail ; +class RsChats ; class RsGxsForums; class RsGxsChannels; class RsNotify; @@ -111,7 +112,8 @@ class RsPlugInInterfaces { public: RsUtil::inited_ptr mPeers; RsUtil::inited_ptr mFiles; - RsUtil::inited_ptr mMsgs; + RsUtil::inited_ptr mChats; + RsUtil::inited_ptr mMail; RsUtil::inited_ptr mTurtle; RsUtil::inited_ptr mDisc; RsUtil::inited_ptr mDht; diff --git a/src/rsitems/rsmsgitems.h b/src/rsitems/rsmsgitems.h index a01a864c9..a6131cadf 100644 --- a/src/rsitems/rsmsgitems.h +++ b/src/rsitems/rsmsgitems.h @@ -24,7 +24,7 @@ #include #include "retroshare/rstypes.h" -#include "retroshare/rsmsgs.h" +#include "retroshare/rsmail.h" #include "serialiser/rstlvkeys.h" #include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" @@ -185,8 +185,8 @@ struct RsOutgoingMessageInfo: public RsSerializable RS_SERIAL_PROCESS(grouter_id); } - Rs::Msgs::MsgAddress origin; - Rs::Msgs::MsgAddress destination; + Rs::Mail::MsgAddress origin; + Rs::Mail::MsgAddress destination; uint32_t flags; GRouterMsgPropagationId grouter_id; }; @@ -231,9 +231,9 @@ class RsMailStorageItem : public RsMessageItem // ----------- Specific fields ------------- // // - Rs::Msgs::MsgAddress from; - Rs::Msgs::MsgAddress to; - Rs::Msgs::MsgTagInfo tagIds; + Rs::Mail::MsgAddress from; + Rs::Mail::MsgAddress to; + Rs::Mail::MsgTagInfo tagIds; uint32_t parentId; RsMsgItem msg; }; diff --git a/src/rsserver/p3msgs.cc b/src/rsserver/p3msgs.cc index db596b71f..32273bbae 100644 --- a/src/rsserver/p3msgs.cc +++ b/src/rsserver/p3msgs.cc @@ -38,234 +38,12 @@ #include "pqi/authgpg.h" -using namespace Rs::Msgs; +using namespace Rs::Mail; -/*extern*/ RsMsgs* rsMsgs = nullptr; +/*extern*/ RsMail* rsMail = nullptr; /****************************************/ /****************************************/ - -ChatId::ChatId(): - type(TYPE_NOT_SET), - lobby_id(0) -{ - -} - -ChatId::ChatId(RsPeerId id): - lobby_id(0) -{ - type = TYPE_PRIVATE; - peer_id = id; -} - -ChatId::ChatId(DistantChatPeerId id): - lobby_id(0) -{ - type = TYPE_PRIVATE_DISTANT; - distant_chat_id = id; -} - -ChatId::ChatId(ChatLobbyId id): - lobby_id(0) -{ - type = TYPE_LOBBY; - lobby_id = id; -} - -ChatId::ChatId(std::string str) : lobby_id(0) -{ - type = TYPE_NOT_SET; - if(str.empty()) return; - - if(str[0] == 'P') - { - type = TYPE_PRIVATE; - peer_id = RsPeerId(str.substr(1)); - } - else if(str[0] == 'D') - { - type = TYPE_PRIVATE_DISTANT; - distant_chat_id = DistantChatPeerId(str.substr(1)); - } - else if(str[0] == 'L') - { - if(sizeof(ChatLobbyId) != 8) - { - std::cerr << "ChatId::ChatId(std::string) Error: sizeof(ChatLobbyId) != 8. please report this" << std::endl; - return; - } - str = str.substr(1); - if(str.size() != 16) - return; - ChatLobbyId id = 0; - for(int i = 0; i<16; i++) - { - uint8_t c = str[i]; - if(c <= '9') - c -= '0'; - else - c -= 'A' - 10; - id = id << 4; - id |= c; - } - type = TYPE_LOBBY; - lobby_id = id; - } - else if(str[0] == 'B') - { - type = TYPE_BROADCAST; - } -} - -ChatId ChatId::makeBroadcastId() -{ - ChatId id; - id.type = TYPE_BROADCAST; - return id; -} - -std::string ChatId::toStdString() const -{ - std::string str; - if(type == TYPE_PRIVATE) - { - str += "P"; - str += peer_id.toStdString(); - } - else if(type == TYPE_PRIVATE_DISTANT) - { - str += "D"; - str += distant_chat_id.toStdString(); - } - else if(type == TYPE_LOBBY) - { - if(sizeof(ChatLobbyId) != 8) - { - std::cerr << "ChatId::toStdString() Error: sizeof(ChatLobbyId) != 8. please report this" << std::endl; - return ""; - } - str += "L"; - - ChatLobbyId id = lobby_id; - for(int i = 0; i<16; i++) - { - uint8_t c = id >>(64-4); - if(c > 9) - c += 'A' - 10; - else - c += '0'; - str += c; - id = id << 4; - } - } - else if(type == TYPE_BROADCAST) - { - str += "B"; - } - return str; -} - -bool ChatId::operator <(const ChatId& other) const -{ - if(type != other.type) - return type < other.type; - else - { - switch(type) - { - case TYPE_NOT_SET: - return false; - case TYPE_PRIVATE: - return peer_id < other.peer_id; - case TYPE_PRIVATE_DISTANT: - return distant_chat_id < other.distant_chat_id; - case TYPE_LOBBY: - return lobby_id < other.lobby_id; - case TYPE_BROADCAST: - return false; - default: - return false; - } - } -} - -bool ChatId::isSameEndpoint(const ChatId &other) const -{ - if(type != other.type) - return false; - else - { - switch(type) - { - case TYPE_NOT_SET: - return false; - case TYPE_PRIVATE: - return peer_id == other.peer_id; - case TYPE_PRIVATE_DISTANT: - return distant_chat_id == other.distant_chat_id; - case TYPE_LOBBY: - return lobby_id == other.lobby_id; - case TYPE_BROADCAST: - return true; - default: - return false; - } - } -} - -bool ChatId::isNotSet() const -{ - return type == TYPE_NOT_SET; -} -bool ChatId::isPeerId() const -{ - return type == TYPE_PRIVATE; -} -bool ChatId::isDistantChatId() const -{ - return type == TYPE_PRIVATE_DISTANT; -} -bool ChatId::isLobbyId() const -{ - return type == TYPE_LOBBY; -} -bool ChatId::isBroadcast() const -{ - return type == TYPE_BROADCAST; -} -RsPeerId ChatId::toPeerId() const -{ - if(type == TYPE_PRIVATE) - return peer_id; - else - { - std::cerr << "ChatId Warning: conversation to RsPeerId requested, but type is different. Current value=\"" << toStdString() << "\"" << std::endl; - return RsPeerId(); - } -} - -DistantChatPeerId ChatId::toDistantChatId() const -{ - if(type == TYPE_PRIVATE_DISTANT) - return distant_chat_id; - else - { - std::cerr << "ChatId Warning: conversation to DistantChatPeerId requested, but type is different. Current value=\"" << toStdString() << "\"" << std::endl; - return DistantChatPeerId(); - } -} -ChatLobbyId ChatId::toLobbyId() const -{ - if(type == TYPE_LOBBY) - return lobby_id; - else - { - std::cerr << "ChatId Warning: conversation to ChatLobbyId requested, but type is different. Current value=\"" << toStdString() << "\"" << std::endl; - return 0; - } -} - bool p3Msgs::getMessageSummaries(BoxName box,std::list &msgList) { return mMsgSrv->getMessageSummaries(box,msgList); @@ -565,22 +343,4 @@ RsMsgs::~RsMsgs() = default; Rs::Msgs::MessageInfo::~MessageInfo() = default; MsgInfoSummary::~MsgInfoSummary() = default; -void RsMailIdRecipientIdPair::serial_process( - RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) -{ - RS_SERIAL_PROCESS(mMailId); - RS_SERIAL_PROCESS(mRecipientId); -} - -bool RsMailIdRecipientIdPair::operator<(const RsMailIdRecipientIdPair& o) const -{ - return std::tie( mMailId, mRecipientId) < - std::tie(o.mMailId, o.mRecipientId); -} -bool RsMailIdRecipientIdPair::operator==(const RsMailIdRecipientIdPair& o) const -{ - return std::tie( mMailId, mRecipientId) == - std::tie(o.mMailId, o.mRecipientId); -} diff --git a/src/rsserver/rsinit.cc b/src/rsserver/rsinit.cc index 0dbfb4847..89e9a89cf 100644 --- a/src/rsserver/rsinit.cc +++ b/src/rsserver/rsinit.cc @@ -44,6 +44,7 @@ #include "util/folderiterator.h" #include "util/rsstring.h" #include "retroshare/rsinit.h" +#include "retroshare/rsmail.h" #include "retroshare/rstor.h" #include "retroshare/rsiface.h" #include "plugins/pluginmanager.h" @@ -859,7 +860,6 @@ RsGRouter *rsGRouter = NULL ; /* Implemented Rs Interfaces */ #include "rsserver/p3face.h" #include "rsserver/p3peers.h" -#include "rsserver/p3msgs.h" #include "rsserver/p3status.h" #include "rsserver/p3history.h" #include "rsserver/p3serverconfig.h" @@ -1589,7 +1589,8 @@ int RsServer::StartupRetroShare() mGxsNetTunnel->connectToTurtleRouter(tr) ; rsGossipDiscovery.reset(mDisc); - rsMsgs = new p3Msgs(msgSrv, chatSrv); + rsMail = msgSrv; + rsChats = chatSrv; // connect components to turtle router. @@ -1615,7 +1616,7 @@ int RsServer::StartupRetroShare() RsPlugInInterfaces interfaces; interfaces.mFiles = rsFiles; interfaces.mPeers = rsPeers; - interfaces.mMsgs = rsMsgs; + interfaces.mMail = rsMail; interfaces.mTurtle = rsTurtle; interfaces.mDisc = rsDisc; #ifdef RS_USE_BITDHT diff --git a/src/services/p3msgservice.cc b/src/services/p3msgservice.cc index 2443fc35e..1f6d3670d 100644 --- a/src/services/p3msgservice.cc +++ b/src/services/p3msgservice.cc @@ -97,7 +97,9 @@ #include #include -using namespace Rs::Msgs; +using namespace Rs::Mail; + +RsMail *rsMail = nullptr; // extern //#define DEBUG_DISTANT_MSG @@ -321,15 +323,15 @@ int p3MsgService::incomingMsgs() // direct node-to-node messages while((mi = (RsMsgItem *) recvItem()) != NULL) { handleIncomingItem(mi, - Rs::Msgs::MsgAddress(mi->PeerId(), Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO), - Rs::Msgs::MsgAddress(mServiceCtrl->getOwnId(),Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO)); + Rs::Mail::MsgAddress(mi->PeerId(), Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO), + Rs::Mail::MsgAddress(mServiceCtrl->getOwnId(),Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO)); ++i ; } return i; } -void p3MsgService::handleIncomingItem(RsMsgItem *mi,const Rs::Msgs::MsgAddress& from,const Rs::Msgs::MsgAddress& to) +void p3MsgService::handleIncomingItem(RsMsgItem *mi,const Rs::Mail::MsgAddress& from,const Rs::Mail::MsgAddress& to) { // only returns true when a msg is complete. if(checkAndRebuildPartialMessage(mi)) @@ -724,9 +726,9 @@ bool p3MsgService::parseList_backwardCompatibility(std::list& load) RsErr() << " Loaded msg source pair (msg=" << psrc->msgId << ", src_id=" << psrc->srcId << ")"; if(mit->second->msg.msgFlags & RS_MSG_FLAGS_DISTANT) - mit->second->from = Rs::Msgs::MsgAddress(RsGxsId(psrc->srcId),Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO); + mit->second->from = Rs::Mail::MsgAddress(RsGxsId(psrc->srcId),Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO); else - mit->second->from = Rs::Msgs::MsgAddress(psrc->srcId,Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO); + mit->second->from = Rs::Mail::MsgAddress(psrc->srcId,Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO); } // 4 - store each message in the appropriate map. @@ -749,30 +751,30 @@ bool p3MsgService::parseList_backwardCompatibility(std::list& load) for(auto d:mit.second->msg.rsgxsid_msgto.ids) if(rsIdentity->isOwnId(d)) { - mit.second->to = MsgAddress(d,Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO); + mit.second->to = MsgAddress(d,Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO); break; } for(auto d:mit.second->msg.rsgxsid_msgcc.ids) if(rsIdentity->isOwnId(d)) { - mit.second->to = MsgAddress(d,Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_CC); + mit.second->to = MsgAddress(d,Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_CC); break; } for(auto d:mit.second->msg.rsgxsid_msgbcc.ids) if(rsIdentity->isOwnId(d)) { - mit.second->to = MsgAddress(d,Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_BCC); + mit.second->to = MsgAddress(d,Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_BCC); break; } } else { if(mit.second->msg.rspeerid_msgto.ids.find(rsPeers->getOwnId()) != mit.second->msg.rspeerid_msgto.ids.end()) - mit.second->to = MsgAddress(rsPeers->getOwnId(),Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO); + mit.second->to = MsgAddress(rsPeers->getOwnId(),Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO); else if(mit.second->msg.rspeerid_msgcc.ids.find(rsPeers->getOwnId()) != mit.second->msg.rspeerid_msgcc.ids.end()) - mit.second->to = MsgAddress(rsPeers->getOwnId(),Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_CC); + mit.second->to = MsgAddress(rsPeers->getOwnId(),Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_CC); else - mit.second->to = MsgAddress(rsPeers->getOwnId(),Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_BCC); + mit.second->to = MsgAddress(rsPeers->getOwnId(),Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_BCC); } RsInfo() << " Storing message " << mit.first << ", possible destination: " << mit.second->to << ", MsgFlags: " << std::hex << mit.second->msg.msgFlags << std::dec ; @@ -1297,7 +1299,7 @@ void p3MsgService::getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32 } /* remove based on the unique mid (stored in sid) */ -bool p3MsgService::deleteMessage(const std::string& mid) +bool p3MsgService::MessageDelete(const std::string& mid) { uint32_t msgId = strtoul(mid.c_str(), 0, 10); @@ -1377,7 +1379,7 @@ bool p3MsgService::deleteMessage(const std::string& mid) return changed; } -bool p3MsgService::markMsgIdRead(const std::string &mid, bool unreadByUser) +bool p3MsgService::MessageRead(const std::string &mid, bool unreadByUser) { uint32_t msgId = strtoul(mid.c_str(), NULL, 10); @@ -1537,7 +1539,7 @@ MessageIdentifier p3MsgService::internal_sendMessage(MessageIdentifier id,const else { info.flags |= RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES; /* load embedded images only for node-to-node messages?? */ // (cyril: ?!?!) - info.origin = Rs::Msgs::MsgAddress(mServiceCtrl->getOwnId(),Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO); + info.origin = Rs::Mail::MsgAddress(mServiceCtrl->getOwnId(),Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO); } } @@ -1763,8 +1765,8 @@ bool p3MsgService::SystemMessage(const std::string &title, const std::string &me msg->rspeerid_msgto.ids.insert(mServiceCtrl->getOwnId()); processIncomingMsg(msg, - Rs::Msgs::MsgAddress(RsPeerId(), Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO), - Rs::Msgs::MsgAddress(mServiceCtrl->getOwnId(),Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO)); + Rs::Mail::MsgAddress(RsPeerId(), Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO), + Rs::Mail::MsgAddress(mServiceCtrl->getOwnId(),Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO)); return true; } @@ -1808,7 +1810,7 @@ bool p3MsgService::MessageToDraft(MessageInfo& info, const std::string& msgParen return true; } -bool p3MsgService::getMessageTag(const std::string &msgId, Rs::Msgs::MsgTagInfo& info) +bool p3MsgService::getMessageTag(const std::string &msgId, Rs::Mail::MsgTagInfo& info) { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ return locked_getMessageTag(msgId,info); @@ -2015,7 +2017,7 @@ bool p3MsgService::setMessageTag(const std::string& msgId, uint32_t tagId, bool msi->tagIds.insert(tagId); ev->mChangedMsgIds.insert(msgId); // normally we should check whether the tag already exists or not. } - else if(tagId==0) // See rsmsgs.h. tagId=0 => erase all tags. + else if(tagId==0) // See rsmail.h. tagId=0 => erase all tags. { msi->tagIds.clear(); ev->mChangedMsgIds.insert(msgId); @@ -2603,8 +2605,8 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId, msg_item->PeerId(RsPeerId(authorId)); handleIncomingItem(msg_item, - Rs::Msgs::MsgAddress(authorId,Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO), - Rs::Msgs::MsgAddress(recipientId,Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO)); + Rs::Mail::MsgAddress(authorId,Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO), + Rs::Mail::MsgAddress(recipientId,Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO)); } else { @@ -2765,8 +2767,8 @@ void p3MsgService::receiveGRouterData( const RsGxsId &destination_key, msg_item->PeerId(RsPeerId(signing_key)) ; // hack to pass on GXS id. handleIncomingItem(msg_item, - Rs::Msgs::MsgAddress(signing_key, Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO), - Rs::Msgs::MsgAddress(destination_key,Rs::Msgs::MsgAddress::MSG_ADDRESS_MODE_TO)); + Rs::Mail::MsgAddress(signing_key, Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO), + Rs::Mail::MsgAddress(destination_key,Rs::Mail::MsgAddress::MSG_ADDRESS_MODE_TO)); } else std::cerr << " Item could not be deserialised. Format error??" << std::endl; @@ -2822,7 +2824,7 @@ void p3MsgService::locked_sendDistantMsgItem(RsMsgItem *msgitem,const RsGxsId& s IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_NOW); // save _ongoing_messages } -RsMsgItem *p3MsgService::createOutgoingMessageItem(const RsMailStorageItem& msi,const Rs::Msgs::MsgAddress& to) +RsMsgItem *p3MsgService::createOutgoingMessageItem(const RsMailStorageItem& msi,const Rs::Mail::MsgAddress& to) { RsMsgItem *item = new RsMsgItem; @@ -2858,6 +2860,31 @@ RsMsgItem *p3MsgService::createOutgoingMessageItem(const RsMailStorageItem& msi, return item; } +bool p3MsgService::MessageReplied(const std::string &mid, bool replied) +{ + return setMsgFlag(mid, replied ? RS_MSG_FLAGS_REPLIED : 0, RS_MSG_FLAGS_REPLIED); +} + +bool p3MsgService::MessageForwarded(const std::string &mid, bool forwarded) +{ + return setMsgFlag(mid, forwarded ? RS_MSG_FLAGS_FORWARDED : 0, RS_MSG_FLAGS_FORWARDED); +} + +bool p3MsgService::MessageLoadEmbeddedImages(const std::string &mid, bool load) +{ + return setMsgFlag(mid, load ? RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES : 0, RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES); +} + +bool p3MsgService::MessageStar(const std::string &mid, bool star) +{ + return setMsgFlag(mid, star ? RS_MSG_FLAGS_STAR : 0, RS_MSG_FLAGS_STAR); +} +bool p3MsgService::MessageJunk(const std::string &mid, bool junk) +{ + return setMsgFlag(mid, junk ? RS_MSG_FLAGS_SPAM : 0, RS_MSG_FLAGS_SPAM); +} + + void p3MsgService::debug_dump() { std::cerr << "Dump of p3MsgService data:" << std::endl; @@ -2889,4 +2916,23 @@ void p3MsgService::debug_dump() } } +void RsMailIdRecipientIdPair::serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) +{ + RS_SERIAL_PROCESS(mMailId); + RS_SERIAL_PROCESS(mRecipientId); +} + +bool RsMailIdRecipientIdPair::operator<(const RsMailIdRecipientIdPair& o) const +{ + return std::tie( mMailId, mRecipientId) < + std::tie(o.mMailId, o.mRecipientId); +} + +bool RsMailIdRecipientIdPair::operator==(const RsMailIdRecipientIdPair& o) const +{ + return std::tie( mMailId, mRecipientId) == + std::tie(o.mMailId, o.mRecipientId); +} diff --git a/src/services/p3msgservice.h b/src/services/p3msgservice.h index f3a30050e..a6a89194e 100644 --- a/src/services/p3msgservice.h +++ b/src/services/p3msgservice.h @@ -26,8 +26,6 @@ #include #include -#include "retroshare/rsmsgs.h" - #include "pqi/pqi.h" #include "pqi/pqiindic.h" @@ -39,6 +37,7 @@ #include "util/rsthreads.h" #include "util/rsdebug.h" #include "retroshare/rsgxsifacetypes.h" +#include "retroshare/rsmail.h" #include "grouter/p3grouter.h" #include "grouter/grouterclientservice.h" @@ -53,14 +52,18 @@ typedef uint32_t MessageIdentifier; // Temp tweak to test grouter class p3MsgService : - public p3Service, public p3Config, public pqiServiceMonitor, GRouterClientService, - GxsTransClient + public RsMail, + public p3Service, + public p3Config, + public pqiServiceMonitor, + public GRouterClientService, + public GxsTransClient { public: p3MsgService(p3ServiceControl *sc, p3IdService *id_service, p3GxsTrans& gxsMS); virtual ~p3MsgService(); - virtual RsServiceInfo getServiceInfo(); + virtual RsServiceInfo getServiceInfo() override; /// @see RsMsgs::sendMail uint32_t sendMail(const RsGxsId from, @@ -73,35 +76,40 @@ class p3MsgService : std::set& trackingIds = RS_DEFAULT_STORAGE_PARAM(std::set), std::string& errorMsg = - RS_DEFAULT_STORAGE_PARAM(std::string) ); + RS_DEFAULT_STORAGE_PARAM(std::string) ) override; /* External Interface */ - bool getMessageSummaries(Rs::Msgs::BoxName box, std::list &msgList); - bool getMessage(const std::string& mid, Rs::Msgs::MessageInfo &msg); - void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox); - - bool deleteMessage(const std::string &mid); - bool markMsgIdRead(const std::string &mid, bool bUnreadByUser); - bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask); - bool getMsgParentId(const std::string &msgId, std::string &msgParentId); + bool getMessageSummaries(Rs::Mail::BoxName box, std::list &msgList) override; + bool getMessage(const std::string& mid, Rs::Mail::MessageInfo &msg) override; + void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox) override; + + bool MessageDelete(const std::string &mid) override; + bool MessageRead(const std::string &mid, bool bUnreadByUser) override; + bool MessageJunk(const std::string &mid, bool bUnreadByUser) override; + bool MessageReplied(const std::string &mid, bool bUnreadByUser) override; + bool MessageForwarded(const std::string &mid, bool forwarded) override; + bool MessageStar(const std::string &mid, bool star) override; + bool MessageLoadEmbeddedImages(const std::string &mid, bool load) override; + + bool getMsgParentId(const std::string &msgId, std::string &msgParentId) override; // msgParentId == 0 --> remove bool setMsgParentId(uint32_t msgId, uint32_t msgParentId); RS_DEPRECATED_FOR(sendMail) - bool MessageSend(Rs::Msgs::MessageInfo &info); - bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); - bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId); - bool MessageToTrash(const std::string &mid, bool bTrash); + bool MessageSend(Rs::Mail::MessageInfo &info) override; + bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) override; + bool MessageToDraft(Rs::Mail::MessageInfo &info, const std::string &msgParentId) override; + bool MessageToTrash(const std::string &mid, bool bTrash) override; - bool getMessageTag(const std::string &msgId, Rs::Msgs::MsgTagInfo& info); - bool getMessageTagTypes(Rs::Msgs::MsgTagType& tags); - bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color); - bool removeMessageTagType(uint32_t tagId); + bool getMessageTag(const std::string &msgId, Rs::Mail::MsgTagInfo& info) override; + bool getMessageTagTypes(Rs::Mail::MsgTagType& tags) override; + bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color) override; + bool removeMessageTagType(uint32_t tagId) override; /* set == false && tagId == 0 --> remove all */ - bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set); + bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set) override; - bool resetMessageStandardTagTypes(Rs::Msgs::MsgTagType& tags); + bool resetMessageStandardTagTypes(Rs::Mail::MsgTagType& tags) override; void loadWelcomeMsg(); /* startup message */ @@ -109,17 +117,17 @@ class p3MsgService : //std::list &getMsgList(); //std::list &getMsgOutList(); - int tick(); + int tick() override; /*** Overloaded from p3Config ****/ - virtual RsSerialiser *setupSerialiser(); - virtual bool saveList(bool& cleanup, std::list&); - virtual bool loadList(std::list& load); - virtual void saveDone(); + virtual RsSerialiser *setupSerialiser() override; + virtual bool saveList(bool& cleanup, std::list&) override; + virtual bool loadList(std::list& load) override; + virtual void saveDone() override; /*** Overloaded from p3Config ****/ /*** Overloaded from pqiMonitor ***/ - virtual void statusChange(const std::list &plist); + virtual void statusChange(const std::list &plist) override; /// iterate through the outgoing queue if online, send int checkOutgoingMessages(); @@ -127,7 +135,7 @@ class p3MsgService : /*** overloaded from p3turtle ***/ - virtual void connectToGlobalRouter(p3GRouter *) ; + virtual void connectToGlobalRouter(p3GRouter *) override; struct DistantMessengingInvite { @@ -143,21 +151,23 @@ class p3MsgService : void enableDistantMessaging(bool b) ; bool distantMessagingEnabled() ; - void setDistantMessagingPermissionFlags(uint32_t flags) ; - uint32_t getDistantMessagingPermissionFlags() ; + void setDistantMessagingPermissionFlags(uint32_t flags) override; + uint32_t getDistantMessagingPermissionFlags() override; /// @see GxsTransClient::receiveGxsTransMail(...) virtual bool receiveGxsTransMail( const RsGxsId& authorId, const RsGxsId& recipientId, - const uint8_t* data, uint32_t dataSize ); + const uint8_t* data, uint32_t dataSize ) override; /// @see GxsTransClient::notifyGxsTransSendStatus(...) virtual bool notifyGxsTransSendStatus( RsGxsTransId mailId, - GxsTransSendStatus status ); + GxsTransSendStatus status ) override; private: + bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask); + void locked_sendDistantMsgItem(RsMsgItem *msgitem, const RsGxsId &from, uint32_t msgId); - bool locked_getMessageTag(const std::string &msgId, Rs::Msgs::MsgTagInfo& info); + bool locked_getMessageTag(const std::string &msgId, Rs::Mail::MsgTagInfo& info); void locked_checkForDuplicates(); RsMailStorageItem *locked_getMessageData(uint32_t mid) const; @@ -170,9 +180,9 @@ class p3MsgService : RsMutex gxsOngoingMutex; // Overloaded from GRouterClientService - virtual bool acceptDataFromPeer(const RsGxsId& gxs_id) ; - virtual void receiveGRouterData(const RsGxsId& destination_key,const RsGxsId& signing_key, GRouterServiceId &client_id, uint8_t *data, uint32_t data_size) ; - virtual void notifyDataStatus(const GRouterMsgPropagationId& msg_id,const RsGxsId& signer_id,uint32_t data_status) ; + virtual bool acceptDataFromPeer(const RsGxsId& gxs_id) override; + virtual void receiveGRouterData(const RsGxsId& destination_key,const RsGxsId& signing_key, GRouterServiceId &client_id, uint8_t *data, uint32_t data_size) override; + virtual void notifyDataStatus(const GRouterMsgPropagationId& msg_id,const RsGxsId& signer_id,uint32_t data_status) override; // Utility functions @@ -181,31 +191,31 @@ class p3MsgService : void manageDistantPeers() ; - void handleIncomingItem(RsMsgItem *, const Rs::Msgs::MsgAddress &from, const Rs::Msgs::MsgAddress &to) ; + void handleIncomingItem(RsMsgItem *, const Rs::Mail::MsgAddress &from, const Rs::Mail::MsgAddress &to) ; uint32_t getNewUniqueMsgId(); - MessageIdentifier internal_sendMessage(MessageIdentifier id, const Rs::Msgs::MsgAddress &from, const Rs::Msgs::MsgAddress &to, uint32_t flags); + MessageIdentifier internal_sendMessage(MessageIdentifier id, const Rs::Mail::MsgAddress &from, const Rs::Mail::MsgAddress &to, uint32_t flags); uint32_t sendDistantMessage(RsMsgItem *item,const RsGxsId& signing_gxs_id); void checkSizeAndSendMessage(RsMsgItem *msg, const RsPeerId &destination); void cleanListOfReceivedMessageHashes(); int incomingMsgs(); - void processIncomingMsg(RsMsgItem *mi,const Rs::Msgs::MsgAddress& from,const Rs::Msgs::MsgAddress& to) ; + void processIncomingMsg(RsMsgItem *mi,const Rs::Mail::MsgAddress& from,const Rs::Mail::MsgAddress& to) ; bool checkAndRebuildPartialMessage(RsMsgItem*) ; // These two functions generate MessageInfo and MessageInfoSummary structures for the UI to use - void initRsMI (const RsMailStorageItem& msi, const Rs::Msgs::MsgAddress& from, const Rs::Msgs::MsgAddress& to, uint32_t flags, Rs::Msgs::MessageInfo& mi ); - void initRsMIS(const RsMailStorageItem& msi, const Rs::Msgs::MsgAddress& from, const Rs::Msgs::MsgAddress& to,MessageIdentifier mid,Rs::Msgs::MsgInfoSummary& mis); + void initRsMI (const RsMailStorageItem& msi, const Rs::Mail::MsgAddress& from, const Rs::Mail::MsgAddress& to, uint32_t flags, Rs::Mail::MessageInfo& mi ); + void initRsMIS(const RsMailStorageItem& msi, const Rs::Mail::MsgAddress& from, const Rs::Mail::MsgAddress& to,MessageIdentifier mid,Rs::Mail::MsgInfoSummary& mis); // Creates a RsMsgItem from a RsMailStorageItem, and a 'to' fields. - RsMsgItem *createOutgoingMessageItem(const RsMailStorageItem& msi, const Rs::Msgs::MsgAddress& to); + RsMsgItem *createOutgoingMessageItem(const RsMailStorageItem& msi, const Rs::Mail::MsgAddress& to); // Creates a RsMailStorageItem from a message info and a 'from' field. - RsMailStorageItem *initMIRsMsg(const Rs::Msgs::MessageInfo &info); + RsMailStorageItem *initMIRsMsg(const Rs::Mail::MessageInfo &info); // Creates a RsMailStorageItem from a MessageInfo. - bool initMIRsMsg(RsMailStorageItem *msi, const Rs::Msgs::MessageInfo &info) ; + bool initMIRsMsg(RsMailStorageItem *msi, const Rs::Mail::MessageInfo &info) ; void initStandardTagTypes();