From 9070caa2a3347f492bafca97e79c88debec6cb62 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Wed, 16 Sep 2020 20:43:36 +0200 Subject: [PATCH] Mute/unmute chats both from list and in chat --- qml/pages/ChatPage.qml | 24 ++++++++++++++++++++++++ qml/pages/OverviewPage.qml | 6 +++--- rpm/harbour-fernschreiber.spec | 2 +- rpm/harbour-fernschreiber.yaml | 2 +- src/chatlistmodel.cpp | 15 +++++++++++++++ src/chatlistmodel.h | 1 + src/chatmodel.cpp | 15 +++++++++++++++ src/chatmodel.h | 3 +++ src/tdlibreceiver.cpp | 8 ++++++++ src/tdlibreceiver.h | 2 ++ src/tdlibwrapper.cpp | 6 ++++++ src/tdlibwrapper.h | 2 ++ translations/harbour-fernschreiber-de.ts | 12 ++++++++++-- translations/harbour-fernschreiber.ts | 8 ++++++++ 14 files changed, 99 insertions(+), 7 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 55d794b..7379f57 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -223,6 +223,30 @@ Page { contentWidth: parent.width anchors.fill: parent + PullDownMenu { + MenuItem { + id: muteChatMenuItem + onClicked: { + var newNotificationSettings = chatInformation.notification_settings; + if (newNotificationSettings.mute_for > 0) { + newNotificationSettings.mute_for = 0; + } else { + newNotificationSettings.mute_for = 6666666; + } + tdLibWrapper.setChatNotificationSettings(chatInformation.id, newNotificationSettings); + } + text: chatInformation.notification_settings.mute_for > 0 ? qsTr("Unmute Chat") : qsTr("Mute Chat") + } + } + + Connections { + target: chatModel + onNotificationSettingsUpdated: { + chatInformation = chatModel.getChatInformation(); + muteChatMenuItem.text = chatInformation.notification_settings.mute_for > 0 ? qsTr("Unmute Chat") : qsTr("Mute Chat"); + } + } + Column { id: chatColumn width: parent.width diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index 8b33e8d..a5b8e03 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -230,7 +230,7 @@ Page { if (newNotificationSettings.mute_for > 0) { newNotificationSettings.mute_for = 0; } else { - newNotificationSettings.mute_for = 666666; + newNotificationSettings.mute_for = 6666666; } tdLibWrapper.setChatNotificationSettings(display.id, newNotificationSettings); } @@ -246,7 +246,7 @@ Page { chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : ""; chatUnreadMessagesCountBackground.visible = display.unread_count > 0; chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count; - chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) : qsTr("Unknown"); + chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown") chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true), Theme.fontSizeExtraSmall) : qsTr("Unknown"); messageContactTimeElapsedText.text = (typeof display.last_message !== "undefined") ? Functions.getDateTimeElapsed(display.last_message.date) : qsTr("Unknown"); } @@ -318,7 +318,7 @@ Page { Text { id: chatListNameText - text: display.title !== "" ? Emoji.emojify(display.title, font.pixelSize) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", font.pixelSize) : "" ) : qsTr("Unknown") + text: display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown") textFormat: Text.StyledText font.pixelSize: Theme.fontSizeMedium color: Theme.primaryColor diff --git a/rpm/harbour-fernschreiber.spec b/rpm/harbour-fernschreiber.spec index 13e5b3c..f63daa0 100644 --- a/rpm/harbour-fernschreiber.spec +++ b/rpm/harbour-fernschreiber.spec @@ -12,7 +12,7 @@ Name: harbour-fernschreiber Summary: Fernschreiber is a Telegram client for Sailfish OS Version: 0.1 -Release: 4 +Release: 5 Group: Qt/Qt License: LICENSE URL: http://werkwolf.eu/ diff --git a/rpm/harbour-fernschreiber.yaml b/rpm/harbour-fernschreiber.yaml index cd1a805..5973bfc 100644 --- a/rpm/harbour-fernschreiber.yaml +++ b/rpm/harbour-fernschreiber.yaml @@ -1,7 +1,7 @@ Name: harbour-fernschreiber Summary: Fernschreiber is a Telegram client for Sailfish OS Version: 0.1 -Release: 4 +Release: 5 # The contents of the Group field should be one of the groups listed here: # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS Group: Qt/Qt diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index 02e47fe..0af4467 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -31,6 +31,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int))); connect(this->tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString))); connect(this->tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap))); + connect(this->tdLibWrapper, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap))); } ChatListModel::~ChatListModel() @@ -170,6 +171,20 @@ void ChatListModel::handleMessageSendSucceeded(const QString &messageId, const Q this->chatListMutex.unlock(); } +void ChatListModel::handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings) +{ + this->chatListMutex.lock(); + int chatIndex = this->chatIndexMap.value(chatId).toInt(); + qDebug() << "[ChatListModel] Updating notification settings for chat " << chatId << " at index " << chatIndex; + QVariantMap currentChat = this->chatList.value(chatIndex).toMap(); + currentChat.insert("notification_settings", chatNotificationSettings); + this->chatList.replace(chatIndex, currentChat); + emit dataChanged(this->index(chatIndex), this->index(chatIndex)); + emit chatChanged(chatId); + + this->chatListMutex.unlock(); +} + void ChatListModel::updateChatOrder(const int ¤tChatIndex, const QVariantMap &updatedChat) { // Finding the new position manually as information is needed by beginMoveRows() diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index c0dee72..1aa7e96 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -48,6 +48,7 @@ public slots: void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount); void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId); void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message); + void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings); private: TDLibWrapper *tdLibWrapper; diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 1ddd22f..605864d 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -33,6 +33,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper) connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int))); connect(this->tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString))); connect(this->tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap))); + connect(this->tdLibWrapper, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap))); } ChatModel::~ChatModel() @@ -85,6 +86,11 @@ void ChatModel::triggerLoadMoreHistory() } } +QVariantMap ChatModel::getChatInformation() +{ + return this->chatInformation; +} + bool compareMessages(const QVariant &message1, const QVariant &message2) { QVariantMap messageMap1 = message1.toMap(); @@ -199,6 +205,15 @@ void ChatModel::handleMessageSendSucceeded(const QString &messageId, const QStri } } +void ChatModel::handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings) +{ + if (chatId == this->chatId) { + this->chatInformation.insert("notification_settings", chatNotificationSettings); + qDebug() << "[ChatModel] Notification settings updated"; + emit notificationSettingsUpdated(); + } +} + void ChatModel::insertMessages() { if (this->messages.isEmpty()) { diff --git a/src/chatmodel.h b/src/chatmodel.h index 30bb3d9..2182820 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -38,6 +38,7 @@ public: Q_INVOKABLE void initialize(const QVariantMap &chatInformation); Q_INVOKABLE void triggerLoadMoreHistory(); + Q_INVOKABLE QVariantMap getChatInformation(); signals: void messagesReceived(const int &modelIndex, const int &lastReadSentIndex); @@ -45,6 +46,7 @@ signals: void newMessageReceived(); void unreadCountUpdated(const int &unreadCount, const QString &lastReadInboxMessageId); void lastReadSentMessageUpdated(const int &lastReadSentIndex); + void notificationSettingsUpdated(); public slots: void handleMessagesReceived(const QVariantList &messages); @@ -52,6 +54,7 @@ public slots: void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount); void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId); void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message); + void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings); private: diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index d2089b3..47aead9 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -77,6 +77,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc if (objectTypeName == "updateMessageSendSucceeded") { this->processMessageSendSucceeded(receivedInformation); } if (objectTypeName == "updateActiveNotifications") { this->processUpdateActiveNotifications(receivedInformation); } if (objectTypeName == "updateNotificationGroup") { this->processUpdateNotificationGroup(receivedInformation); } + if (objectTypeName == "updateChatNotificationSettings") { this->processUpdateChatNotificationSettings(receivedInformation); } } void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation) @@ -258,3 +259,10 @@ void TDLibReceiver::processUpdateNotification(const QVariantMap &receivedInforma qDebug() << "[TDLibReceiver] Received notification update"; emit notificationUpdated(receivedInformation); } + +void TDLibReceiver::processUpdateChatNotificationSettings(const QVariantMap &receivedInformation) +{ + QString chatId = receivedInformation.value("chat_id").toString(); + qDebug() << "[TDLibReceiver] Received new notification settings for chat " << chatId; + emit chatNotificationSettingsUpdated(chatId, receivedInformation.value("notification_settings").toMap()); +} diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index eb6829c..7c517fb 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -60,6 +60,7 @@ signals: void activeNotificationsUpdated(const QVariantList notificationGroups); void notificationGroupUpdated(const QVariantMap notificationGroupUpdate); void notificationUpdated(const QVariantMap updatedNotification); + void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap updatedChatNotificationSettings); private: void *tdLibClient; @@ -91,6 +92,7 @@ private: void processUpdateActiveNotifications(const QVariantMap &receivedInformation); void processUpdateNotificationGroup(const QVariantMap &receivedInformation); void processUpdateNotification(const QVariantMap &receivedInformation); + void processUpdateChatNotificationSettings(const QVariantMap &receivedInformation); }; #endif // TDLIBRECEIVER_H diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 03fffbe..45fd1ad 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -69,6 +69,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent) connect(this->tdLibReceiver, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList))); connect(this->tdLibReceiver, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap))); connect(this->tdLibReceiver, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(QVariantMap))); + connect(this->tdLibReceiver, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap))); this->tdLibReceiver->start(); @@ -550,6 +551,11 @@ void TDLibWrapper::handleUpdateNotification(const QVariantMap updatedNotificatio emit notificationUpdated(updatedNotification); } +void TDLibWrapper::handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings) +{ + emit chatNotificationSettingsUpdated(chatId, chatNotificationSettings); +} + void TDLibWrapper::setInitialParameters() { qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 0c55d28..d4e5a38 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -118,6 +118,7 @@ signals: void activeNotificationsUpdated(const QVariantList notificationGroups); void notificationGroupUpdated(const QVariantMap notificationGroupUpdate); void notificationUpdated(const QVariantMap updatedNotification); + void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings); public slots: void handleVersionDetected(const QString &version); @@ -144,6 +145,7 @@ public slots: void handleUpdateActiveNotifications(const QVariantList notificationGroups); void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate); void handleUpdateNotification(const QVariantMap updatedNotification); + void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings); private: void *tdLibClient; diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index abe71bc..b1b3961 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -153,6 +153,14 @@ Loading messages... Lade Nachrichten... + + Unmute Chat + Stummschaltung des Chats aufheben + + + Mute Chat + Chat stummschalten + CoverPage @@ -360,11 +368,11 @@ Unmute Chat - + Stummschaltung des Chats aufheben Mute Chat - + Chat stummschalten diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 01fb2f6..c20bc13 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -153,6 +153,14 @@ Loading messages... + + Unmute Chat + + + + Mute Chat + + CoverPage