Allow editing unsent messages

As of 0db4d71ec2 (Prevent edits of
unsent messages), messages that are edits of (or replies to) unsent
messages were not allowed. This change was made because otherwise
the edits were discarded due to use of txnid rather than mxid in the
"m.relates_to" object. Remove this restriction and fix the issue by
replacing txnid with mxid in all related events when the message is
sent (and we obtain mxid from the server).
This commit is contained in:
Alexander Bantyev 2021-06-17 22:27:37 +03:00
parent 9e2b5a1061
commit 9f798e76ed
No known key found for this signature in database
GPG key ID: E081FF12ADCB4AD5
4 changed files with 67 additions and 7 deletions

View file

@ -1681,6 +1681,27 @@ Cache::storeEvent(const std::string &room_id,
txn.commit();
}
void
Cache::replaceEvent(const std::string &room_id,
const std::string &event_id,
const mtx::events::collections::TimelineEvent &event)
{
auto txn = lmdb::txn::begin(env_);
auto eventsDb = getEventsDb(txn, room_id);
auto relationsDb = getRelationsDb(txn, room_id);
auto event_json = mtx::accessors::serialize_event(event.data).dump();
{
eventsDb.del(txn, event_id);
eventsDb.put(txn, event_id, event_json);
for (auto relation : mtx::accessors::relations(event.data).relations) {
relationsDb.put(txn, relation.event_id, event_id);
}
}
txn.commit();
}
std::vector<std::string>
Cache::relatedEvents(const std::string &room_id, const std::string &event_id)
{