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

150 lines
4.0 KiB
QML
Raw Normal View History

// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
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
// [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
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: ""
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)
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)
function clearReplyTo() {
if (! replyToEventId) return
replyToEventId = ""
replyToUserId = ""
replyToDisplayName = ""
}
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},
)
}
Timer {
interval: 300
running: ! ready
onTriggered: longLoading = true
}
Connections {
target: pageLoader
onAboutToRecycle: chat.clearReplyTo()
}
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
2020-09-03 10:49:15 -04:00
readonly property alias appearAnimation: appearAnimation
2019-12-13 09:52:04 -04:00
referenceSizeParent: chat
maximumSize: chat.width - theme.minimumSupportedWidth * 1.5
2020-09-03 10:49:15 -04:00
HNumberAnimation {
id: appearAnimation
target: roomPane.contentTranslation
property: "x"
from: -chat.width + roomPane.width
to: 0
easing.type: Easing.OutCirc
factor: 2
running: true
}
Connections {
target: pageLoader
onRecycled: roomPane.appearAnimation.restart()
}
2019-12-13 09:52:04 -04:00
}
2019-04-21 10:44:04 -04:00
}
2019-03-21 23:28:14 -04:00
}