feat(Notifications): allow users to turn of notifications for non-contacts

Partially fixes #1280
This commit is contained in:
Pascal Precht 2020-11-18 13:50:38 +01:00 committed by Pascal Precht
parent f8c5002ff8
commit db0b765d74
4 changed files with 21 additions and 3 deletions

View File

@ -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()

View File

@ -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)
}
}

View File

@ -348,6 +348,10 @@ ScrollView {
StatusSwitch {
Layout.alignment: Qt.AlignRight
checked: appSettings.allowNotificationsFromNonContacts
onCheckedChanged: {
appSettings.allowNotificationsFromNonContacts = checked
}
}
}

View File

@ -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