From: Camila Date: Thu, 24 Mar 2022 17:56:39 +0000 (+0100) Subject: Let qml know the message reply was sent. X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~17^2~87^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b2056187a0a22b54b929060c8eacf348ac888162;p=nextcloud-desktop.git Let qml know the message reply was sent. Signed-off-by: Camila --- diff --git a/src/gui/tray/TalkReplyTextField.qml b/src/gui/tray/TalkReplyTextField.qml index e59c22cec..c4b1581f3 100644 --- a/src/gui/tray/TalkReplyTextField.qml +++ b/src/gui/tray/TalkReplyTextField.qml @@ -7,14 +7,20 @@ import com.nextcloud.desktopclient 1.0 Item { id: root + Connections { + target: activityModel + function onMessageSent() { + replyMessageTextField.clear(); + replyMessageSent.text = activityModel.talkReplyMessageSent(model.index); + } + } + function sendReplyMessage() { if (replyMessageTextField.text === "") { return; } - UserModel.currentUser.sendReplyMessage(model.conversationToken, replyMessageTextField.text, model.messageId); - replyMessageSent.text = replyMessageTextField.text; - replyMessageTextField.clear(); + UserModel.currentUser.sendReplyMessage(model.index, model.conversationToken, replyMessageTextField.text, model.messageId); } Text { diff --git a/src/gui/tray/activitydata.h b/src/gui/tray/activitydata.h index bd7b49ffc..9c035e2a3 100644 --- a/src/gui/tray/activitydata.h +++ b/src/gui/tray/activitydata.h @@ -112,6 +112,7 @@ public: struct TalkNotificationData { QString conversationToken; QString messageId; + QString messageSent; }; Type _type; diff --git a/src/gui/tray/activitylistmodel.cpp b/src/gui/tray/activitylistmodel.cpp index 7c75d178e..dc5363cfd 100644 --- a/src/gui/tray/activitylistmodel.cpp +++ b/src/gui/tray/activitylistmodel.cpp @@ -79,6 +79,7 @@ QHash ActivityListModel::roleNames() const roles[ThumbnailRole] = "thumbnail"; roles[TalkNotificationConversationTokenRole] = "conversationToken"; roles[TalkNotificationMessageIdRole] = "messageId"; + roles[TalkNotificationMessageSentRole] = "messageSent"; return roles; } @@ -329,6 +330,8 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const return a._talkNotificationData.conversationToken; case TalkNotificationMessageIdRole: return a._talkNotificationData.messageId; + case TalkNotificationMessageSentRole: + return a._talkNotificationData.messageSent; default: return QVariant(); } @@ -808,5 +811,28 @@ void ActivityListModel::slotRemoveAccount() _showMoreActivitiesAvailableEntry = false; } +void ActivityListModel::replyMessageSent(const int activityIndex, const QString &message) +{ + if (activityIndex < 0 || activityIndex >= _finalList.size()) { + qCWarning(lcActivity) << "Couldn't trigger action on activity at index" << activityIndex << "/ final list size:" << _finalList.size(); + return; + } + + _finalList[activityIndex]._talkNotificationData.messageSent = message; + + emit messageSent(); +} + +QString ActivityListModel::talkReplyMessageSent(const int activityIndex) const +{ + if (activityIndex < 0 || activityIndex >= _finalList.size()) { + qCWarning(lcActivity) << "Couldn't trigger action on activity at index" << activityIndex << "/ final list size:" << _finalList.size(); + return {}; + } + + return _finalList[activityIndex]._talkNotificationData.messageSent; +} + + } diff --git a/src/gui/tray/activitylistmodel.h b/src/gui/tray/activitylistmodel.h index 2ff879f8b..19e54ac9f 100644 --- a/src/gui/tray/activitylistmodel.h +++ b/src/gui/tray/activitylistmodel.h @@ -43,6 +43,7 @@ class ActivityListModel : public QAbstractListModel Q_PROPERTY(quint32 maxActionButtons READ maxActionButtons CONSTANT) Q_PROPERTY(AccountState *accountState READ accountState CONSTANT) + public: enum DataRole { DarkIconRole = Qt::UserRole + 1, @@ -70,6 +71,7 @@ public: ThumbnailRole, TalkNotificationConversationTokenRole, TalkNotificationMessageIdRole, + TalkNotificationMessageSentRole, }; Q_ENUM(DataRole) @@ -104,6 +106,9 @@ public: void setCurrentItem(const int currentItem); + void replyMessageSent(const int activityIndex, const QString &message); + Q_INVOKABLE QString talkReplyMessageSent(const int activityIndex) const; + public slots: void slotRefreshActivity(); void slotRemoveAccount(); @@ -114,6 +119,8 @@ public slots: signals: void activityJobStatusCode(int statusCode); void sendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row); + void messageSent(); + protected: void setup(); diff --git a/src/gui/tray/usermodel.cpp b/src/gui/tray/usermodel.cpp index 1298fc627..41590bf06 100644 --- a/src/gui/tray/usermodel.cpp +++ b/src/gui/tray/usermodel.cpp @@ -793,10 +793,13 @@ void User::removeAccount() const AccountManager::instance()->save(); } -void User::slotSendReplyMessage(const QString &token, const QString &message, const QString &replyTo) +void User::slotSendReplyMessage(const int activityIndex, const QString &token, const QString &message, const QString &replyTo) { QPointer talkReply = new TalkReply(_account.data(), this); talkReply->sendReplyMessage(token, message, replyTo); + connect(talkReply, &TalkReply::replyMessageSent, this, [&](const QString &message) { + _activityModel->replyMessageSent(activityIndex, message); + }); } /*-------------------------------------------------------------------------------------*/ @@ -1230,5 +1233,4 @@ QHash UserAppsModel::roleNames() const roles[IconUrlRole] = "appIconUrl"; return roles; } - } diff --git a/src/gui/tray/usermodel.h b/src/gui/tray/usermodel.h index 2f1fdc74d..81036f940 100644 --- a/src/gui/tray/usermodel.h +++ b/src/gui/tray/usermodel.h @@ -87,7 +87,7 @@ signals: void headerColorChanged(); void headerTextColorChanged(); void accentColorChanged(); - void sendReplyMessage(const QString &token, const QString &message, const QString &replyTo); + void sendReplyMessage(const int activityIndex, const QString &conversationToken, const QString &message, const QString &replyTo); public slots: void slotItemCompleted(const QString &folder, const SyncFileItemPtr &item); @@ -107,7 +107,7 @@ public slots: void slotRefreshImmediately(); void setNotificationRefreshInterval(std::chrono::milliseconds interval); void slotRebuildNavigationAppList(); - void slotSendReplyMessage(const QString &conversationToken, const QString &message, const QString &replyTo); + void slotSendReplyMessage(const int activityIndex, const QString &conversationToken, const QString &message, const QString &replyTo); private: void slotPushNotificationsReady(); @@ -142,7 +142,6 @@ private: // number of currently running notification requests. If non zero, // no query for notifications is started. int _notificationRequestsRunning; - QString textSentStr; }; class UserModel : public QAbstractListModel @@ -255,6 +254,5 @@ private: AccountAppList _apps; }; - } #endif // USERMODEL_H