diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-07-01 20:08:48 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-07-01 22:07:27 +0200 |
commit | 9577599e6af4dfb36df81fe5d89801c4ce4a19ab (patch) | |
tree | 1d383f6f3466c3c2198b4de2a2f53b6ad500fe39 /src/main.cpp | |
parent | afab7dc5673fbc5fd600182612626676ae36d1c0 (diff) |
Direct message shared state
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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<string> &) config.service<DirectMessageService>() .onUpdate([](const DirectMessageThread & thread, ssize_t, ssize_t) { + if (thread.at(0).from()->sameAs(server->identity())) + return; + ostringstream ss; string name = "<unnamed>"; @@ -550,6 +553,36 @@ void dmSendContact(const vector<string> & args) args.at(1)); } +template<class T> +static void dmList(const T & peer) +{ + if (auto id = peer.identity()) + for (const auto & msg : h->behavior().get().shared<DirectMessageThreads>().thread(*id)) { + string name = "<unnamed>"; + 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<string> & args) +{ + dmList(getPeer(args.at(0)).peer); +} + +void dmListContact(const vector<string> & args) +{ + dmList(getContact(args.at(0))); +} + vector<Command> commands = { { "store", store }, { "stored-generation", storedGeneration }, @@ -576,6 +609,8 @@ vector<Command> commands = { { "contact-set-name", contactSetName }, { "dm-send-peer", dmSendPeer }, { "dm-send-contact", dmSendContact }, + { "dm-list-peer", dmListPeer }, + { "dm-list-contact", dmListContact }, }; } |