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
|
2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-27 09:06:42 -04:00
|
|
|
import Clipboard 0.1
|
2019-12-02 16:29:29 -04:00
|
|
|
import ".."
|
2019-04-28 15:18:36 -04:00
|
|
|
import "../Base"
|
2020-03-30 15:03:35 -04:00
|
|
|
import "../Base/HTile"
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2020-05-14 19:30:34 -04:00
|
|
|
HTile {
|
2020-03-22 12:50:10 -04:00
|
|
|
id: room
|
2020-05-13 08:24:53 -04:00
|
|
|
backgroundColor: theme.mainPane.listView.room.background
|
2020-05-13 07:37:39 -04:00
|
|
|
leftPadding: theme.spacing * 2
|
|
|
|
rightPadding: theme.spacing
|
2020-03-12 22:16:33 -04:00
|
|
|
|
2020-03-30 15:03:35 -04:00
|
|
|
contentItem: ContentRow {
|
|
|
|
tile: room
|
2020-05-13 21:51:31 -04:00
|
|
|
opacity: model.left ? theme.mainPane.listView.room.leftRoomOpacity : 1
|
|
|
|
|
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2020-03-15 15:01:09 -04:00
|
|
|
|
2020-03-30 15:03:35 -04:00
|
|
|
HRoomAvatar {
|
|
|
|
id: avatar
|
|
|
|
roomId: model.id
|
|
|
|
displayName: model.display_name
|
|
|
|
mxc: model.avatar_url
|
|
|
|
compact: room.compact
|
2020-05-13 08:24:53 -04:00
|
|
|
radius: theme.mainPane.listView.room.avatarRadius
|
2020-03-22 23:55:48 -04:00
|
|
|
|
2020-03-30 15:03:35 -04:00
|
|
|
Behavior on radius { HNumberAnimation {} }
|
2020-03-22 23:55:48 -04:00
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
|
2020-03-30 15:03:35 -04:00
|
|
|
HColumnLayout {
|
|
|
|
HRowLayout {
|
|
|
|
spacing: room.spacing
|
|
|
|
|
|
|
|
TitleLabel {
|
|
|
|
text: model.display_name || qsTr("Empty room")
|
2020-06-26 05:43:49 -04:00
|
|
|
color:
|
|
|
|
model.local_unreads ?
|
|
|
|
theme.mainPane.listView.room.unreadName :
|
|
|
|
theme.mainPane.listView.room.name
|
2020-03-30 15:03:35 -04:00
|
|
|
}
|
|
|
|
|
2020-05-01 04:35:54 -04:00
|
|
|
MessageIndicator {
|
|
|
|
indicatorTheme:
|
2020-05-13 08:24:53 -04:00
|
|
|
theme.mainPane.listView.room.unreadIndicator
|
2020-05-01 04:35:54 -04:00
|
|
|
unreads: model.unreads
|
2020-05-31 19:13:19 -04:00
|
|
|
highlights: model.highlights
|
2020-06-26 05:43:49 -04:00
|
|
|
localUnreads: model.local_unreads
|
2020-04-09 18:03:12 -04:00
|
|
|
}
|
2020-03-30 15:03:35 -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 {} }
|
|
|
|
}
|
|
|
|
|
|
|
|
TitleRightInfoLabel {
|
|
|
|
tile: room
|
2020-05-13 08:24:53 -04:00
|
|
|
color: theme.mainPane.listView.room.lastEventDate
|
2020-06-24 08:14:54 -04:00
|
|
|
text: utils.smartFormatDate(model.last_event_date)
|
2020-03-30 15:03:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SubtitleLabel {
|
|
|
|
tile: room
|
2020-05-13 08:24:53 -04:00
|
|
|
color: theme.mainPane.listView.room.subtitle
|
2020-03-30 15:03:35 -04:00
|
|
|
textFormat: Text.StyledText
|
|
|
|
font.italic:
|
|
|
|
lastEvent && lastEvent.event_type === "RoomMessageEmote"
|
|
|
|
|
|
|
|
text: {
|
|
|
|
if (! lastEvent) return ""
|
|
|
|
|
|
|
|
const ev_type = lastEvent.event_type
|
|
|
|
const isEmote = ev_type === "RoomMessageEmote"
|
|
|
|
const isMsg = ev_type.startsWith("RoomMessage")
|
|
|
|
const isUnknownMsg = ev_type === "RoomMessageUnknown"
|
|
|
|
const isCryptMedia = ev_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
|
|
|
|
|
2020-04-27 23:49:36 -04:00
|
|
|
const subColor =
|
2020-05-13 08:24:53 -04:00
|
|
|
theme.mainPane.listView.room.subtitleQuote
|
2020-03-30 15:03:35 -04:00
|
|
|
|
|
|
|
return text.replace(
|
|
|
|
/< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g,
|
|
|
|
`<font color="${subColor}">` +
|
|
|
|
`$1</font>`,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
2019-08-21 14:58:57 -04:00
|
|
|
contextMenu: HMenu {
|
2019-12-20 10:29:45 -04:00
|
|
|
HMenuItemPopupSpawner {
|
2019-12-13 17:04:56 -04:00
|
|
|
visible: joined
|
2019-12-02 16:29:29 -04:00
|
|
|
enabled: model.can_invite
|
2019-12-13 17:04:56 -04:00
|
|
|
icon.name: "room-send-invite"
|
|
|
|
text: qsTr("Invite members")
|
|
|
|
|
2019-12-20 10:29:45 -04:00
|
|
|
popup: "Popups/InviteToRoomPopup.qml"
|
|
|
|
properties: ({
|
2020-04-29 14:00:02 -04:00
|
|
|
userId: model.for_account,
|
2019-12-02 16:29:29 -04:00
|
|
|
roomId: model.id,
|
|
|
|
roomName: model.display_name,
|
|
|
|
invitingAllowed: Qt.binding(() => model.can_invite)
|
2019-12-20 10:29:45 -04:00
|
|
|
})
|
2019-12-13 17:04:56 -04:00
|
|
|
}
|
|
|
|
|
2019-12-12 08:32:50 -04:00
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy-room-id"
|
|
|
|
text: qsTr("Copy room ID")
|
2019-12-02 16:29:29 -04:00
|
|
|
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
|
2019-12-17 17:59:53 -04:00
|
|
|
text: qsTr("Accept %1's invite").arg(utils.coloredNameHtml(
|
2019-12-02 16:29:29 -04:00
|
|
|
model.inviter_name, model.inviter_id
|
2019-08-21 16:38:34 -04:00
|
|
|
))
|
|
|
|
label.textFormat: Text.StyledText
|
|
|
|
|
|
|
|
onTriggered: py.callClientCoro(
|
2020-04-29 14:00:02 -04:00
|
|
|
model.for_account, "join", [model.id]
|
2019-08-21 16:38:34 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-20 10:29:45 -04:00
|
|
|
HMenuItemPopupSpawner {
|
2019-12-13 17:04:56 -04:00
|
|
|
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
|
|
|
|
2019-12-20 10:29:45 -04:00
|
|
|
popup: "Popups/LeaveRoomPopup.qml"
|
|
|
|
properties: ({
|
2020-04-29 14:00:02 -04:00
|
|
|
userId: model.for_account,
|
2019-12-02 16:29:29 -04:00
|
|
|
roomId: model.id,
|
|
|
|
roomName: model.display_name,
|
2019-12-20 10:29:45 -04:00
|
|
|
})
|
2019-08-21 14:58:57 -04:00
|
|
|
}
|
2019-08-21 16:29:44 -04:00
|
|
|
|
2019-12-20 10:29:45 -04:00
|
|
|
HMenuItemPopupSpawner {
|
2019-08-21 16:29:44 -04:00
|
|
|
icon.name: "room-forget"
|
2019-08-28 18:21:13 -04:00
|
|
|
icon.color: theme.colors.negativeBackground
|
2019-08-21 16:29:44 -04:00
|
|
|
text: qsTr("Forget")
|
2019-08-21 16:38:34 -04:00
|
|
|
|
2019-12-20 10:29:45 -04:00
|
|
|
popup: "Popups/ForgetRoomPopup.qml"
|
|
|
|
autoDestruct: false
|
|
|
|
properties: ({
|
2020-04-29 14:00:02 -04:00
|
|
|
userId: model.for_account,
|
2019-12-02 16:29:29 -04:00
|
|
|
roomId: model.id,
|
|
|
|
roomName: model.display_name,
|
2019-12-20 10:29:45 -04:00
|
|
|
})
|
2019-08-21 16:29:44 -04:00
|
|
|
}
|
2019-08-21 14:58:57 -04:00
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
readonly property bool joined: ! invited && ! parted
|
|
|
|
readonly property bool invited: model.inviter_id && ! parted
|
|
|
|
readonly property bool parted: model.left
|
|
|
|
|
|
|
|
readonly property ListModel eventModel:
|
2020-04-29 14:00:02 -04:00
|
|
|
ModelStore.get(model.for_account, model.id, "events")
|
2019-12-02 16:29:29 -04:00
|
|
|
|
|
|
|
readonly property QtObject lastEvent:
|
|
|
|
eventModel.count > 0 ? eventModel.get(0) : null
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|