Faster switching of rooms from different accounts

Use a single [userId, roomId] property for the chat page.
This gets read of the intermediate state where the userId property has
been updated but the roomId one not yet, which led to the page unloading
and reloading itself until both were properly set.

Side-effect: when starting Mirage after this commit for the first time,
the last saved page will not load and user must click a room or
other page manually.
This commit is contained in:
miruka 2020-09-13 12:47:25 -04:00
parent 32679aa7f8
commit 6df9647b59
8 changed files with 37 additions and 21 deletions

View File

@ -19,10 +19,10 @@ HListView {
window.uiState.page === "Pages/Chat/Chat.qml"
readonly property string wantedUserId:
window.uiState.pageProperties.userId || ""
(window.uiState.pageProperties.userRoomId || [])[0] || ""
readonly property string wantedRoomId:
window.uiState.pageProperties.roomId || ""
(window.uiState.pageProperties.userRoomId || [])[1] || ""
readonly property var accountIndice: {
const accounts = {}

View File

@ -45,7 +45,7 @@ HLoader {
}
function showRoom(userId, roomId) {
show("Pages/Chat/Chat.qml", {userId, roomId})
show("Pages/Chat/Chat.qml", {userRoomId: [userId, roomId]})
}
function showPrevious(timesBack=1) {

View File

@ -9,19 +9,28 @@ import "RoomPane"
Item {
id: chat
property string userId
property string roomId
property QtObject userInfo: ModelStore.get("accounts").find(userId)
property QtObject roomInfo: ModelStore.get(userId, "rooms").find(roomId)
property bool ready: Boolean(userInfo && roomInfo)
property bool longLoading: false
// [userId, roomId] - Set this instead of changing the userId and roomId
// properties one by one, else QML has time to be in an invalid state
// between the two changes.
property var userRoomId
property string replyToEventId: ""
property string replyToUserId: ""
property string replyToDisplayName: ""
property bool longLoading: false
readonly property string userId: userRoomId[0]
readonly property string roomId: userRoomId[1]
readonly property QtObject userInfo:
ModelStore.get("accounts").find(userRoomId[0])
readonly property QtObject roomInfo:
ModelStore.get(userRoomId[0], "rooms").find(userRoomId[1])
readonly property bool ready: Boolean(userInfo && roomInfo)
readonly property alias loader: loader
readonly property alias roomPane: roomPaneLoader.item

View File

@ -8,7 +8,7 @@ import "../../../../Base"
HColumnLayout {
readonly property alias keybindFocusItem: filterField
readonly property var modelSyncId:
[chat.userId, chat.roomId, "filtered_members"]
[chat.userRoomId[0], chat.userRoomId[1], "filtered_members"]
readonly property alias viewDepth: stackView.depth
readonly property alias filterField: filterField

View File

@ -201,8 +201,8 @@ Rectangle {
onActivated: window.makePopup(
"Popups/ClearMessagesPopup.qml",
{
userId: window.uiState.pageProperties.userId,
roomId: window.uiState.pageProperties.roomId,
userId: window.uiState.pageProperties.userRoomId[0],
roomId: window.uiState.pageProperties.userRoomId[1],
preClearCallback: eventList.uncheckAll,
}
)
@ -506,7 +506,7 @@ Rectangle {
// reloaded from network.
cacheBuffer: Screen.desktopAvailableHeight * 2
model: ModelStore.get(chat.userId, chat.roomId, "events")
model: ModelStore.get(chat.userRoomId[0], chat.userRoomId[1], "events")
delegate: EventDelegate {}
highlight: Rectangle {

View File

@ -16,8 +16,8 @@ HFlickableColumnPopup {
function forget() {
py.callClientCoro(userId, "room_forget", [roomId], () => {
if (window.uiState.page === "Pages/Chat/Chat.qml" &&
window.uiState.pageProperties.userId === userId &&
window.uiState.pageProperties.roomId === roomId)
window.uiState.pageProperties.userRoomId[0] === userId &&
window.uiState.pageProperties.userRoomId[1] === roomId)
{
window.mainUI.pageLoader.showPrevious() ||
window.mainUI.pageLoader.show("Pages/Default.qml")

View File

@ -31,7 +31,10 @@ HFlickableColumnPopup {
}
}
onClosed: if (window.uiState.pageProperties.userId === userId) addAccount()
onClosed: if (
window.uiState.pageProperties.userId === userId ||
(window.uiState.pageProperties.userRoomId || [])[0] === userId
) addAccount()
SummaryLabel {
text: qsTr("Signed out from %1").arg(coloredNameHtml("", userId))

View File

@ -35,9 +35,13 @@ HFlickableColumnPopup {
icon.name: "sign-out"
onClicked: {
if (ModelStore.get("accounts").count < 2 ||
window.uiState.pageProperties.userId === userId)
{
const showAdd =
ModelStore.get("accounts").count < 2 ||
window.uiState.pageProperties.userId === userId ||
(window.uiState.pageProperties.userRoomId || [])[0] ===
userId
if (showAdd) {
const page = "Pages/AddAccount/AddAccount.qml"
window.mainUI.pageLoader.show(page)
}