Display reactions in MessageDelegate.
This commit is contained in:
@@ -220,6 +220,12 @@ ColumnLayout {
|
|||||||
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReactionDelegate {
|
||||||
|
Layout.bottomMargin: 8
|
||||||
|
Layout.leftMargin: 16
|
||||||
|
Layout.rightMargin: 16
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
imports/Spectral/Component/Timeline/ReactionDelegate.qml
Normal file
28
imports/Spectral/Component/Timeline/ReactionDelegate.qml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.12
|
||||||
|
import QtQuick.Layouts 1.12
|
||||||
|
import Spectral.Setting 0.1
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
visible: reaction || false
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: reaction
|
||||||
|
|
||||||
|
delegate: Control {
|
||||||
|
horizontalPadding: 4
|
||||||
|
verticalPadding: 0
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
radius: height / 2
|
||||||
|
color: MPalette.banner
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: Label {
|
||||||
|
text: modelData.reaction + " " + modelData.count
|
||||||
|
font.pixelSize: 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -5,3 +5,4 @@ SectionDelegate 2.0 SectionDelegate.qml
|
|||||||
ImageDelegate 2.0 ImageDelegate.qml
|
ImageDelegate 2.0 ImageDelegate.qml
|
||||||
FileDelegate 2.0 FileDelegate.qml
|
FileDelegate 2.0 FileDelegate.qml
|
||||||
VideoDelegate 2.0 VideoDelegate.qml
|
VideoDelegate 2.0 VideoDelegate.qml
|
||||||
|
ReactionDelegate 2.0 ReactionDelegate.qml
|
||||||
|
|||||||
1
res.qrc
1
res.qrc
@@ -57,5 +57,6 @@
|
|||||||
<file>imports/Spectral/Dialog/OpenFolderDialog.qml</file>
|
<file>imports/Spectral/Dialog/OpenFolderDialog.qml</file>
|
||||||
<file>imports/Spectral/Component/Timeline/VideoDelegate.qml</file>
|
<file>imports/Spectral/Component/Timeline/VideoDelegate.qml</file>
|
||||||
<file>imports/Spectral/Component/AutoRectangle.qml</file>
|
<file>imports/Spectral/Component/AutoRectangle.qml</file>
|
||||||
|
<file>imports/Spectral/Component/Timeline/ReactionDelegate.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <settings.h>
|
#include <settings.h>
|
||||||
#include <user.h>
|
#include <user.h>
|
||||||
|
|
||||||
|
#include <events/reactionevent.h>
|
||||||
#include <events/redactionevent.h>
|
#include <events/redactionevent.h>
|
||||||
#include <events/roomavatarevent.h>
|
#include <events/roomavatarevent.h>
|
||||||
#include <events/roommemberevent.h>
|
#include <events/roommemberevent.h>
|
||||||
@@ -35,6 +36,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const {
|
|||||||
roles[ShowAuthorRole] = "showAuthor";
|
roles[ShowAuthorRole] = "showAuthor";
|
||||||
roles[ShowSectionRole] = "showSection";
|
roles[ShowSectionRole] = "showSection";
|
||||||
roles[BubbleShapeRole] = "bubbleShape";
|
roles[BubbleShapeRole] = "bubbleShape";
|
||||||
|
roles[ReactionRole] = "reaction";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,7 +359,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
|||||||
return EventStatus::Hidden;
|
return EventStatus::Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is<RedactionEvent>(evt))
|
if (is<RedactionEvent>(evt) || is<ReactionEvent>(evt))
|
||||||
return EventStatus::Hidden;
|
return EventStatus::Hidden;
|
||||||
if (evt.isRedacted())
|
if (evt.isRedacted())
|
||||||
return EventStatus::Hidden;
|
return EventStatus::Hidden;
|
||||||
@@ -417,9 +419,9 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
|||||||
return QVariantMap{
|
return QVariantMap{
|
||||||
{"eventId", replyEventId},
|
{"eventId", replyEventId},
|
||||||
{"display", utils::cleanHTML(utils::removeReply(
|
{"display", utils::cleanHTML(utils::removeReply(
|
||||||
m_currentRoom->eventToString(replyEvt, Qt::RichText)))},
|
m_currentRoom->eventToString(replyEvt, Qt::RichText)))},
|
||||||
{"author", QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()))}
|
{"author",
|
||||||
};
|
QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()))}};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ShowAuthorRole) {
|
if (role == ShowAuthorRole) {
|
||||||
@@ -478,6 +480,35 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
|||||||
return BubbleShapes::MiddleShape;
|
return BubbleShapes::MiddleShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == ReactionRole) {
|
||||||
|
const auto& annotations =
|
||||||
|
m_currentRoom->relatedEvents(evt, EventRelation::Annotation());
|
||||||
|
if (annotations.isEmpty())
|
||||||
|
return {};
|
||||||
|
QMap<QString, QList<SpectralUser*>> reactions;
|
||||||
|
for (const auto& a : annotations) {
|
||||||
|
if (auto e = eventCast<const ReactionEvent>(a))
|
||||||
|
reactions[e->relation().key].append(
|
||||||
|
static_cast<SpectralUser*>(m_currentRoom->user(e->senderId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantList res;
|
||||||
|
QMap<QString, QList<SpectralUser*>>::const_iterator i =
|
||||||
|
reactions.constBegin();
|
||||||
|
while (i != reactions.constEnd()) {
|
||||||
|
QVariantList authors;
|
||||||
|
for (auto author : i.value()) {
|
||||||
|
authors.append(QVariant::fromValue(author));
|
||||||
|
}
|
||||||
|
res.append(QVariantMap{{"reaction", i.key()},
|
||||||
|
{"count", i.value().count()},
|
||||||
|
{"authors", authors}});
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ class MessageEventModel : public QAbstractListModel {
|
|||||||
|
|
||||||
BubbleShapeRole,
|
BubbleShapeRole,
|
||||||
|
|
||||||
|
ReactionRole,
|
||||||
|
|
||||||
// For debugging
|
// For debugging
|
||||||
EventResolvedTypeRole,
|
EventResolvedTypeRole,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user