add notifications support
first attempt attempt 2 working notifications add notification sound cleanup remove unneeded imports remove unneded imports
This commit is contained in:
parent
19f358ef9c
commit
7d7bac5fb6
|
@ -125,7 +125,7 @@ QtObject:
|
|||
read = getStickerList
|
||||
notify = activeStickerPackChanged
|
||||
|
||||
proc setActiveChannel*(self: ChatsView, channel: string) =
|
||||
proc setActiveChannel*(self: ChatsView, channel: string) {.slot.} =
|
||||
if(channel == ""): return
|
||||
self.activeChannel.setChatItem(self.chats.getChannel(self.chats.chats.findIndexById(channel)))
|
||||
self.activeChannelChanged()
|
||||
|
@ -148,6 +148,8 @@ QtObject:
|
|||
|
||||
proc messagePushed*(self: ChatsView) {.signal.}
|
||||
|
||||
proc messageNotificationPushed*(self: ChatsView, chatId: string, text: string) {.signal.}
|
||||
|
||||
proc messagesCleared*(self: ChatsView) {.signal.}
|
||||
|
||||
proc clearMessages*(self: ChatsView, id: string) =
|
||||
|
@ -160,6 +162,8 @@ QtObject:
|
|||
msg.alias = self.status.chat.getUserName(msg.fromAuthor, msg.alias)
|
||||
self.messageList[msg.chatId].add(msg)
|
||||
self.messagePushed()
|
||||
if msg.chatId != self.activeChannel.id:
|
||||
self.messageNotificationPushed(msg.chatId, msg.text)
|
||||
|
||||
proc updateUsernames*(self:ChatsView, contacts: seq[Profile]) =
|
||||
if contacts.len > 0:
|
||||
|
|
|
@ -43,8 +43,6 @@ Rectangle {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ScrollView {
|
||||
id: scrollView
|
||||
anchors.bottom: parent.bottom
|
||||
|
@ -87,6 +85,6 @@ Rectangle {
|
|||
}
|
||||
/*##^##
|
||||
Designer {
|
||||
D{i:0;formeditorColor:"#ffffff";formeditorZoom:1.25}
|
||||
D{i:0;formeditorColor:"#ffffff"}
|
||||
}
|
||||
##^##*/
|
||||
|
|
|
@ -48,6 +48,10 @@ ScrollView {
|
|||
if(chatLogView.atYEnd)
|
||||
Qt.callLater( chatLogView.positionViewAtEnd )
|
||||
}
|
||||
|
||||
onMessageNotificationPushed: function(chatId, msg) {
|
||||
notificationWindow.notifyUser(chatId, msg)
|
||||
}
|
||||
}
|
||||
|
||||
onContentYChanged: {
|
||||
|
|
12
ui/main.qml
12
ui/main.qml
|
@ -5,12 +5,14 @@ import Qt.labs.platform 1.1
|
|||
import QtQml.StateMachine 1.14 as DSM
|
||||
import QtMultimedia 5.13
|
||||
import Qt.labs.settings 1.0
|
||||
import QtQuick.Window 2.12
|
||||
import QtQml 2.13
|
||||
import QtQuick.Window 2.0
|
||||
|
||||
import "./onboarding"
|
||||
import "./app"
|
||||
import "./sounds"
|
||||
import "./shared"
|
||||
import "./imports"
|
||||
|
||||
ApplicationWindow {
|
||||
|
@ -48,6 +50,12 @@ ApplicationWindow {
|
|||
source: "../../../../sounds/send_message.wav"
|
||||
}
|
||||
|
||||
Audio {
|
||||
id: notificationSound
|
||||
audioRole: Audio.NotificationRole
|
||||
source: "../../../../sounds/notification.wav"
|
||||
}
|
||||
|
||||
Settings {
|
||||
id: settings
|
||||
property var chatSplitView
|
||||
|
@ -235,6 +243,10 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationWindow {
|
||||
id: notificationWindow
|
||||
}
|
||||
}
|
||||
|
||||
/*##^##
|
||||
|
|
|
@ -219,6 +219,7 @@ DISTFILES += \
|
|||
shared/AddButton.qml \
|
||||
shared/Input.qml \
|
||||
shared/ModalPopup.qml \
|
||||
shared/NotificationWindow.qml \
|
||||
shared/PopupMenu.qml \
|
||||
shared/Identicon.qml \
|
||||
shared/CopyToClipBoardButton.qml \
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
import QtQuick 2.13
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Window 2.12
|
||||
import QtQml 2.13
|
||||
|
||||
import "../imports"
|
||||
|
||||
Item {
|
||||
id: root
|
||||
property var chatId: ""
|
||||
property var message: "hello"
|
||||
|
||||
Component {
|
||||
id: winInit
|
||||
Window {
|
||||
flags: Qt.WindowStaysOnTopHint | Qt.WindowStaysOnTopHint | Qt.Popup | Qt.WA_ShowWithoutActivating | Qt.WindowStaysOnTopHint | Qt.BypassWindowManagerHint | Qt.WindowStaysOnTopHint
|
||||
width: 1
|
||||
height: 1
|
||||
Component.onCompleted: {
|
||||
requestActivate()
|
||||
mainWin.createObject(root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: mainWin
|
||||
|
||||
Window {
|
||||
id: notificationWindowSub
|
||||
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WA_ShowWithoutActivating | Qt.BypassWindowManagerHint | Qt.WindowStaysOnTopHint | Qt.BypassWindowManagerHint
|
||||
x: Screen.width - 250
|
||||
y: 50
|
||||
width: 200
|
||||
height: 100
|
||||
visible: true
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "white"
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: message
|
||||
MouseArea {
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
timer.stop()
|
||||
notificationWindowSub.close()
|
||||
applicationWindow.raise()
|
||||
chatsModel.setActiveChannel(chatId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 4000;
|
||||
running: false;
|
||||
repeat: false
|
||||
onTriggered: notificationWindowSub.close()
|
||||
}
|
||||
onVisibleChanged: {
|
||||
if(visible) {
|
||||
timer.running = true;
|
||||
if (applicationWindow.active) {
|
||||
this.flags |= Qt.Popup
|
||||
} else {
|
||||
this.flags = Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WA_ShowWithoutActivating | Qt.BypassWindowManagerHint | Qt.WindowStaysOnTopHint | Qt.BypassWindowManagerHint
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function notifyUser(chatId, msg) {
|
||||
this.chatId = chatId
|
||||
this.message = msg
|
||||
notificationSound.play()
|
||||
var w1 = winInit.createObject(null)
|
||||
w1.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
/*##^##
|
||||
Designer {
|
||||
D{i:0;autoSize:true;height:480;width:640}
|
||||
}
|
||||
##^##*/
|
|
@ -16,3 +16,4 @@ Identicon 1.0 Identicon.qml
|
|||
RoundedImage 1.0 RoundedImage.qml
|
||||
SplitViewHandle 1.0 SplitViewHandle.qml
|
||||
CopyToClipBoardButton 1.0 CopyToClipBoardButton.qml
|
||||
NotificationWindow 1.0 NotificationWindow.qml
|
||||
|
|
Loading…
Reference in New Issue