From fb65f6a6e802e5bb9ec80d0e91177a35a206e7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 17 Dec 2023 18:01:01 +0100 Subject: Message: use ready state before sending messages --- src/message.cpp | 13 ++++++------- src/message.h | 7 ++++--- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/message.cpp b/src/message.cpp index a9d6139..1ee362a 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -202,6 +202,7 @@ DirectMessageState DirectMessageState::load(const Ref & ref) .prev = rec->items("PREV").as(), .peer = Identity::load(rec->items("peer").asRef()), + .ready = rec->items("ready").as(), .sent = rec->items("sent").as(), .received = rec->items("received").as(), .seen = rec->items("seen").as(), @@ -221,6 +222,8 @@ Ref DirectMessageState::store(const Storage & st) const for (const auto & ref : peer->refs()) items.emplace_back("peer", ref); + for (const auto & x : ready) + items.emplace_back("ready", x.ref()); for (const auto & x : sent) items.emplace_back("sent", x.ref()); for (const auto & x : received) @@ -280,8 +283,8 @@ bool DirectMessageThreads::operator!=(const DirectMessageThreads & other) const DirectMessageThread DirectMessageThreads::thread(const Identity & peer) const { vector> head; - for (const auto & c : findThreadComponents(state, peer, &DirectMessageState::sent)) - for (const auto & m : c->sent) + for (const auto & c : findThreadComponents(state, peer, &DirectMessageState::ready)) + for (const auto & m : c->ready) head.push_back(m); for (const auto & c : findThreadComponents(state, peer, &DirectMessageState::received)) for (const auto & m : c->received) @@ -345,9 +348,7 @@ void DirectMessageService::handle(Context & ctx) auto state = st.store(DirectMessageState { .prev = threads.data(), .peer = powner, - .sent = {}, .received = { msg }, - .seen = {}, }); auto res = st.store(loc->shared(DirectMessageThreads(state))); @@ -381,9 +382,7 @@ DirectMessage DirectMessageService::send(const Identity & to, const string & tex auto state = st.store(DirectMessageState { .prev = threads.data(), .peer = to, - .sent = { msg }, - .received = {}, - .seen = {}, + .ready = { msg }, }); return st.store(loc->shared(DirectMessageThreads(state))); diff --git a/src/message.h b/src/message.h index 4e99cd1..f729700 100644 --- a/src/message.h +++ b/src/message.h @@ -53,9 +53,10 @@ struct DirectMessageState vector> prev; optional peer; - vector> sent; - vector> received; - vector> seen; + vector> ready {}; + vector> sent {}; + vector> received {}; + vector> seen {}; }; } -- cgit v1.2.3