2020-09-23 19:57:54 -04:00
|
|
|
// 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
|
|
|
|
|
2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-02 16:29:29 -04:00
|
|
|
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-11 13:02:24 -04:00
|
|
|
|
2020-09-13 12:47:25 -04:00
|
|
|
// [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
|
2019-08-16 14:44:45 -04:00
|
|
|
|
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: ""
|
|
|
|
|
2020-09-13 12:47:25 -04:00
|
|
|
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
|
2019-12-09 13:52:02 -04:00
|
|
|
|
2020-06-05 05:42:12 -04:00
|
|
|
readonly property bool composerHasFocus:
|
|
|
|
Boolean(loader.item && loader.item.composer.hasFocus)
|
|
|
|
|
2020-08-24 10:17:04 -04:00
|
|
|
function clearReplyTo() {
|
|
|
|
if (! replyToEventId) return
|
|
|
|
|
|
|
|
replyToEventId = ""
|
|
|
|
replyToUserId = ""
|
|
|
|
replyToDisplayName = ""
|
|
|
|
}
|
|
|
|
|
2019-11-10 09:38:16 -04:00
|
|
|
|
2020-07-12 00:25:57 -04:00
|
|
|
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"
|
2020-08-03 01:26:35 -04:00
|
|
|
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"
|
2020-08-03 01:26:35 -04:00
|
|
|
onActivated: window.makePopup(
|
2020-03-28 12:50:09 -04:00
|
|
|
"Popups/ForgetRoomPopup.qml",
|
|
|
|
{userId, roomId, roomName: roomInfo.display_name},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-11 13:02:24 -04:00
|
|
|
Timer {
|
|
|
|
interval: 300
|
|
|
|
running: ! ready
|
|
|
|
onTriggered: longLoading = true
|
|
|
|
}
|
|
|
|
|
2020-10-01 20:18:39 -04:00
|
|
|
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
|
2020-07-14 03:00:10 -04:00
|
|
|
anchors.rightMargin:
|
2020-07-14 16:01:51 -04:00
|
|
|
! roomPane ?
|
|
|
|
0 :
|
|
|
|
|
|
|
|
ready &&
|
2020-07-14 03:00:10 -04:00
|
|
|
! (
|
|
|
|
roomPane.requireDefaultSize &&
|
2020-07-14 03:56:58 -04:00
|
|
|
roomPane.minimumSize > roomPane.maximumSize &&
|
|
|
|
! roomPane.collapse
|
2020-07-14 03:00:10 -04:00
|
|
|
) ?
|
|
|
|
roomPane.visibleSize :
|
2020-07-14 16:01:51 -04:00
|
|
|
|
|
|
|
roomPane.calculatedSizeNoRequiredMinimum
|
2020-07-14 03:00:10 -04:00
|
|
|
|
2019-12-09 05:25:31 -04:00
|
|
|
anchors.fill: parent
|
2020-07-14 03:56:58 -04:00
|
|
|
visible: ! (ready && roomPane && roomPane.visibleSize >= chat.width)
|
|
|
|
|
2019-12-09 14:13:38 -04:00
|
|
|
onLoaded: if (chat.focus) item.composer.takeFocus()
|
2019-05-08 13:45:25 -04:00
|
|
|
|
2019-12-09 05:25:31 -04:00
|
|
|
source: ready ? "ChatPage.qml" : ""
|
2019-11-10 09:38:16 -04:00
|
|
|
|
2020-07-14 03:56:58 -04:00
|
|
|
Behavior on anchors.rightMargin { HNumberAnimation {} }
|
|
|
|
|
2019-12-09 05:25:31 -04:00
|
|
|
HLoader {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: 96 * theme.uiScale
|
|
|
|
height: width
|
2019-07-21 08:38:49 -04:00
|
|
|
|
2020-03-11 12:53:55 -04:00
|
|
|
source: "../../Base/HBusyIndicator.qml"
|
2020-03-11 13:02:24 -04:00
|
|
|
active: ready ? 0 : longLoading ? 1 : 0
|
2020-03-11 12:53:55 -04:00
|
|
|
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-07-07 05:15:18 -04:00
|
|
|
|
2019-12-13 09:52:04 -04:00
|
|
|
HLoader {
|
|
|
|
id: roomPaneLoader
|
|
|
|
active: ready
|
2019-12-19 19:27:39 -04:00
|
|
|
|
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
|
2019-12-20 07:38:42 -04:00
|
|
|
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
|
|
|
|
}
|
2020-09-03 17:59:48 -04:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: pageLoader
|
2020-09-16 08:21:51 -04:00
|
|
|
onRecycled: roomPane.appearAnimation.restart()
|
2020-09-03 17:59:48 -04:00
|
|
|
}
|
2019-12-13 09:52:04 -04:00
|
|
|
}
|
2019-04-21 10:44:04 -04:00
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|