Reactions are refreshed correctly in the timeline.
This commit is contained in:
@@ -12,31 +12,38 @@ Menu {
|
||||
|
||||
id: root
|
||||
|
||||
Flow {
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 32
|
||||
|
||||
spacing: 0
|
||||
Row {
|
||||
anchors.centerIn: parent
|
||||
|
||||
Repeater {
|
||||
model: ["👍", "👎️", "😄", "🎉", "🚀", "👀"]
|
||||
spacing: 0
|
||||
|
||||
delegate: ItemDelegate {
|
||||
width: 32
|
||||
height: 32
|
||||
Repeater {
|
||||
model: ["👍", "👎️", "😄", "🎉", "🚀", "👀"]
|
||||
|
||||
contentItem: Label {
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
delegate: ItemDelegate {
|
||||
width: 32
|
||||
height: 32
|
||||
|
||||
font.pixelSize: 16
|
||||
text: modelData
|
||||
contentItem: Label {
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
|
||||
font.pixelSize: 16
|
||||
text: modelData
|
||||
}
|
||||
|
||||
onClicked: currentRoom.toggleReaction(eventId, modelData)
|
||||
}
|
||||
|
||||
onClicked: currentRoom.toggleReaction(eventId, modelData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MenuSeparator {}
|
||||
|
||||
MenuItem {
|
||||
text: "View Source"
|
||||
|
||||
|
||||
Submodule include/libQuotient updated: 2fb22758c1...64bea52b86
@@ -136,6 +136,10 @@ void MessageEventModel::setRoom(SpectralRoom* room) {
|
||||
refreshLastUserEvents(refreshEvent(newEvent->id()) -
|
||||
timelineBaseIndex());
|
||||
});
|
||||
connect(m_currentRoom, &Room::updatedEvent, this,
|
||||
[this](const QString& eventId) {
|
||||
refreshEventRoles(eventId, {ReactionRole});
|
||||
});
|
||||
connect(m_currentRoom, &Room::fileTransferProgress, this,
|
||||
&MessageEventModel::refreshEvent);
|
||||
connect(m_currentRoom, &Room::fileTransferCompleted, this,
|
||||
@@ -178,15 +182,24 @@ void MessageEventModel::refreshEventRoles(int row, const QVector<int>& roles) {
|
||||
emit dataChanged(idx, idx, roles);
|
||||
}
|
||||
|
||||
int MessageEventModel::refreshEventRoles(const QString& eventId,
|
||||
int MessageEventModel::refreshEventRoles(const QString& id,
|
||||
const QVector<int>& roles) {
|
||||
const auto it = m_currentRoom->findInTimeline(eventId);
|
||||
if (it == m_currentRoom->timelineEdge()) {
|
||||
qWarning() << "Trying to refresh inexistent event:" << eventId;
|
||||
return -1;
|
||||
// On 64-bit platforms, difference_type for std containers is long long
|
||||
// but Qt uses int throughout its interfaces; hence casting to int below.
|
||||
int row = -1;
|
||||
// First try pendingEvents because it is almost always very short.
|
||||
const auto pendingIt = m_currentRoom->findPendingEvent(id);
|
||||
if (pendingIt != m_currentRoom->pendingEvents().end())
|
||||
row = int(pendingIt - m_currentRoom->pendingEvents().begin());
|
||||
else {
|
||||
const auto timelineIt = m_currentRoom->findInTimeline(id);
|
||||
if (timelineIt == m_currentRoom->timelineEdge()) {
|
||||
qWarning() << "Trying to refresh inexistent event:" << id;
|
||||
return -1;
|
||||
}
|
||||
row = int(timelineIt - m_currentRoom->messageEvents().rbegin()) +
|
||||
timelineBaseIndex();
|
||||
}
|
||||
const auto row =
|
||||
it - m_currentRoom->messageEvents().rbegin() + timelineBaseIndex();
|
||||
refreshEventRoles(row, roles);
|
||||
return row;
|
||||
}
|
||||
@@ -485,14 +498,20 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
||||
m_currentRoom->relatedEvents(evt, EventRelation::Annotation());
|
||||
if (annotations.isEmpty())
|
||||
return {};
|
||||
QMap<QString, QList<SpectralUser*>> reactions;
|
||||
QMap<QString, QList<SpectralUser*>> reactions = {};
|
||||
for (const auto& a : annotations) {
|
||||
if (a->isRedacted()) // Just in case?
|
||||
continue;
|
||||
if (auto e = eventCast<const ReactionEvent>(a))
|
||||
reactions[e->relation().key].append(
|
||||
static_cast<SpectralUser*>(m_currentRoom->user(e->senderId())));
|
||||
}
|
||||
|
||||
QVariantList res;
|
||||
if (reactions.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QVariantList res = {};
|
||||
QMap<QString, QList<SpectralUser*>>::const_iterator i =
|
||||
reactions.constBegin();
|
||||
while (i != reactions.constEnd()) {
|
||||
|
||||
@@ -432,7 +432,7 @@ void SpectralRoom::toggleReaction(const QString& eventId,
|
||||
|
||||
const auto& evt = **eventIt;
|
||||
|
||||
QStringList redactEventIds; // What if there are multiple reaction events?
|
||||
QStringList redactEventIds; // What if there are multiple reaction events?
|
||||
|
||||
const auto& annotations = relatedEvents(evt, EventRelation::Annotation());
|
||||
if (!annotations.isEmpty()) {
|
||||
@@ -450,15 +450,10 @@ void SpectralRoom::toggleReaction(const QString& eventId,
|
||||
}
|
||||
|
||||
if (!redactEventIds.isEmpty()) {
|
||||
qDebug() << "Remove reaction event" << redactEventIds << "of event"
|
||||
<< eventId << ":" << reaction;
|
||||
for (auto redactEventId : redactEventIds) {
|
||||
redactEvent(redactEventId);
|
||||
redactEvent(redactEventId);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Add reaction event" << eventId << ":" << reaction;
|
||||
postEvent(new ReactionEvent(EventRelation::annotate(eventId, reaction)));
|
||||
}
|
||||
|
||||
qDebug() << "End of SpectralRoom::toggleReaction()";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user