Add live location tracking model

This can either watch a single live location beacon or all of those in
a given room.
This commit is contained in:
Volker Krause
2023-06-11 13:37:09 +02:00
parent b968c85de2
commit d10460c45b
4 changed files with 216 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "neochatroom.h"
#include <QAbstractListModel>
#include <QPointer>
namespace Quotient
{
class RoomMessageEvent;
}
struct LiveLocationData {
QString eventId;
QString senderId;
QJsonObject beaconInfo;
QJsonObject beacon;
};
bool operator<(const LiveLocationData &lhs, const LiveLocationData &rhs);
/** Accumulates live location beacon events in a given room
* and provides the last known state for one or more live location beacons.
*/
class LiveLocationsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(NeoChatRoom *room MEMBER m_room NOTIFY roomChanged)
/** The event id of the beacon start event, ie. the one all suspequent
* events use to relate to the same beacon.
* If this is set only this specific beacon will be coverd by this model,
* if it is empty, all beacons in the room will be covered.
*/
Q_PROPERTY(QString eventId MEMBER m_eventId NOTIFY eventIdChanged)
public:
explicit LiveLocationsModel(QObject *parent = nullptr);
enum Roles {
LatitudeRole, /**< Latest latitude of a live locaction beacon. */
LongitudeRole, /**< Latest longitude of a live locaction beacon. */
AssetRole, /**< Type of location event, e.g. self pin of the user location. */
AuthorRole, /**< The author of the event. */
IsLiveRole, /**< Boolean that indicates whether a live location beacon is still live. */
};
Q_ENUM(Roles)
int rowCount(const QModelIndex &parent = {}) const override;
QVariant data(const QModelIndex &index, int roleName) const override;
QHash<int, QByteArray> roleNames() const override;
Q_SIGNALS:
void roomChanged();
void eventIdChanged();
private:
void addEvent(const Quotient::RoomEvent *event);
void updateLocationData(LiveLocationData &&data);
QPointer<NeoChatRoom> m_room;
QString m_eventId;
QList<LiveLocationData> m_locations;
};