2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 07:06:37 +10:00
|
|
|
import QtQuick 2.12
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-28 00:06:42 +11:00
|
|
|
import Clipboard 0.1
|
2019-12-03 07:29:29 +11:00
|
|
|
import ".."
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../Base"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-08-21 18:39:07 +10:00
|
|
|
HTileDelegate {
|
2019-12-11 06:17:41 +11:00
|
|
|
backgroundColor: theme.mainPane.room.background
|
2019-12-03 07:29:29 +11:00
|
|
|
opacity: model.left ? theme.mainPane.room.leftRoomOpacity : 1
|
2019-08-20 00:28:49 +10:00
|
|
|
|
2020-03-13 13:16:33 +11:00
|
|
|
topPadding: theme.spacing / (model.index === 0 ? 1 : 1.5)
|
|
|
|
bottomPadding: theme.spacing / (model.index === view.count - 1 ? 1 : 1.5)
|
|
|
|
leftPadding: theme.spacing * 2
|
|
|
|
rightPadding: theme.spacing
|
|
|
|
|
2019-08-21 18:39:07 +10:00
|
|
|
image: HRoomAvatar {
|
2020-03-10 02:46:08 +11:00
|
|
|
roomId: model.id
|
2019-12-03 07:29:29 +11:00
|
|
|
displayName: model.display_name
|
|
|
|
mxc: model.avatar_url
|
2019-08-21 18:39:07 +10:00
|
|
|
}
|
2019-08-20 03:09:05 +10:00
|
|
|
|
2019-12-11 06:17:41 +11:00
|
|
|
title.color: theme.mainPane.room.name
|
2019-12-03 07:29:29 +11:00
|
|
|
title.text: model.display_name || qsTr("Empty room")
|
2019-08-20 03:09:05 +10:00
|
|
|
|
2019-08-21 18:39:07 +10:00
|
|
|
additionalInfo.children: HIcon {
|
|
|
|
svgName: "invite-received"
|
2019-08-29 08:21:13 +10:00
|
|
|
colorize: theme.colors.alertBackground
|
2019-08-20 03:09:05 +10:00
|
|
|
|
2019-08-22 04:58:57 +10:00
|
|
|
Layout.maximumWidth: invited ? implicitWidth : 0
|
2019-08-21 18:39:07 +10:00
|
|
|
|
|
|
|
Behavior on Layout.maximumWidth { HNumberAnimation {} }
|
2019-08-18 17:27:00 +10:00
|
|
|
}
|
2019-08-18 10:29:56 +10:00
|
|
|
|
2019-12-11 06:17:41 +11:00
|
|
|
subtitle.color: theme.mainPane.room.subtitle
|
2019-08-21 18:39:07 +10:00
|
|
|
subtitle.textFormat: Text.StyledText
|
2019-12-03 07:29:29 +11:00
|
|
|
subtitle.font.italic:
|
|
|
|
lastEvent && lastEvent.event_type === "RoomMessageEmote"
|
2019-08-21 18:39:07 +10:00
|
|
|
subtitle.text: {
|
2019-11-30 23:14:39 +11:00
|
|
|
if (! lastEvent) return ""
|
2019-08-12 12:57:36 +10:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
const isEmote = lastEvent.event_type === "RoomMessageEmote"
|
|
|
|
const isMsg = lastEvent.event_type.startsWith("RoomMessage")
|
|
|
|
const isUnknownMsg = lastEvent.event_type === "RoomMessageUnknown"
|
|
|
|
const isCryptMedia = lastEvent.event_type.startsWith("RoomEncrypted")
|
2019-12-05 09:27:56 +11:00
|
|
|
|
|
|
|
// If it's a general event
|
2019-12-03 07:29:29 +11:00
|
|
|
if (isEmote || isUnknownMsg || (! isMsg && ! isCryptMedia))
|
2019-12-18 08:59:53 +11:00
|
|
|
return utils.processedEventText(lastEvent)
|
2019-05-03 04:20:21 +10:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
const text = utils.coloredNameHtml(
|
2019-11-30 23:14:39 +11:00
|
|
|
lastEvent.sender_name, lastEvent.sender_id
|
|
|
|
) + ": " + lastEvent.inline_content
|
2019-08-31 02:07:50 +10:00
|
|
|
|
|
|
|
return text.replace(
|
2019-10-25 00:43:40 +11:00
|
|
|
/< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g,
|
2019-12-11 06:17:41 +11:00
|
|
|
`<font color="${theme.mainPane.room.subtitleQuote}">$1</font>`,
|
2019-08-31 02:07:50 +10:00
|
|
|
)
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
2019-08-22 04:58:57 +10:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
rightInfo.color: theme.mainPane.room.lastEventDate
|
|
|
|
rightInfo.text: {
|
|
|
|
model.last_event_date < new Date(1) ?
|
|
|
|
"" :
|
|
|
|
|
|
|
|
utils.dateIsToday(model.last_event_date) ?
|
|
|
|
utils.formatTime(model.last_event_date, false) : // no seconds
|
|
|
|
|
|
|
|
model.last_event_date.getFullYear() === new Date().getFullYear() ?
|
2020-01-06 07:00:08 +11:00
|
|
|
Qt.formatDate(model.last_event_date, "d MMM") : // e.g. "5 Dec"
|
2019-12-03 07:29:29 +11:00
|
|
|
|
2020-01-06 07:00:08 +11:00
|
|
|
// model.last_event_date.getFullYear() ?
|
|
|
|
Qt.formatDate(model.last_event_date, "MMM yyyy") // e.g. "Jan 2020"
|
2019-12-03 07:29:29 +11:00
|
|
|
}
|
|
|
|
|
2019-08-22 04:58:57 +10:00
|
|
|
contextMenu: HMenu {
|
2019-12-21 01:29:45 +11:00
|
|
|
HMenuItemPopupSpawner {
|
2019-12-14 08:04:56 +11:00
|
|
|
visible: joined
|
2019-12-03 07:29:29 +11:00
|
|
|
enabled: model.can_invite
|
2019-12-14 08:04:56 +11:00
|
|
|
icon.name: "room-send-invite"
|
|
|
|
text: qsTr("Invite members")
|
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
popup: "Popups/InviteToRoomPopup.qml"
|
|
|
|
properties: ({
|
2019-12-03 07:29:29 +11:00
|
|
|
userId: userId,
|
|
|
|
roomId: model.id,
|
|
|
|
roomName: model.display_name,
|
|
|
|
invitingAllowed: Qt.binding(() => model.can_invite)
|
2019-12-21 01:29:45 +11:00
|
|
|
})
|
2019-12-14 08:04:56 +11:00
|
|
|
}
|
|
|
|
|
2019-12-12 23:32:50 +11:00
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy-room-id"
|
|
|
|
text: qsTr("Copy room ID")
|
2019-12-03 07:29:29 +11:00
|
|
|
onTriggered: Clipboard.text = model.id
|
2019-12-12 23:32:50 +11:00
|
|
|
}
|
|
|
|
|
2019-08-22 06:38:34 +10:00
|
|
|
HMenuItem {
|
|
|
|
visible: invited
|
|
|
|
icon.name: "invite-accept"
|
2019-08-29 08:21:13 +10:00
|
|
|
icon.color: theme.colors.positiveBackground
|
2019-12-18 08:59:53 +11:00
|
|
|
text: qsTr("Accept %1's invite").arg(utils.coloredNameHtml(
|
2019-12-03 07:29:29 +11:00
|
|
|
model.inviter_name, model.inviter_id
|
2019-08-22 06:38:34 +10:00
|
|
|
))
|
|
|
|
label.textFormat: Text.StyledText
|
|
|
|
|
|
|
|
onTriggered: py.callClientCoro(
|
2019-12-03 07:29:29 +11:00
|
|
|
userId, "join", [model.id]
|
2019-08-22 06:38:34 +10:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
HMenuItemPopupSpawner {
|
2019-12-14 08:04:56 +11:00
|
|
|
visible: invited || joined
|
2019-08-22 06:23:22 +10:00
|
|
|
icon.name: invited ? "invite-decline" : "room-leave"
|
2019-08-29 08:21:13 +10:00
|
|
|
icon.color: theme.colors.negativeBackground
|
2019-08-22 06:23:22 +10:00
|
|
|
text: invited ? qsTr("Decline invite") : qsTr("Leave")
|
2019-08-22 06:38:34 +10:00
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
popup: "Popups/LeaveRoomPopup.qml"
|
|
|
|
properties: ({
|
2019-12-03 07:29:29 +11:00
|
|
|
userId: userId,
|
|
|
|
roomId: model.id,
|
|
|
|
roomName: model.display_name,
|
2019-12-21 01:29:45 +11:00
|
|
|
})
|
2019-08-22 04:58:57 +10:00
|
|
|
}
|
2019-08-22 06:29:44 +10:00
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
HMenuItemPopupSpawner {
|
2019-08-22 06:29:44 +10:00
|
|
|
icon.name: "room-forget"
|
2019-08-29 08:21:13 +10:00
|
|
|
icon.color: theme.colors.negativeBackground
|
2019-08-22 06:29:44 +10:00
|
|
|
text: qsTr("Forget")
|
2019-08-22 06:38:34 +10:00
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
popup: "Popups/ForgetRoomPopup.qml"
|
|
|
|
autoDestruct: false
|
|
|
|
properties: ({
|
2019-12-03 07:29:29 +11:00
|
|
|
userId: userId,
|
|
|
|
roomId: model.id,
|
|
|
|
roomName: model.display_name,
|
2019-12-21 01:29:45 +11:00
|
|
|
})
|
2019-08-22 06:29:44 +10:00
|
|
|
}
|
2019-08-22 04:58:57 +10:00
|
|
|
}
|
2019-12-03 07:29:29 +11:00
|
|
|
|
2020-02-13 21:58:13 +11:00
|
|
|
onActivated: {
|
|
|
|
pageLoader.showRoom(userId, model.id)
|
2020-03-10 20:38:28 +11:00
|
|
|
mainPaneList.detachedCurrentIndex = false
|
2020-02-13 21:58:13 +11:00
|
|
|
}
|
2019-12-03 07:29:29 +11:00
|
|
|
|
|
|
|
|
|
|
|
property string userId
|
|
|
|
readonly property bool joined: ! invited && ! parted
|
|
|
|
readonly property bool invited: model.inviter_id && ! parted
|
|
|
|
readonly property bool parted: model.left
|
|
|
|
|
|
|
|
readonly property ListModel eventModel:
|
|
|
|
ModelStore.get(userId, model.id, "events")
|
|
|
|
|
|
|
|
readonly property QtObject lastEvent:
|
|
|
|
eventModel.count > 0 ? eventModel.get(0) : null
|
|
|
|
|
|
|
|
|
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2020-03-13 14:17:23 +11:00
|
|
|
Behavior on leftPadding { HNumberAnimation {} }
|
|
|
|
|
|
|
|
Binding on leftPadding {
|
|
|
|
value: (mainPane.minimumSize - loadedImage.width) / 2
|
|
|
|
when: mainPane.small
|
|
|
|
}
|
|
|
|
|
|
|
|
Binding on topPadding {
|
|
|
|
value: leftPadding / 2
|
|
|
|
when: mainPane.small
|
|
|
|
}
|
|
|
|
|
|
|
|
Binding on bottomPadding {
|
|
|
|
value: leftPadding / 2
|
|
|
|
when: mainPane.small
|
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|