moment/src/qml/MainPane/RoomDelegate.qml

167 lines
5.1 KiB
QML
Raw Normal View History

2019-07-13 07:06:37 +10:00
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../Base"
import "../utils.js" as Utils
2019-03-22 14:28:14 +11:00
HTileDelegate {
id: roomDelegate
spacing: theme.spacing
2019-12-11 06:17:41 +11:00
backgroundColor: theme.mainPane.room.background
opacity: model.data.left ? theme.mainPane.room.leftRoomOpacity : 1
shouldBeCurrent:
2019-12-10 02:35:50 +11:00
window.uiState.page === "Chat/Chat.qml" &&
window.uiState.pageProperties.userId === model.user_id &&
window.uiState.pageProperties.roomId === model.data.room_id
setCurrentTimer.running:
2019-12-11 06:17:41 +11:00
! mainPaneList.activateLimiter.running && ! mainPane.hasFocus
Behavior on opacity { HOpacityAnimator {} }
readonly property bool joined: ! invited && ! parted
readonly property bool invited: model.data.inviter_id && ! parted
readonly property bool parted: model.data.left
readonly property var lastEvent: model.data.last_event
onActivated: pageLoader.showRoom(model.user_id, model.data.room_id)
image: HRoomAvatar {
displayName: model.data.display_name
mxc: model.data.avatar_url
}
2019-12-11 06:17:41 +11:00
title.color: theme.mainPane.room.name
2019-11-28 01:03:49 +11:00
title.text: model.data.display_name || qsTr("Empty room")
additionalInfo.children: HIcon {
svgName: "invite-received"
2019-08-29 08:21:13 +10:00
colorize: theme.colors.alertBackground
visible: invited
Layout.maximumWidth: invited ? implicitWidth : 0
Behavior on Layout.maximumWidth { HNumberAnimation {} }
}
2019-12-11 06:17:41 +11:00
rightInfo.color: theme.mainPane.room.lastEventDate
rightInfo.text: {
! lastEvent || ! lastEvent.date ?
"" :
Utils.dateIsToday(lastEvent.date) ?
Utils.formatTime(lastEvent.date, false) : // no seconds
2019-12-10 02:35:50 +11:00
lastEvent.date.getFullYear() === new Date().getFullYear() ?
Qt.formatDate(lastEvent.date, "d MMM") : // e.g. "5 Dec"
lastEvent.date.getFullYear()
}
2019-03-22 14:28:14 +11:00
2019-12-11 06:17:41 +11:00
subtitle.color: theme.mainPane.room.subtitle
subtitle.font.italic:
Boolean(lastEvent && lastEvent.event_type === "RoomMessageEmote")
subtitle.textFormat: Text.StyledText
subtitle.text: {
if (! lastEvent) return ""
let isEmote = lastEvent.event_type === "RoomMessageEmote"
let isMsg = lastEvent.event_type.startsWith("RoomMessage")
let isUnknownMsg = lastEvent.event_type === "RoomMessageUnknown"
let isCryptMedia = lastEvent.event_type.startsWith("RoomEncrypted")
// If it's a general event
if (isEmote || isUnknownMsg || (! isMsg && ! isCryptMedia)) {
return Utils.processedEventText(lastEvent)
}
let text = Utils.coloredNameHtml(
lastEvent.sender_name, lastEvent.sender_id
) + ": " + lastEvent.inline_content
return text.replace(
/< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g,
2019-12-11 06:17:41 +11:00
`<font color="${theme.mainPane.room.subtitleQuote}">$1</font>`,
)
2019-03-22 14:28:14 +11:00
}
contextMenu: HMenu {
HMenuItem {
visible: joined
enabled: model.data.can_invite
icon.name: "room-send-invite"
text: qsTr("Invite members")
onTriggered: Utils.makePopup(
"Popups/InviteToRoomPopup.qml",
window,
{
userId: model.user_id,
roomId: model.data.room_id,
2019-12-14 08:08:59 +11:00
roomName: model.data.display_name,
invitingAllowed: Qt.binding(() => model.data.can_invite)
}
)
}
2019-12-12 23:32:50 +11:00
HMenuItem {
icon.name: "copy-room-id"
text: qsTr("Copy room ID")
onTriggered: Clipboard.text = model.data.room_id
}
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-08-22 06:38:34 +10:00
text: qsTr("Accept %1's invite").arg(Utils.coloredNameHtml(
model.data.inviter_name, model.data.inviter_id
))
label.textFormat: Text.StyledText
onTriggered: py.callClientCoro(
model.user_id, "join", [model.data.room_id]
)
}
HMenuItem {
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-09-09 23:12:51 +10:00
onTriggered: Utils.makePopup(
"Popups/LeaveRoomPopup.qml",
window,
2019-09-09 23:12:51 +10:00
{
userId: model.user_id,
roomId: model.data.room_id,
roomName: model.data.display_name,
}
)
}
HMenuItem {
icon.name: "room-forget"
2019-08-29 08:21:13 +10:00
icon.color: theme.colors.negativeBackground
text: qsTr("Forget")
2019-08-22 06:38:34 +10:00
2019-09-09 23:24:45 +10:00
onTriggered: Utils.makePopup(
"Popups/ForgetRoomPopup.qml",
window,
2019-09-09 23:24:45 +10:00
{
userId: model.user_id,
roomId: model.data.room_id,
roomName: model.data.display_name,
},
null,
false,
)
}
}
2019-03-22 14:28:14 +11:00
}