feat: add OS notification and setting to switch back

This commit is contained in:
Jonathan Rainville 2020-12-07 12:37:39 -05:00 committed by Iuri Matias
parent 239b95e9a2
commit 08a7baed8f
5 changed files with 93 additions and 36 deletions

View File

@ -1,4 +1,5 @@
import QtQuick 2.13 import QtQuick 2.13
import Qt.labs.platform 1.1
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Window 2.13 import QtQuick.Window 2.13
import QtQuick.Layouts 1.13 import QtQuick.Layouts 1.13
@ -29,6 +30,8 @@ ScrollView {
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ListView { ListView {
property string currentNotificationChatId
id: chatLogView id: chatLogView
anchors.fill: parent anchors.fill: parent
anchors.bottomMargin: Style.current.bigPadding anchors.bottomMargin: Style.current.bigPadding
@ -118,6 +121,12 @@ ScrollView {
return true return true
} }
function clickOnNotification(chatId) {
applicationWindow.raise()
chatsModel.setActiveChannel(chatId)
appMain.changeAppSection(Constants.chat)
applicationWindow.requestActivate()
}
Connections { Connections {
@ -154,8 +163,44 @@ ScrollView {
if (chatType === Constants.chatTypeOneToOne && !appSettings.allowNotificationsFromNonContacts && !isAddedContact) { if (chatType === Constants.chatTypeOneToOne && !appSettings.allowNotificationsFromNonContacts && !isAddedContact) {
return return
} }
notificationWindow.notifyUser(chatId, msg, messageType, chatType, timestamp, identicon, username, channelName) chatLogView.currentNotificationChatId = chatId
let name;
if (appSettings.notificationMessagePreviewSetting === Constants.notificationPreviewAnonymous) {
name = "Status"
} else if (chatType === Constants.chatTypePublic) {
name = chatId
} else {
name = chatType === Constants.chatTypePrivateGroupChat ? Utils.filterXSS(channelName) : Utils.removeStatusEns(username)
} }
let message;
if (appSettings.notificationMessagePreviewSetting > Constants.notificationPreviewNameOnly) {
switch(messageType){
case Constants.imageType: message = qsTr("Image"); break
case Constants.stickerType: message = qsTr("Sticker"); break
default: message = Emoji.parse(msg, "26x26").replace(/\n|\r/g, ' ')
}
} else {
message = qsTr("You have a new message")
}
if (appSettings.useOSNotifications && systemTray.supportsMessages) {
systemTray.showMessage(name,
message,
SystemTrayIcon.NoIcon,
Constants.notificationPopupTTL)
} else {
notificationWindow.notifyUser(chatId, name, message, chatType, identicon, chatLogView.clickOnNotification)
}
}
}
}
Connections {
target: systemTray
onMessageClicked: {
chatLogView.clickOnNotification(chatLogView.currentNotificationChatId)
} }
} }

View File

@ -160,6 +160,34 @@ ScrollView {
} }
} }
RowLayout {
width: parent.width
StyledText {
text: qsTr("Use your operating system's notifications")
font.pixelSize: 15
wrapMode: Text.WordWrap
Layout.fillWidth: true
StyledText {
id: detailText
text: qsTr("Setting this to false will instead use Status' notification style as seen below")
color: Style.current.secondaryText
width: parent.width
font.pixelSize: 12
wrapMode: Text.WordWrap
anchors.top: parent.bottom
}
}
StatusSwitch {
Layout.alignment: Qt.AlignRight
checked: appSettings.useOSNotifications
onCheckedChanged: {
appSettings.useOSNotifications = checked
}
}
}
/* GridLayout { */ /* GridLayout { */
/* columns: 4 */ /* columns: 4 */
/* width: parent.width */ /* width: parent.width */

View File

@ -15,6 +15,8 @@ QtObject {
readonly property int limitLongChatText: 500 readonly property int limitLongChatText: 500
readonly property int limitLongChatTextCompactMode: 1000 readonly property int limitLongChatTextCompactMode: 1000
readonly property int notificationPopupTTL: 5000
readonly property string chat: "chat" readonly property string chat: "chat"
readonly property string wallet: "wallet" readonly property string wallet: "wallet"
readonly property string browser: "browser" readonly property string browser: "browser"

View File

@ -102,6 +102,7 @@ ApplicationWindow {
property real volume: 0.2 property real volume: 0.2
property int notificationSetting: Constants.notifyAllMessages property int notificationSetting: Constants.notifyAllMessages
property bool notificationSoundsEnabled: true property bool notificationSoundsEnabled: true
property bool useOSNotifications: true
property int notificationMessagePreviewSetting: Constants.notificationPreviewNameAndMessage property int notificationMessagePreviewSetting: Constants.notificationPreviewNameAndMessage
property bool allowNotificationsFromNonContacts: false property bool allowNotificationsFromNonContacts: false
property var whitelistedUnfurlingSites: ({}) property var whitelistedUnfurlingSites: ({})
@ -139,6 +140,7 @@ ApplicationWindow {
property real volume: defaultAppSettings.volume property real volume: defaultAppSettings.volume
property int notificationSetting: defaultAppSettings.notificationSetting property int notificationSetting: defaultAppSettings.notificationSetting
property bool notificationSoundsEnabled: defaultAppSettings.notificationSoundsEnabled property bool notificationSoundsEnabled: defaultAppSettings.notificationSoundsEnabled
property bool useOSNotifications: defaultAppSettings.useOSNotifications
property int notificationMessagePreviewSetting: defaultAppSettings.notificationMessagePreviewSetting property int notificationMessagePreviewSetting: defaultAppSettings.notificationMessagePreviewSetting
property bool allowNotificationsFromNonContacts: defaultAppSettings.allowNotificationsFromNonContacts property bool allowNotificationsFromNonContacts: defaultAppSettings.allowNotificationsFromNonContacts
property var whitelistedUnfurlingSites: defaultAppSettings.whitelistedUnfurlingSites property var whitelistedUnfurlingSites: defaultAppSettings.whitelistedUnfurlingSites
@ -178,6 +180,7 @@ ApplicationWindow {
} }
SystemTrayIcon { SystemTrayIcon {
id: systemTray
visible: true visible: true
icon.source: "shared/img/status-logo.png" icon.source: "shared/img/status-logo.png"
menu: Menu { menu: Menu {

View File

@ -11,13 +11,11 @@ import "../app/AppLayouts/Chat/ContactsColumn"
Item { Item {
id: root id: root
property string chatId: "" property string chatId: ""
property string name: "channel name"
property string message: "Everything is connected" property string message: "Everything is connected"
property int messageType: 1
property int chatType: 1 property int chatType: 1
property string timestamp: "20/2/2020" property var onClick
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQAQMAAAC6caSPAAAABlBMVEXMzMz////TjRV2AAAAAWJLR0QB/wIt3gAAACpJREFUGBntwYEAAAAAw6D7Uw/gCtUAAAAAAAAAAAAAAAAAAAAAAAAAgBNPsAABAjKCqQAAAABJRU5ErkJggg==" property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQAQMAAAC6caSPAAAABlBMVEXMzMz////TjRV2AAAAAWJLR0QB/wIt3gAAACpJREFUGBntwYEAAAAAw6D7Uw/gCtUAAAAAAAAAAAAAAAAAAAAAAAAAgBNPsAABAjKCqQAAAABJRU5ErkJggg=="
property string username: "@jonas"
property string channelName: "sic-mundus"
property var processClick: Backpressure.oneInTime(root, 1000, function () { property var processClick: Backpressure.oneInTime(root, 1000, function () {
notificationSound.play() notificationSound.play()
@ -55,25 +53,8 @@ Item {
StatusNotification { StatusNotification {
id: channelNotif id: channelNotif
chatId: root.chatId chatId: root.chatId
name: { name: root.name
if (appSettings.notificationMessagePreviewSetting === Constants.notificationPreviewAnonymous) { message: root.message
return "Status"
}
if (root.chatType === Constants.chatTypePublic) {
return root.chatId
}
return root.chatType === Constants.chatTypePrivateGroupChat ? Utils.filterXSS(root.channelName) : Utils.removeStatusEns(root.username)
}
message: {
if (appSettings.notificationMessagePreviewSetting > Constants.notificationPreviewNameOnly) {
switch(root.messageType){
case Constants.imageType: return qsTr("Image");
case Constants.stickerType: return qsTr("Sticker");
default: return Emoji.parse(root.message, "26x26").replace(/\n|\r/g, ' ')
}
}
return qsTr("You have a new message")
}
chatType: root.chatType chatType: root.chatType
identicon: root.identicon identicon: root.identicon
@ -83,19 +64,19 @@ Item {
onClicked: { onClicked: {
timer.stop() timer.stop()
notificationWindowSub.close() notificationWindowSub.close()
applicationWindow.raise() root.onClick(root.chatId)
chatsModel.setActiveChannel(chatId) notificationWindowSub.destroy()
applicationWindow.requestActivate()
} }
} }
Timer { Timer {
id: timer id: timer
interval: 4000 interval: Constants.notificationPopupTTL
running: false running: true
repeat: false repeat: false
onTriggered: { onTriggered: {
notificationWindowSub.close() notificationWindowSub.close()
notificationWindowSub.destroy()
} }
} }
onVisibleChanged: { onVisibleChanged: {
@ -113,15 +94,13 @@ Item {
} }
} }
function notifyUser(chatId, msg, messageType, chatType, timestamp, identicon, username, channelName) { function notifyUser(chatId, name, msg, chatType, identicon, onClick) {
this.chatId = chatId this.chatId = chatId
this.name = name
this.message = msg this.message = msg
this.messageType = parseInt(messageType, 10)
this.chatType = chatType this.chatType = chatType
this.timestamp = timestamp
this.identicon = identicon this.identicon = identicon
this.username = username this.onClick = onClick
this.channelName = channelName
processClick() processClick()
} }
} }