2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-07-24 01:11:33 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2024-03-16 03:24:33 +03:00
|
|
|
#pragma once
|
2021-07-24 01:11:33 +03:00
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2021-07-24 16:17:06 +03:00
|
|
|
#include <QDateTime>
|
2021-07-24 01:11:33 +03:00
|
|
|
#include <QObject>
|
2023-06-19 02:38:40 +03:00
|
|
|
#include <QQmlEngine>
|
2021-07-29 04:31:37 +03:00
|
|
|
#include <QSortFilterProxyModel>
|
2021-07-24 01:11:33 +03:00
|
|
|
#include <QString>
|
|
|
|
|
2022-10-10 15:38:29 +03:00
|
|
|
class ReadReceiptsModel final : public QAbstractListModel
|
2021-07-24 01:11:33 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
2021-07-24 01:11:33 +03:00
|
|
|
|
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
Mxid,
|
|
|
|
DisplayName,
|
|
|
|
AvatarUrl,
|
|
|
|
Timestamp,
|
|
|
|
RawTimestamp,
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit ReadReceiptsModel(QString event_id, QString room_id, QObject *parent = nullptr);
|
|
|
|
|
|
|
|
QString eventId() const { return event_id_; }
|
|
|
|
QString roomId() const { return room_id_; }
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent) const override
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
return readReceipts_.size();
|
|
|
|
}
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2021-07-24 01:11:33 +03:00
|
|
|
|
|
|
|
public slots:
|
2021-09-18 01:22:33 +03:00
|
|
|
void addUsers(const std::multimap<uint64_t, std::string, std::greater<uint64_t>> &users);
|
|
|
|
void update();
|
2021-07-24 01:11:33 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
QString dateFormat(const QDateTime &then) const;
|
2021-07-24 05:19:48 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QString event_id_;
|
|
|
|
QString room_id_;
|
|
|
|
QVector<QPair<QString, QDateTime>> readReceipts_;
|
2021-07-24 01:11:33 +03:00
|
|
|
};
|
|
|
|
|
2022-10-10 15:38:29 +03:00
|
|
|
class ReadReceiptsProxy final : public QSortFilterProxyModel
|
2021-07-29 04:31:37 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
2021-07-29 04:31:37 +03:00
|
|
|
|
2023-06-19 02:38:40 +03:00
|
|
|
QML_ELEMENT
|
|
|
|
QML_UNCREATABLE("")
|
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_PROPERTY(QString eventId READ eventId CONSTANT)
|
|
|
|
Q_PROPERTY(QString roomId READ roomId CONSTANT)
|
2021-07-29 04:31:37 +03:00
|
|
|
|
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
explicit ReadReceiptsProxy(QString event_id, QString room_id, QObject *parent = nullptr);
|
2021-07-29 04:31:37 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QString eventId() const { return event_id_; }
|
|
|
|
QString roomId() const { return room_id_; }
|
2021-07-29 04:31:37 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
QString event_id_;
|
|
|
|
QString room_id_;
|
2021-07-29 04:31:37 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
ReadReceiptsModel model_;
|
2021-07-29 04:31:37 +03:00
|
|
|
};
|