Try to fix flickering, if sync return event before send completes

This commit is contained in:
Nicolas Werner 2020-02-16 00:20:41 +01:00
parent 70f4a89d10
commit ec9da9f42a
3 changed files with 36 additions and 0 deletions

View file

@ -207,6 +207,20 @@ struct EventInReplyTo
} }
}; };
struct EventTransactionId
{
template<class T>
std::string operator()(const mtx::events::RoomEvent<T> &e)
{
return e.unsigned_data.transaction_id;
}
template<class T>
std::string operator()(const mtx::events::Event<T> &e)
{
return e.unsigned_data.transaction_id;
}
};
struct EventMediaHeight struct EventMediaHeight
{ {
template<class Content> template<class Content>
@ -344,6 +358,12 @@ mtx::accessors::in_reply_to_event(const mtx::events::collections::TimelineEvents
return std::visit(EventInReplyTo{}, event); return std::visit(EventInReplyTo{}, event);
} }
std::string
mtx::accessors::transaction_id(const mtx::events::collections::TimelineEvents &event)
{
return std::visit(EventTransactionId{}, event);
}
int64_t int64_t
mtx::accessors::filesize(const mtx::events::collections::TimelineEvents &event) mtx::accessors::filesize(const mtx::events::collections::TimelineEvents &event)
{ {

View file

@ -50,6 +50,8 @@ std::string
mimetype(const mtx::events::collections::TimelineEvents &event); mimetype(const mtx::events::collections::TimelineEvents &event);
std::string std::string
in_reply_to_event(const mtx::events::collections::TimelineEvents &event); in_reply_to_event(const mtx::events::collections::TimelineEvents &event);
std::string
transaction_id(const mtx::events::collections::TimelineEvents &event);
int64_t int64_t
filesize(const mtx::events::collections::TimelineEvents &event); filesize(const mtx::events::collections::TimelineEvents &event);

View file

@ -538,6 +538,20 @@ TimelineModel::internalAddEvents(
continue; continue;
} }
QString txid = QString::fromStdString(mtx::accessors::transaction_id(e));
if (this->pending.removeOne(txid)) {
this->events.insert(id, e);
this->events.remove(txid);
int idx = idToIndex(txid);
if (idx < 0) {
nhlog::ui()->warn("Received index out of range");
continue;
}
eventOrder[idx] = id;
emit dataChanged(index(idx, 0), index(idx, 0));
continue;
}
if (auto redaction = if (auto redaction =
std::get_if<mtx::events::RedactionEvent<mtx::events::msg::Redaction>>(&e)) { std::get_if<mtx::events::RedactionEvent<mtx::events::msg::Redaction>>(&e)) {
QString redacts = QString::fromStdString(redaction->redacts); QString redacts = QString::fromStdString(redaction->redacts);