From 3d0f50a5b30f1823bb38b4a1fccd2c332f6642b1 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Thu, 15 Oct 2020 13:53:27 +0200 Subject: [PATCH] feat: allow users to configure notification settings Can choose between all, just mentions, or nothing --- src/app/chat/view.nim | 4 ++-- src/status/chat/message.nim | 1 + src/status/signals/messages.nim | 7 ++++--- ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml | 7 +++++-- .../Profile/Sections/NotificationsContainer.qml | 13 ++++++++++++- ui/imports/Constants.qml | 3 +++ ui/main.qml | 1 + 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 723271d221..170df3503d 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -330,7 +330,7 @@ QtObject: proc messagePushed*(self: ChatsView) {.signal.} proc newMessagePushed*(self: ChatsView) {.signal.} - proc messageNotificationPushed*(self: ChatsView, chatId: string, text: string, messageType: string, chatType: int, timestamp: string, identicon: string, username: string) {.signal.} + proc messageNotificationPushed*(self: ChatsView, chatId: string, text: string, messageType: string, chatType: int, timestamp: string, identicon: string, username: string, hasMention: bool) {.signal.} proc messagesCleared*(self: ChatsView) {.signal.} @@ -348,7 +348,7 @@ QtObject: if msg.chatId != self.activeChannel.id: let channel = self.chats.getChannelById(msg.chatId) if not channel.muted: - self.messageNotificationPushed(msg.chatId, msg.text, msg.messageType, channel.chatType.int, msg.timestamp, msg.identicon, msg.alias) + self.messageNotificationPushed(msg.chatId, msg.text, msg.messageType, channel.chatType.int, msg.timestamp, msg.identicon, msg.alias, msg.hasMention) else: discard self.status.chat.markMessagesSeen(msg.chatId, @[msg.id]) self.newMessagePushed() diff --git a/src/status/chat/message.nim b/src/status/chat/message.nim index 0d2b4988ba..7dda8b1134 100644 --- a/src/status/chat/message.nim +++ b/src/status/chat/message.nim @@ -59,6 +59,7 @@ type Message* = object image*: string audio*: string audioDurationMs*: int + hasMention*: bool type Reaction* = object id*: string diff --git a/src/status/signals/messages.nim b/src/status/signals/messages.nim index 6527ee9d62..3b42c1b370 100644 --- a/src/status/signals/messages.nim +++ b/src/status/signals/messages.nim @@ -28,9 +28,9 @@ proc fromEvent*(event: JsonNode): Signal = if event["event"]{"messages"} != nil: for jsonMsg in event["event"]["messages"]: - let message = jsonMsg.toMessage - let hasMentions = concat(message.parsedText.map(t => t.children.filter(c => c.textType == "mention" and c.literal == pk))).len > 0 - if hasMentions: + var message = jsonMsg.toMessage + message.hasMention = concat(message.parsedText.map(t => t.children.filter(c => c.textType == "mention" and c.literal == pk))).len > 0 + if message.hasMention: chatsWithMentions.add(message.chatId) signal.messages.add(message) @@ -185,6 +185,7 @@ proc toMessage*(jsonMsg: JsonNode): Message = image: $jsonMsg{"image"}.getStr, audio: $jsonMsg{"audio"}.getStr, audioDurationMs: jsonMsg{"audioDurationMs"}.getInt, + hasMention: false ) if jsonMsg["parsedText"].kind != JNull: diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index c5865e71cd..88568b21dd 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -144,8 +144,11 @@ ScrollView { }, 500); } - onMessageNotificationPushed: function(chatId, msg, messageType, chatType, timestamp, identicon, username) { - notificationWindow.notifyUser(chatId, msg, messageType, chatType, timestamp, identicon, username) + onMessageNotificationPushed: function(chatId, msg, messageType, chatType, timestamp, identicon, username, hasMention) { + if (appSettings.notificationSetting == Constants.notifyAllMessages || + (appSettings.notificationSetting == Constants.notifyJustMentions && hasMention)) { + notificationWindow.notifyUser(chatId, msg, messageType, chatType, timestamp, identicon, username) + } } } diff --git a/ui/app/AppLayouts/Profile/Sections/NotificationsContainer.qml b/ui/app/AppLayouts/Profile/Sections/NotificationsContainer.qml index d8eefc1af4..caad9574ae 100644 --- a/ui/app/AppLayouts/Profile/Sections/NotificationsContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/NotificationsContainer.qml @@ -54,10 +54,13 @@ ScrollView { } StatusRadioButton { - checked: true Layout.alignment: Qt.AlignRight ButtonGroup.group: notificationSetting rightPadding: 0 + checked: appSettings.notificationSetting === 0 + onCheckedChanged: { + appSettings.notificationSetting = 0 + } } } @@ -72,6 +75,10 @@ ScrollView { Layout.alignment: Qt.AlignRight ButtonGroup.group: notificationSetting rightPadding: 0 + checked: appSettings.notificationSetting === 1 + onCheckedChanged: { + appSettings.notificationSetting = 1 + } } } @@ -86,6 +93,10 @@ ScrollView { Layout.alignment: Qt.AlignRight ButtonGroup.group: notificationSetting rightPadding: 0 + checked: appSettings.notificationSetting === 2 + onCheckedChanged: { + appSettings.notificationSetting = 2 + } } } } diff --git a/ui/imports/Constants.qml b/ui/imports/Constants.qml index f5807e2a99..e14ebf226f 100644 --- a/ui/imports/Constants.qml +++ b/ui/imports/Constants.qml @@ -15,6 +15,9 @@ QtObject { readonly property int limitLongChatText: 500 readonly property int limitLongChatTextCompactMode: 1000 + readonly property int notifyAllMessages: 0 + readonly property int notifyJustMentions: 1 + readonly property int notifyNone: 2 readonly property int fetchMoreMessagesButton: -2 readonly property int chatIdentifier: -1 readonly property int unknownContentType: 0 diff --git a/ui/main.qml b/ui/main.qml index 4dce3253d7..f32902e79e 100644 --- a/ui/main.qml +++ b/ui/main.qml @@ -76,6 +76,7 @@ ApplicationWindow { property string locale: "en" property var recentEmojis: [] property real volume: 0.2 + property int notificationSetting: 0 } Connections { target: profileModel