summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-01-13 21:50:21 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2024-01-24 21:32:27 +0100
commit33773031d59762a28fbc4673c7df2dd378b79d0e (patch)
tree82a9a82122920abaf8c29d0c557edc62ab08b2b0 /src
parent56b6a56b5d14781cd24e38860c082bfdab96c918 (diff)
Message: sync state when peer appears on network
Diffstat (limited to 'src')
-rw-r--r--src/message.cpp15
1 files changed, 14 insertions, 1 deletions
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<SharedState>().lens<DirectMessageThreads>().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<LocalState> & head, const DirectMessageThread & thread, const Peer & peer)
{
for (const auto & msg : thread.p->head)