summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-12-17 18:01:01 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2023-12-18 21:38:53 +0100
commitfb65f6a6e802e5bb9ec80d0e91177a35a206e7a1 (patch)
tree3ea73b2f0c30356e69c62179d91f225c9f934ac4
parent0bcef826baaa6a335d8fddafdbebd00fbf421c2c (diff)
Message: use ready state before sending messages
-rw-r--r--src/message.cpp13
-rw-r--r--src/message.h7
2 files changed, 10 insertions, 10 deletions
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<DirectMessageState>(),
.peer = Identity::load(rec->items("peer").asRef()),
+ .ready = rec->items("ready").as<DirectMessageData>(),
.sent = rec->items("sent").as<DirectMessageData>(),
.received = rec->items("received").as<DirectMessageData>(),
.seen = rec->items("seen").as<DirectMessageData>(),
@@ -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<Stored<DirectMessageData>> 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>(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>(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<Stored<DirectMessageState>> prev;
optional<Identity> peer;
- vector<Stored<DirectMessageData>> sent;
- vector<Stored<DirectMessageData>> received;
- vector<Stored<DirectMessageData>> seen;
+ vector<Stored<DirectMessageData>> ready {};
+ vector<Stored<DirectMessageData>> sent {};
+ vector<Stored<DirectMessageData>> received {};
+ vector<Stored<DirectMessageData>> seen {};
};
}