moment/src/gui/Pages/Chat/Chat.qml

124 lines
3.1 KiB
QML
Raw Normal View History

2019-12-19 07:46:16 -04:00
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../.."
2019-12-18 04:53:08 -04:00
import "../../Base"
2019-12-10 14:57:54 -04:00
import "RoomPane"
2019-03-21 23:28:14 -04:00
2019-12-09 05:25:31 -04:00
Item {
id: chat
2020-03-08 04:02:26 -04:00
property string userId
property string roomId
2019-07-16 17:08:06 -04:00
2020-03-08 04:02:26 -04:00
property QtObject userInfo: null
property QtObject roomInfo: null
property bool ready: Boolean(userInfo && roomInfo)
property bool longLoading: false
2020-05-20 06:17:14 -04:00
property string replyToEventId: ""
2020-05-20 05:19:06 -04:00
property string replyToUserId: ""
property string replyToDisplayName: ""
2019-12-09 14:22:39 -04:00
readonly property alias loader: loader
2019-12-13 09:52:04 -04:00
readonly property alias roomPane: roomPaneLoader.item
readonly property bool composerHasFocus:
Boolean(loader.item && loader.item.composer.hasFocus)
onFocusChanged: if (focus && loader.item) loader.item.composer.takeFocus()
onReadyChanged: longLoading = false
2020-03-28 12:50:09 -04:00
HShortcut {
sequences: window.settings.keys.leaveRoom
2020-07-11 00:43:31 -04:00
active: userInfo && userInfo.presence !== "offline"
onActivated: window.makePopup(
2020-03-28 12:50:09 -04:00
"Popups/LeaveRoomPopup.qml",
{userId, roomId, roomName: roomInfo.display_name},
)
}
HShortcut {
sequences: window.settings.keys.forgetRoom
2020-07-11 00:43:31 -04:00
active: userInfo && userInfo.presence !== "offline"
onActivated: window.makePopup(
2020-03-28 12:50:09 -04:00
"Popups/ForgetRoomPopup.qml",
{userId, roomId, roomName: roomInfo.display_name},
)
}
2020-03-08 04:02:26 -04:00
Timer {
interval: 100
running: ! userInfo
repeat: true
triggeredOnStart: true
onTriggered: userInfo = ModelStore.get("accounts").find(userId)
}
Timer {
interval: 100
running: ! roomInfo
repeat: true
triggeredOnStart: true
onTriggered: roomInfo = ModelStore.get(userId, "rooms").find(roomId)
}
Timer {
interval: 300
running: ! ready
onTriggered: longLoading = true
}
2019-12-09 05:25:31 -04:00
HLoader {
2019-12-09 14:13:38 -04:00
id: loader
anchors.rightMargin:
! roomPane ?
0 :
ready &&
! (
roomPane.requireDefaultSize &&
roomPane.minimumSize > roomPane.maximumSize &&
! roomPane.collapse
) ?
roomPane.visibleSize :
roomPane.calculatedSizeNoRequiredMinimum
2019-12-09 05:25:31 -04:00
anchors.fill: parent
visible: ! (ready && roomPane && roomPane.visibleSize >= chat.width)
2019-12-09 14:13:38 -04:00
onLoaded: if (chat.focus) item.composer.takeFocus()
2019-12-09 05:25:31 -04:00
source: ready ? "ChatPage.qml" : ""
Behavior on anchors.rightMargin { HNumberAnimation {} }
2019-12-09 05:25:31 -04:00
HLoader {
anchors.centerIn: parent
width: 96 * theme.uiScale
height: width
source: "../../Base/HBusyIndicator.qml"
active: ready ? 0 : longLoading ? 1 : 0
opacity: active ? 1 : 0
2019-04-21 10:44:04 -04:00
2019-12-16 04:42:41 -04:00
Behavior on opacity { HNumberAnimation { factor: 2 } }
2019-12-09 05:25:31 -04:00
}
}
2019-12-13 09:52:04 -04:00
HLoader {
id: roomPaneLoader
active: ready
2019-12-13 09:52:04 -04:00
sourceComponent: RoomPane {
id: roomPane
referenceSizeParent: chat
maximumSize: chat.width - theme.minimumSupportedWidth * 1.5
2019-12-13 09:52:04 -04:00
}
2019-04-21 10:44:04 -04:00
}
2019-03-21 23:28:14 -04:00
}