moment/src/gui/MainPane/Room.qml

211 lines
6.3 KiB
QML
Raw Normal View History

2019-12-19 07:46:16 -04:00
// SPDX-License-Identifier: LGPL-3.0-or-later
2019-07-12 17:06:37 -04:00
import QtQuick 2.12
import QtQuick.Layouts 1.12
2019-12-27 09:06:42 -04:00
import Clipboard 0.1
import ".."
import "../Base"
2019-03-21 23:28:14 -04:00
HTileDelegate {
id: room
2020-03-13 01:09:04 -04:00
backgroundColor: theme.mainPane.listView.room.background
opacity: model.left ? theme.mainPane.listView.room.leftRoomOpacity : 1
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
image: HRoomAvatar {
roomId: model.id
displayName: model.display_name
mxc: model.avatar_url
compact: room.compact
radius:
mainPane.small ?
theme.mainPane.listView.room.collapsedAvatarRadius :
theme.mainPane.listView.room.avatarRadius
Behavior on radius { HNumberAnimation {} }
}
2020-03-13 01:09:04 -04:00
title.color: theme.mainPane.listView.room.name
title.text: model.display_name || qsTr("Empty room")
2020-03-22 23:55:48 -04:00
additionalInfo.children: [
// HLabel {
// text: model.mentions
// font.pixelSize: theme.fontSize.small
// verticalAlignment: Qt.AlignVCenter
// leftPadding: theme.spacing / 4
// rightPadding: leftPadding
// scale: model.mentions === 0 ? 0 : 1
// visible: scale > 0
// background: Rectangle {
// color: theme.colors.alertBackground
// radius: theme.radius / 4
// }
// Behavior on scale { HNumberAnimation {} }
// },
2020-03-22 23:55:48 -04:00
HIcon {
svgName: "invite-received"
colorize: theme.colors.alertBackground
small: room.compact
visible: invited
Layout.maximumWidth: invited ? implicitWidth : 0
Behavior on Layout.maximumWidth { HNumberAnimation {} }
}
]
2020-03-13 01:09:04 -04:00
subtitle.color: theme.mainPane.listView.room.subtitle
subtitle.textFormat: Text.StyledText
subtitle.font.italic:
lastEvent && lastEvent.event_type === "RoomMessageEmote"
subtitle.text: {
if (! lastEvent) return ""
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")
// If it's a general event
if (isEmote || isUnknownMsg || (! isMsg && ! isCryptMedia))
return utils.processedEventText(lastEvent)
const text = utils.coloredNameHtml(
lastEvent.sender_name, lastEvent.sender_id
) + ": " + lastEvent.inline_content
return text.replace(
/< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g,
2020-03-13 01:09:04 -04:00
`<font color="${theme.mainPane.listView.room.subtitleQuote}">` +
`$1</font>`,
)
2019-03-21 23:28:14 -04:00
}
2020-03-13 01:09:04 -04:00
rightInfo.color: theme.mainPane.listView.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() ?
Qt.formatDate(model.last_event_date, "d MMM") : // e.g. "5 Dec"
// model.last_event_date.getFullYear() ?
Qt.formatDate(model.last_event_date, "MMM yyyy") // e.g. "Jan 2020"
}
contextMenu: HMenu {
HMenuItemPopupSpawner {
visible: joined
enabled: model.can_invite
icon.name: "room-send-invite"
text: qsTr("Invite members")
popup: "Popups/InviteToRoomPopup.qml"
properties: ({
userId: userId,
roomId: model.id,
roomName: model.display_name,
invitingAllowed: Qt.binding(() => model.can_invite)
})
}
2019-12-12 08:32:50 -04:00
HMenuItem {
icon.name: "copy-room-id"
text: qsTr("Copy room ID")
onTriggered: Clipboard.text = model.id
2019-12-12 08:32:50 -04:00
}
2019-08-21 16:38:34 -04:00
HMenuItem {
visible: invited
icon.name: "invite-accept"
2019-08-28 18:21:13 -04:00
icon.color: theme.colors.positiveBackground
text: qsTr("Accept %1's invite").arg(utils.coloredNameHtml(
model.inviter_name, model.inviter_id
2019-08-21 16:38:34 -04:00
))
label.textFormat: Text.StyledText
onTriggered: py.callClientCoro(
userId, "join", [model.id]
2019-08-21 16:38:34 -04:00
)
}
HMenuItemPopupSpawner {
visible: invited || joined
2019-08-21 16:23:22 -04:00
icon.name: invited ? "invite-decline" : "room-leave"
2019-08-28 18:21:13 -04:00
icon.color: theme.colors.negativeBackground
2019-08-21 16:23:22 -04:00
text: invited ? qsTr("Decline invite") : qsTr("Leave")
2019-08-21 16:38:34 -04:00
popup: "Popups/LeaveRoomPopup.qml"
properties: ({
userId: userId,
roomId: model.id,
roomName: model.display_name,
})
}
HMenuItemPopupSpawner {
icon.name: "room-forget"
2019-08-28 18:21:13 -04:00
icon.color: theme.colors.negativeBackground
text: qsTr("Forget")
2019-08-21 16:38:34 -04:00
popup: "Popups/ForgetRoomPopup.qml"
autoDestruct: false
properties: ({
userId: userId,
roomId: model.id,
roomName: model.display_name,
})
}
}
onActivated: {
pageLoader.showRoom(userId, model.id)
2020-03-10 05:38:28 -04:00
mainPaneList.detachedCurrentIndex = false
mainPaneList.centerToHighlight = false
}
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 {} }
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-21 23:28:14 -04:00
}