summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/erebos/message.h1
-rw-r--r--src/message.cpp15
-rw-r--r--test/message.test15
3 files changed, 30 insertions, 1 deletions
diff --git a/include/erebos/message.h b/include/erebos/message.h
index 6ad6e54..a74e6a3 100644
--- a/include/erebos/message.h
+++ b/include/erebos/message.h
@@ -141,6 +141,7 @@ public:
private:
void updateHandler(const DirectMessageThreads &);
+ void peerWatcher(size_t, const class Peer *);
static void syncWithPeer(const Head<LocalState> &, const DirectMessageThread &, const Peer &);
const Config config;
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)
diff --git a/test/message.test b/test/message.test
index f630c59..307f11a 100644
--- a/test/message.test
+++ b/test/message.test
@@ -132,3 +132,18 @@ test DirectMessage:
send "start-server" to p1
expect /dm-received from Owner1 text while_offline/ from p2
+
+ for p in [p1, p2]:
+ with p:
+ send "stop-server"
+ for p in [p1, p2]:
+ with p:
+ expect /stop-server-done/
+ send "start-server" to p1
+
+ send "dm-send-contact $c1_2 while_peer_offline" to p1
+ # TODO: sync from p1 on peer p2 discovery not ensured without addition wait
+ #wait
+ send "start-server" to p2
+
+ expect /dm-received from Owner1 text while_peer_offline/ from p2