Let qml know the message reply was sent.
authorCamila <hello@camila.codes>
Thu, 24 Mar 2022 17:56:39 +0000 (18:56 +0100)
committerCamila <hello@camila.codes>
Mon, 28 Mar 2022 14:04:54 +0000 (16:04 +0200)
Signed-off-by: Camila <hello@camila.codes>
src/gui/tray/TalkReplyTextField.qml
src/gui/tray/activitydata.h
src/gui/tray/activitylistmodel.cpp
src/gui/tray/activitylistmodel.h
src/gui/tray/usermodel.cpp
src/gui/tray/usermodel.h

index e59c22cecb168cc9cf038ae0133274abb657dbba..c4b1581f37badbfae78aa535a6258166d4cdee08 100644 (file)
@@ -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 {
index bd7b49ffc055959ab86e1d79b72fc5b6c8591470..9c035e2a32216f45c9f98d05c3b7237fe78474f6 100644 (file)
@@ -112,6 +112,7 @@ public:
     struct TalkNotificationData {
         QString conversationToken;
         QString messageId;
+        QString messageSent;
     };
 
     Type _type;
index 7c75d178e38c60b5daf9c6cf7fe1dbdd0d65d7f6..dc5363cfdc0407f9f056b6460633accf1389e40f 100644 (file)
@@ -79,6 +79,7 @@ QHash<int, QByteArray> 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;
+}
+
+
 }
 
index 2ff879f8b91ab56616b6d86366a6fa6656ed0d4a..19e54ac9fe4c93c9c8c50777bc0c127600fe34f2 100644 (file)
@@ -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();
index 1298fc627d2dc2b5d413c16d1f0c9c00eb8bfac6..41590bf06a9474ee16cddb2375fd9dad62db85ea 100644 (file)
@@ -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> 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<int, QByteArray> UserAppsModel::roleNames() const
     roles[IconUrlRole] = "appIconUrl";
     return roles;
 }
-
 }
index 2f1fdc74d6dd746a7f577ea9ce9f4be023b94194..81036f940c394e1ddc7828c04690fc4dcf7be42c 100644 (file)
@@ -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