mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Fix editing pending messages
This commit is contained in:
parent
4946548997
commit
9f5b647fb3
3 changed files with 31 additions and 10 deletions
|
@ -2931,6 +2931,28 @@ Cache::savePendingMessage(const std::string &room_id,
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
std::vector<std::string>
|
||||||
|
Cache::pendingEvents(const std::string &room_id)
|
||||||
|
{
|
||||||
|
auto txn = ro_txn(env_);
|
||||||
|
auto pending = getPendingMessagesDb(txn, room_id);
|
||||||
|
|
||||||
|
std::vector<std::string> related_ids;
|
||||||
|
|
||||||
|
try {
|
||||||
|
{
|
||||||
|
auto pendingCursor = lmdb::cursor::open(txn, pending);
|
||||||
|
std::string_view tsIgnored, pendingTxn;
|
||||||
|
while (pendingCursor.get(tsIgnored, pendingTxn, MDB_NEXT)) {
|
||||||
|
related_ids.emplace_back(pendingTxn.data(), pendingTxn.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const lmdb::error &e) {
|
||||||
|
nhlog::db()->error("pending events error: {}", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
return related_ids;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<mtx::events::collections::TimelineEvent>
|
std::optional<mtx::events::collections::TimelineEvent>
|
||||||
Cache::firstPendingMessage(const std::string &room_id)
|
Cache::firstPendingMessage(const std::string &room_id)
|
||||||
|
|
|
@ -218,6 +218,7 @@ public:
|
||||||
uint64_t saveOldMessages(const std::string &room_id, const mtx::responses::Messages &res);
|
uint64_t saveOldMessages(const std::string &room_id, const mtx::responses::Messages &res);
|
||||||
void savePendingMessage(const std::string &room_id,
|
void savePendingMessage(const std::string &room_id,
|
||||||
const mtx::events::collections::TimelineEvent &message);
|
const mtx::events::collections::TimelineEvent &message);
|
||||||
|
std::vector<std::string> pendingEvents(const std::string &room_id);
|
||||||
std::optional<mtx::events::collections::TimelineEvent>
|
std::optional<mtx::events::collections::TimelineEvent>
|
||||||
firstPendingMessage(const std::string &room_id);
|
firstPendingMessage(const std::string &room_id);
|
||||||
void removePendingStatus(const std::string &room_id, const std::string &txn_id);
|
void removePendingStatus(const std::string &room_id, const std::string &txn_id);
|
||||||
|
|
|
@ -187,15 +187,13 @@ EventStore::EventStore(std::string room_id, QObject *)
|
||||||
|
|
||||||
// FIXME (introduced by balsoft): this doesn't work for encrypted events, but
|
// FIXME (introduced by balsoft): this doesn't work for encrypted events, but
|
||||||
// allegedly it's hard to fix so I'll leave my first contribution at that
|
// allegedly it's hard to fix so I'll leave my first contribution at that
|
||||||
for (const auto &related_event_id : cache::client()->relatedEvents(room_id_, txn_id)) {
|
for (const auto &pending_event_id : cache::client()->pendingEvents(room_id_)) {
|
||||||
if (cache::client()->getEvent(room_id_, related_event_id)) {
|
if (auto pending_event = cache::client()->getEvent(room_id_, pending_event_id)) {
|
||||||
auto related_event =
|
auto relations = mtx::accessors::relations(pending_event->data);
|
||||||
cache::client()->getEvent(room_id_, related_event_id).value();
|
|
||||||
auto relations = mtx::accessors::relations(related_event.data);
|
|
||||||
|
|
||||||
// Replace the blockquote in fallback reply
|
// Replace the blockquote in fallback reply
|
||||||
auto related_text = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Text>>(
|
auto related_text = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Text>>(
|
||||||
&related_event.data);
|
&pending_event->data);
|
||||||
if (related_text && relations.reply_to() == txn_id) {
|
if (related_text && relations.reply_to() == txn_id) {
|
||||||
size_t index = related_text->content.formatted_body.find(txn_id);
|
size_t index = related_text->content.formatted_body.find(txn_id);
|
||||||
if (index != std::string::npos) {
|
if (index != std::string::npos) {
|
||||||
|
@ -209,13 +207,13 @@ EventStore::EventStore(std::string room_id, QObject *)
|
||||||
rel.event_id = event_id;
|
rel.event_id = event_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
mtx::accessors::set_relations(related_event.data, std::move(relations));
|
mtx::accessors::set_relations(pending_event->data, std::move(relations));
|
||||||
|
|
||||||
cache::client()->replaceEvent(room_id_, related_event_id, related_event);
|
cache::client()->replaceEvent(room_id_, pending_event_id, *pending_event);
|
||||||
|
|
||||||
auto idx = idToIndex(related_event_id);
|
auto idx = idToIndex(pending_event_id);
|
||||||
|
|
||||||
events_by_id_.remove({room_id_, related_event_id});
|
events_by_id_.remove({room_id_, pending_event_id});
|
||||||
events_.remove({room_id_, toInternalIdx(*idx)});
|
events_.remove({room_id_, toInternalIdx(*idx)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue