diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 837ceb06f8..067f9b36e2 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -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: diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml index 2e27ae6a42..305e61d281 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml @@ -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"} } ##^##*/ diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 7e34fe57a9..2803aea7de 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -48,6 +48,10 @@ ScrollView { if(chatLogView.atYEnd) Qt.callLater( chatLogView.positionViewAtEnd ) } + + onMessageNotificationPushed: function(chatId, msg) { + notificationWindow.notifyUser(chatId, msg) + } } onContentYChanged: { diff --git a/ui/main.qml b/ui/main.qml index e2c632f433..6bbe5e5817 100644 --- a/ui/main.qml +++ b/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 + } } /*##^## diff --git a/ui/nim-status-client.pro b/ui/nim-status-client.pro index 4b72c8fa5b..cbe7ba646c 100644 --- a/ui/nim-status-client.pro +++ b/ui/nim-status-client.pro @@ -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 \ diff --git a/ui/shared/NotificationWindow.qml b/ui/shared/NotificationWindow.qml new file mode 100644 index 0000000000..fc4689af2b --- /dev/null +++ b/ui/shared/NotificationWindow.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} +} +##^##*/ diff --git a/ui/shared/qmldir b/ui/shared/qmldir index 917b9f8260..e0937bb302 100644 --- a/ui/shared/qmldir +++ b/ui/shared/qmldir @@ -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