Visually show reactions while the server is processing them
Unlike messages, reactions do not have a "pending" state. This problem is more obvious while the server is under heavy load, or your connection is disconnecting often, etc. This creates a pretty terrible UX as you try to add an emoji, and nothing obvious happens. libQuotient gives us the tools to do this, we can take advantage of this. The main missing component is that we depend on a changed RoomMessage event for reaction updates, but in the pending queue the library gives us a ReactionEvent directly. We can process this, and tell ReactionModel to use this while waiting for the message to be updated. I did some code cleanup in ReactionModel while I'm touching it as well.
This commit is contained in:
@@ -428,7 +428,7 @@ void MessageModel::refreshLastUserEvents(int baseTimelineRow)
|
||||
}
|
||||
}
|
||||
|
||||
void MessageModel::createEventObjects(const Quotient::RoomEvent *event)
|
||||
void MessageModel::createEventObjects(const Quotient::RoomEvent *event, bool pending)
|
||||
{
|
||||
if (event == nullptr) {
|
||||
return;
|
||||
@@ -469,6 +469,28 @@ void MessageModel::createEventObjects(const Quotient::RoomEvent *event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pending) {
|
||||
if (const auto reactionEvent = eventCast<const ReactionEvent>(event)) {
|
||||
auto targetEvent = m_currentRoom->getEvent(reactionEvent->eventId());
|
||||
if (!targetEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (const auto roomEvent = eventCast<const RoomMessageEvent>(targetEvent)) {
|
||||
if (m_reactionModels.contains(targetEvent->id())) {
|
||||
m_reactionModels[targetEvent->id()]->queueReaction(reactionEvent);
|
||||
} else {
|
||||
auto reactionModel = QSharedPointer<ReactionModel>(new ReactionModel(roomEvent, m_currentRoom));
|
||||
m_reactionModels[targetEvent->id()] = reactionModel;
|
||||
reactionModel->queueReaction(reactionEvent);
|
||||
if (!resetting) {
|
||||
refreshEventRoles(targetEvent->id(), {ReactionRole, ShowReactionsRole});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageModel::moveReadMarker(const QString &toEventId)
|
||||
|
||||
@@ -192,7 +192,7 @@ protected:
|
||||
private:
|
||||
QMap<QString, QSharedPointer<ReadMarkerModel>> m_readMarkerModels;
|
||||
|
||||
void createEventObjects(const Quotient::RoomEvent *event);
|
||||
void createEventObjects(const Quotient::RoomEvent *event, bool pending);
|
||||
|
||||
static std::function<bool(const Quotient::RoomEvent *)> m_hiddenFilter;
|
||||
static bool m_threadsEnabled;
|
||||
|
||||
Reference in New Issue
Block a user