diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index ac5eb53fe4..a0ae2fe9c4 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, hasMention: bool) {.signal.} + proc messageNotificationPushed*(self: ChatsView, chatId: string, text: string, messageType: string, chatType: int, timestamp: string, identicon: string, username: string, hasMention: bool, isAddedContact: bool) {.signal.} proc messagesCleared*(self: ChatsView) {.signal.} @@ -347,8 +347,18 @@ QtObject: if self.channelOpenTime.getOrDefault(msg.chatId, high(int64)) < msg.timestamp.parseFloat.fromUnixFloat.toUnix: if msg.chatId != self.activeChannel.id: let channel = self.chats.getChannelById(msg.chatId) + let isAddedContact = channel.chatType.isOneToOne and self.status.contacts.isAdded(channel.id) if not channel.muted: - self.messageNotificationPushed(msg.chatId, escape_html(msg.text), msg.messageType, channel.chatType.int, msg.timestamp, msg.identicon, msg.alias, msg.hasMention) + self.messageNotificationPushed( + msg.chatId, + escape_html(msg.text), + msg.messageType, + channel.chatType.int, + msg.timestamp, + msg.identicon, + msg.alias, + msg.hasMention, + isAddedContact) else: discard self.status.chat.markMessagesSeen(msg.chatId, @[msg.id]) self.newMessagePushed() diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 56ed2a5c8a..282411a9b6 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -140,9 +140,12 @@ ScrollView { chatLogView.scrollToBottom(true) } - onMessageNotificationPushed: function(chatId, msg, messageType, chatType, timestamp, identicon, username, hasMention) { + onMessageNotificationPushed: function(chatId, msg, messageType, chatType, timestamp, identicon, username, hasMention, isAddedContact) { if (appSettings.notificationSetting == Constants.notifyAllMessages || (appSettings.notificationSetting == Constants.notifyJustMentions && hasMention)) { + if (chatType === Constants.chatTypeOneToOne && !appSettings.allowNotificationsFromNonContacts && !isAddedContact) { + return + } 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 371a7eb123..562ad06f03 100644 --- a/ui/app/AppLayouts/Profile/Sections/NotificationsContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/NotificationsContainer.qml @@ -348,6 +348,10 @@ ScrollView { StatusSwitch { Layout.alignment: Qt.AlignRight + checked: appSettings.allowNotificationsFromNonContacts + onCheckedChanged: { + appSettings.allowNotificationsFromNonContacts = checked + } } } diff --git a/ui/main.qml b/ui/main.qml index df2ddd02c9..5ece444463 100644 --- a/ui/main.qml +++ b/ui/main.qml @@ -84,6 +84,7 @@ ApplicationWindow { property int notificationSetting: 0 property bool notificationSoundsEnabled: true property int notificationMessagePreviewSetting: Constants.notificationPreviewNameAndMessage + property bool allowNotificationsFromNonContacts: false property var whitelistedUnfurlingSites: ({}) property bool neverAskAboutUnfurlingAgain: false