Show starting live location beacons as location delegates in the timeline

Also, hide ending live location beacon state changes.
This commit is contained in:
Volker Krause
2023-06-11 11:36:47 +02:00
parent d10460c45b
commit 59495a1452
6 changed files with 110 additions and 0 deletions

View File

@@ -525,6 +525,9 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return DelegateType::Sticker;
}
if (evt.isStateEvent()) {
if (evt.matrixType() == "org.matrix.msc3672.beacon_info"_ls) {
return DelegateType::LiveLocation;
}
return DelegateType::State;
}
if (is<const EncryptedEvent>(evt)) {
@@ -635,6 +638,11 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return EventStatus::Hidden;
}
// hide ending live location beacons
if (evt.isStateEvent() && evt.matrixType() == "org.matrix.msc3672.beacon_info"_ls && !evt.contentJson()["live"_ls].toBool()) {
return EventStatus::Hidden;
}
return EventStatus::Normal;
}

View File

@@ -53,6 +53,7 @@ public:
ReadMarker, /**< The local user read marker. */
Poll, /**< The initial event for a poll. */
Location, /**< A location event. */
LiveLocation, /**< The initial event of a shared live location (i.e., the place where this is supposed to be shown in the timeline). */
Other, /**< Anything that cannot be classified as another type. */
};
Q_ENUM(DelegateType);

View File

@@ -11,7 +11,9 @@ import org.kde.kirigami 2.15 as Kirigami
import org.kde.neochat 1.0
DelegateChooser {
id: root
role: "delegateType"
property var room
DelegateChoice {
roleValue: MessageEventModel.State
@@ -77,6 +79,12 @@ DelegateChooser {
roleValue: MessageEventModel.Location
delegate: LocationDelegate {}
}
DelegateChoice {
roleValue: MessageEventModel.LiveLocation
delegate: LiveLocationDelegate {
room: root.room
}
}
DelegateChoice {
roleValue: MessageEventModel.Other

View File

@@ -0,0 +1,91 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtLocation 5.15
import QtPositioning 5.15
import org.kde.kirigami 2.15 as Kirigami
import org.kde.neochat 1.0
/**
* @brief A timeline delegate for a location message.
*
* @inherit TimelineContainer
*/
TimelineContainer {
id: root
property alias room: liveLocationModel.room
ColumnLayout {
Layout.maximumWidth: root.contentMaxWidth
Layout.preferredWidth: root.contentMaxWidth
LiveLocationsModel {
id: liveLocationModel
eventId: root.eventId
}
Map {
id: map
Layout.fillWidth: true
Layout.preferredHeight: root.contentMaxWidth / 16 * 9
// center: QtPositioning.coordinate(root.latitude, root.longitude)
// zoomLevel: 15
plugin: OsmLocationPlugin.plugin
onCopyrightLinkActivated: Qt.openUrlExternally(link)
MapItemView {
model: liveLocationModel
delegate: MapQuickItem {
anchorPoint.x: sourceItem.width / 2
anchorPoint.y: sourceItem.height
coordinate: QtPositioning.coordinate(model.latitude, model.longitude)
autoFadeIn: false
sourceItem: Kirigami.Icon {
width: height
height: Kirigami.Units.iconSizes.huge
source: "gps"
isMask: true
color: model.isLive ? Kirigami.Theme.highlightColor : Kirigami.Theme.disabledTextColor
Kirigami.Icon {
anchors.centerIn: parent
anchors.verticalCenterOffset: -parent.height / 8
visible: model.asset === "m.pin"
width: height
height: parent.height / 3 + 1
source: "pin"
isMask: true
color: parent.color
}
Kirigami.Avatar {
anchors.centerIn: parent
anchors.verticalCenterOffset: -parent.height / 8
visible: model.asset === "m.self"
width: height
height: parent.height / 3 + 1
name: model.author.displayName
source: model.author.avatarSource
color: model.author.color
}
}
}
}
TapHandler {
acceptedButtons: Qt.LeftButton
onLongPressed: openMessageContext("")
}
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: openMessageContext("")
}
}
}
}

View File

@@ -173,6 +173,7 @@ QQC2.ScrollView {
}
delegate: EventDelegate {
room: root.currentRoom
}
QQC2.RoundButton {

View File

@@ -127,5 +127,6 @@
<file alias="AvatarTabButton.qml">qml/Component/AvatarTabButton.qml</file>
<file alias="SpaceDrawer.qml">qml/Page/RoomList/SpaceDrawer.qml</file>
<file alias="OsmLocationPlugin.qml">qml/Component/Timeline/OsmLocationPlugin.qml</file>
<file alias="LiveLocationDelegate.qml">qml/Component/Timeline/LiveLocationDelegate.qml</file>
</qresource>
</RCC>