diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index 28ade2674..9775f54de 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -881,6 +881,13 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *& ci) RsServer::notify()->notifyChatMessage(cm); mHistoryMgr->addMessage(cm); + + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mChatMessage = cm; + rsEvents->postEvent(ev); + } return true ; } diff --git a/libretroshare/src/chat/p3chatservice.h b/libretroshare/src/chat/p3chatservice.h index 3a5b08ab9..bc4dd56b9 100644 --- a/libretroshare/src/chat/p3chatservice.h +++ b/libretroshare/src/chat/p3chatservice.h @@ -42,6 +42,22 @@ class p3HistoryMgr; typedef RsPeerId ChatLobbyVirtualPeerId ; +struct RsChatMessageEvent : RsEvent +{ + RsChatMessageEvent() : RsEvent(RsEventType::CHAT_MESSAGE) {} + ~RsChatMessageEvent() override = default; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override + { + RsEvent::serial_process(j, ctx); + + RS_SERIAL_PROCESS(mChatMessage); + } + + ChatMessage mChatMessage; +}; + //!The basic Chat service. /** * diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 090368910..cd23cacd9 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -94,7 +94,10 @@ enum class RsEventType : uint32_t /// @see RsFiles FILE_TRANSFER = 14, - MAX /// Used to detect invalid event type passed + /// @see RsMsgs + CHAT_MESSAGE = 15, + + MAX /// Used to detect invalid event type passed }; /** diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 3bdc76505..bee111af9 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -426,9 +426,8 @@ public: } }; -class ChatMessage +struct ChatMessage : RsSerializable { -public: 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 @@ -441,6 +440,22 @@ public: 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