From a1661f7006d7661bfd54cdd9971afd6717ed9c92 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Thu, 7 May 2020 20:53:24 -0400 Subject: [PATCH] merge master into reactions --- resources/qml/ImageButton.qml | 3 ++- resources/qml/TimelineRow.qml | 13 ++++++++++++- resources/qml/TimelineView.qml | 5 ++++- resources/qml/delegates/Pill.qml | 5 ++++- src/ChatPage.cpp | 8 ++++++++ src/ChatPage.h | 1 + src/timeline/TimelineModel.cpp | 7 +++++++ src/timeline/TimelineModel.h | 20 +++++++++++++++++++- src/timeline/TimelineViewManager.cpp | 14 ++++++++++++++ src/timeline/TimelineViewManager.h | 4 +++- 10 files changed, 74 insertions(+), 6 deletions(-) diff --git a/resources/qml/ImageButton.qml b/resources/qml/ImageButton.qml index dd100503..dd67d597 100644 --- a/resources/qml/ImageButton.qml +++ b/resources/qml/ImageButton.qml @@ -3,7 +3,8 @@ import QtQuick.Controls 2.3 AbstractButton { property string image: undefined - + width: 16 + height: 16 id: button Image { diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index 22222ef3..de71fb69 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -71,7 +71,18 @@ MouseArea { Layout.preferredHeight: 16 width: 16 } - + ImageButton { + visible: timelineSettings.buttons + Layout.alignment: Qt.AlignRight | Qt.AlignTop + Layout.preferredHeight: 16 + width: 16 + id: reactButton + hoverEnabled: true + image: ":/icons/icons/ui/smile.png" + ToolTip.visible: hovered + ToolTip.text: qsTr("React") + onClicked: chat.model.reactAction(model.id) + } ImageButton { visible: timelineSettings.buttons Layout.alignment: Qt.AlignRight | Qt.AlignTop diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index eca646d1..9a360726 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -48,7 +48,10 @@ Page { property string eventId property int eventType property bool isEncrypted - + MenuItem { + text: qsTr("React") + onClicked: chat.model.reactAction(messageContextMenu.eventId) + } MenuItem { text: qsTr("Reply") onClicked: chat.model.replyAction(messageContextMenu.eventId) diff --git a/resources/qml/delegates/Pill.qml b/resources/qml/delegates/Pill.qml index c4260c33..23a69b10 100644 --- a/resources/qml/delegates/Pill.qml +++ b/resources/qml/delegates/Pill.qml @@ -2,6 +2,9 @@ import QtQuick 2.5 import QtQuick.Controls 2.1 Label { + id: pillComponent + property color userColor: "red" + color: colors.brightText horizontalAlignment: Text.AlignHCenter @@ -10,6 +13,6 @@ Label { background: Rectangle { radius: parent.height / 2 - color: colors.dark + color: Qt.rgba(userColor.r, userColor.g, userColor.b, 0.2) } } diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index ae3c7a11..01075173 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -582,6 +582,14 @@ ChatPage::resetUI() showUnreadMessageNotification(0); } +void +ChatPage::reactMessage(const QString &id) +{ + view_manager_->queueReactionMessage(current_room_, + id, + "👀"); +} + void ChatPage::focusMessageInput() { diff --git a/src/ChatPage.h b/src/ChatPage.h index 46630692..94a5db59 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -85,6 +85,7 @@ public: //! Show the room/group list (if it was visible). void showSideBars(); void initiateLogout(); + void reactMessage(const QString &eventId); void focusMessageInput(); public slots: diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 388a5842..022267d0 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -914,6 +914,13 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEventreactMessage(id); +} + void TimelineModel::replyAction(QString id) { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index a737aac7..df231925 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -126,6 +126,7 @@ class TimelineModel : public QAbstractListModel int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(std::vector typingUsers READ typingUsers WRITE updateTypingUsers NOTIFY typingUsersChanged) + Q_PROPERTY(QString reaction READ reaction WRITE setReaction NOTIFY reactionChanged RESET resetReaction) Q_PROPERTY(QString reply READ reply WRITE setReply NOTIFY replyChanged RESET resetReply) Q_PROPERTY( bool paginationInProgress READ paginationInProgress NOTIFY paginationInProgressChanged) @@ -187,6 +188,7 @@ public: Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void viewDecryptedRawMessage(QString id) const; Q_INVOKABLE void openUserProfile(QString userid) const; + Q_INVOKABLE void reactAction(QString id); Q_INVOKABLE void replyAction(QString id); Q_INVOKABLE void readReceiptsAction(QString id) const; Q_INVOKABLE void redactEvent(QString id); @@ -215,7 +217,21 @@ public slots: } std::vector typingUsers() const { return typingUsers_; } bool paginationInProgress() const { return m_paginationInProgress; } - + QString reaction() const { return reaction_; } + void setReaction(QString reaction) + { + if (reaction_ != reaction) { + reaction_ = reaction; + emit reactionChanged(reaction_); + } + } + void resetReaction() + { + if (!reaction_.isEmpty()) { + reaction_ = ""; + emit reactionChanged(reaction_); + } + } QString reply() const { return reply_; } void setReply(QString newReply) { @@ -252,6 +268,7 @@ signals: void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo); void eventFetched(QString requestingEvent, mtx::events::collections::TimelineEvents event); void typingUsersChanged(std::vector users); + void reactionChanged(QString reaction); void replyChanged(QString reply); void paginationInProgressChanged(const bool); @@ -285,6 +302,7 @@ private: bool m_paginationInProgress = false; QString currentId; + QString reaction_; QString reply_; std::vector typingUsers_; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index b9565be8..f17e3090 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -282,6 +282,20 @@ TimelineViewManager::queueEmoteMessage(const QString &msg) timeline_->sendMessage(emote); } +void +TimelineViewManager::queueReactionMessage(const QString &roomId, + const QString &reactedEvent, + const QString &reactionKey) +{ + mtx::events::msg::Reaction reaction; + reaction.relates_to.rel_type = mtx::common::RelationType::Annotation; + reaction.relates_to.event_id = reactedEvent.toStdString(); + reaction.relates_to.key = reactionKey.toStdString(); + + auto model = models.value(roomId); + model->sendMessage(reaction); +} + void TimelineViewManager::queueImageMessage(const QString &roomid, const QString &filename, diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 45a603af..eb2223e2 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -55,7 +55,9 @@ public slots: void setHistoryView(const QString &room_id); void updateColorPalette(); - + void queueReactionMessage(const QString &roomId, + const QString &reactedEvent, + const QString &reaction); void queueTextMessage(const QString &msg); void queueEmoteMessage(const QString &msg); void queueImageMessage(const QString &roomid,