Fix ForgetRoomPopup destruction/callback

This commit is contained in:
miruka 2019-09-09 20:56:10 -04:00
parent 3e01eeef71
commit 988ab94772
5 changed files with 30 additions and 14 deletions

View File

@ -817,6 +817,9 @@ class MatrixClient(nio.AsyncClient):
if not self.first_sync_done.is_set(): if not self.first_sync_done.is_set():
return return
if room.room_id not in self.models[Room, self.user_id]:
return
self.models[Room, self.user_id][room.room_id].typing_members = sorted( self.models[Room, self.user_id][room.room_id].typing_members = sorted(
room.user_name(user_id) for user_id in ev.users room.user_name(user_id) for user_id in ev.users
if user_id not in self.backend.clients if user_id not in self.backend.clients

View File

@ -24,19 +24,16 @@ Banner {
forget: button => { forget: button => {
Utils.makePopup( Utils.makePopup(
"Popups/ForgetRoomPopup.qml", "Popups/ForgetRoomPopup.qml",
chatPage, mainUI, // Must not be destroyed with chatPage
{ {
userId: chatPage.userId, userId: chatPage.userId,
roomId: chatPage.roomId, roomId: chatPage.roomId,
roomName: chatPage.roomInfo.display_name, roomName: chatPage.roomInfo.display_name,
forgottenCallback: () => {
button.loading = false
Qt.callLater(pageLoader.showPage, "Default")
},
}, },
obj => { obj => {
obj.onOk.connect(() => { button.loading = true }) obj.onOk.connect(() => { button.loading = true })
}, },
false,
) )
} }
}) })

View File

@ -1,6 +1,7 @@
import QtQuick 2.12 import QtQuick 2.12
BoxPopup { BoxPopup {
id: popup
summary.text: qsTr("Leave %1 and discard the history?").arg(roomName) summary.text: qsTr("Leave %1 and discard the history?").arg(roomName)
details.text: qsTr( details.text: qsTr(
"You will not be able to see the messages you received in " + "You will not be able to see the messages you received in " +
@ -12,11 +13,23 @@ BoxPopup {
okText: qsTr("Forget") okText: qsTr("Forget")
box.focusButton: "ok" box.focusButton: "ok"
onOk: py.callClientCoro(userId, "room_forget", [roomId], forgottenCallback) onOk: py.callClientCoro(userId, "room_forget", [roomId], () => {
if (window.uiState.page == "Chat/Chat.qml" &&
window.uiState.pageProperties.userId == userId &&
window.uiState.pageProperties.roomId == roomId)
{
pageLoader.showPage("Default")
Qt.callLater(popup.destroy)
}
})
onCancel: canDestroy = true
onClosed: if (canDestroy) Qt.callLater(popup.destroy)
property string userId: "" property string userId: ""
property string roomId: "" property string roomId: ""
property string roomName: "" property string roomName: ""
property var forgottenCallback: null
property bool canDestroy: false
} }

View File

@ -131,7 +131,9 @@ HTileDelegate {
userId: model.user_id, userId: model.user_id,
roomId: model.data.room_id, roomId: model.data.room_id,
roomName: model.data.display_name, roomName: model.data.display_name,
} },
null,
false,
) )
} }
} }

View File

@ -31,11 +31,12 @@ function makeObject(url, parent=null, properties={}, callback=null) {
} }
function makePopup(url, parent=null, properties={}, callback=null) { function makePopup(url, parent=null, properties={}, callback=null,
autoDestruct=true) {
makeObject(url, parent, properties, (popup) => { makeObject(url, parent, properties, (popup) => {
popup.open() popup.open()
popup.closed.connect(() => { popup.destroy() }) if (autoDestruct) popup.closed.connect(() => { popup.destroy() })
if (callback) callback(popup) if (callback) callback(popup)
}) })
} }