From 33773031d59762a28fbc4673c7df2dd378b79d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 13 Jan 2024 21:50:21 +0100 Subject: Message: sync state when peer appears on network --- src/message.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/message.cpp b/src/message.cpp index 389807b..54c080e 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -314,7 +314,10 @@ DirectMessageService::DirectMessageService(Config && c, const Server & s): server(s), watched(server.localState().lens().lens().watch( std::bind(&DirectMessageService::updateHandler, this, std::placeholders::_1))) -{} +{ + server.peerList().onUpdate(std::bind(&DirectMessageService::peerWatcher, this, + std::placeholders::_1, std::placeholders::_2)); +} DirectMessageService::~DirectMessageService() = default; @@ -473,6 +476,16 @@ void DirectMessageService::updateHandler(const DirectMessageThreads & threads) } } +void DirectMessageService::peerWatcher(size_t, const class Peer * peer) +{ + if (peer) { + if (auto pid = peer->identity()) { + syncWithPeer(server.localHead(), + thread(pid->finalOwner()), *peer); + } + } +} + void DirectMessageService::syncWithPeer(const Head & head, const DirectMessageThread & thread, const Peer & peer) { for (const auto & msg : thread.p->head) -- cgit v1.2.3