feat: allow users to configure notification settings

Can choose between all, just mentions, or nothing
This commit is contained in:
Pascal Precht 2020-10-15 13:53:27 +02:00 committed by Iuri Matias
parent ebda8b19a9
commit 3d0f50a5b3
7 changed files with 28 additions and 8 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) {.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()

View File

@ -59,6 +59,7 @@ type Message* = object
image*: string
audio*: string
audioDurationMs*: int
hasMention*: bool
type Reaction* = object
id*: string

View File

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

View File

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

View File

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

View File

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

View File

@ -76,6 +76,7 @@ ApplicationWindow {
property string locale: "en"
property var recentEmojis: []
property real volume: 0.2
property int notificationSetting: 0
}
Connections {
target: profileModel