From 9577599e6af4dfb36df81fe5d89801c4ce4a19ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 1 Jul 2023 20:08:48 +0200 Subject: Direct message shared state --- src/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index f9c5e98..b39130a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -289,6 +289,9 @@ void startServer(const vector &) config.service() .onUpdate([](const DirectMessageThread & thread, ssize_t, ssize_t) { + if (thread.at(0).from()->sameAs(server->identity())) + return; + ostringstream ss; string name = ""; @@ -550,6 +553,36 @@ void dmSendContact(const vector & args) args.at(1)); } +template +static void dmList(const T & peer) +{ + if (auto id = peer.identity()) + for (const auto & msg : h->behavior().get().shared().thread(*id)) { + string name = ""; + if (const auto & from = msg.from()) + if (const auto & opt = from->name()) + name = *opt; + + ostringstream ss; + ss << "dm-list-item" + << " from " << name + << " text " << msg.text() + ; + printLine(ss.str()); + } + printLine("dm-list-done"); +} + +void dmListPeer(const vector & args) +{ + dmList(getPeer(args.at(0)).peer); +} + +void dmListContact(const vector & args) +{ + dmList(getContact(args.at(0))); +} + vector commands = { { "store", store }, { "stored-generation", storedGeneration }, @@ -576,6 +609,8 @@ vector commands = { { "contact-set-name", contactSetName }, { "dm-send-peer", dmSendPeer }, { "dm-send-contact", dmSendContact }, + { "dm-list-peer", dmListPeer }, + { "dm-list-contact", dmListContact }, }; } -- cgit v1.2.3