Confirmation popup to clear messages
This commit is contained in:
parent
f40e853078
commit
2611e86517
|
@ -2,10 +2,16 @@ import QtQuick 2.12
|
|||
import QtQuick.Layouts 1.12
|
||||
|
||||
HPopup {
|
||||
id: popup
|
||||
onAboutToShow: okClicked = false
|
||||
|
||||
|
||||
signal ok()
|
||||
signal cancel()
|
||||
|
||||
|
||||
property alias label: label
|
||||
property alias text: label.text
|
||||
property bool okClicked: false
|
||||
|
||||
|
||||
|
@ -15,8 +21,8 @@ HPopup {
|
|||
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
|
||||
]
|
||||
box.buttonCallbacks: ({
|
||||
ok: button => { okClicked = true; popup.close() },
|
||||
cancel: button => { okClicked = false; popup.close() },
|
||||
ok: button => { okClicked = true; popup.ok(); popup.close() },
|
||||
cancel: button => { okClicked = false; popup.cancel(); popup.close() },
|
||||
})
|
||||
|
||||
|
||||
|
|
16
src/qml/Chat/ClearMessagesPopup.qml
Normal file
16
src/qml/Chat/ClearMessagesPopup.qml
Normal file
|
@ -0,0 +1,16 @@
|
|||
import QtQuick 2.12
|
||||
import "../Base"
|
||||
|
||||
HOkCancelPopup {
|
||||
text: qsTr(
|
||||
"Clear this room's messages?\n" +
|
||||
"The messages will only be removed on your side. " +
|
||||
"They will be available again after you restart the application."
|
||||
)
|
||||
|
||||
onOk: py.callClientCoro(userId, "clear_events", [roomId])
|
||||
|
||||
|
||||
property string userId: ""
|
||||
property string roomId: ""
|
||||
}
|
|
@ -127,8 +127,10 @@ Column {
|
|||
HMenuItem {
|
||||
icon.name: "clear-messages"
|
||||
text: qsTr("Clear messages")
|
||||
onTriggered: py.callClientCoro(
|
||||
chatPage.userId, "clear_events", [chatPage.roomId],
|
||||
onTriggered: Utils.makePopup(
|
||||
"Chat/ClearMessagesPopup.qml",
|
||||
chatPage,
|
||||
{userId: chatPage.userId, roomId: chatPage.roomId},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -116,10 +116,13 @@ HShortcutHandler {
|
|||
HShortcut {
|
||||
enabled: window.uiState.page == "Chat/Chat.qml"
|
||||
sequences: settings.keys.clearRoomMessages
|
||||
onPressed: py.callClientCoro(
|
||||
window.uiState.pageProperties.userId,
|
||||
"clear_events",
|
||||
[window.uiState.pageProperties.roomId],
|
||||
onPressed: Utils.makePopup(
|
||||
"Chat/ClearMessagesPopup.qml",
|
||||
mainUI,
|
||||
{
|
||||
userId: window.uiState.pageProperties.userId,
|
||||
roomId: window.uiState.pageProperties.roomId,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,45 @@
|
|||
function makeObject(url, parent=null, properties={}, callback=null) {
|
||||
let comp = Qt.createComponent(url, Component.Asynchronous)
|
||||
let ready = false
|
||||
|
||||
comp.statusChanged.connect(status => {
|
||||
if ([Component.Null, Component.Error].includes(status)) {
|
||||
console.error("Failed creating component: ", comp.errorString())
|
||||
|
||||
} else if (status == Component.Ready) {
|
||||
let incu = comp.incubateObject(parent, properties, Qt.Asynchronous)
|
||||
|
||||
if (incu.status == Component.Ready) {
|
||||
if (callback) callback(incu.object)
|
||||
return
|
||||
}
|
||||
|
||||
incu.onStatusChanged = (istatus) => {
|
||||
if (incu.status == Component.Error) {
|
||||
console.error("Failed incubating object: ",
|
||||
incu.errorString())
|
||||
|
||||
} else if (istatus == Component.Ready && callback && ! ready) {
|
||||
if (callback) callback(incu.object)
|
||||
ready = true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (comp.status == Component.Ready) comp.statusChanged(comp.status)
|
||||
}
|
||||
|
||||
|
||||
function makePopup(url, parent=null, properties={}, callback=null) {
|
||||
makeObject(url, parent, properties, (popup) => {
|
||||
popup.open()
|
||||
popup.closed.connect(() => { popup.destroy() })
|
||||
if (callback) callback(popup)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function isEmptyObject(obj) {
|
||||
return Object.entries(obj).length === 0 && obj.constructor === Object
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user