summary refs log tree commit diff
path: root/src/ReadReceiptsModel.h
diff options
context:
space:
mode:
authorDeepBlueV7.X <nicolas.werner@hotmail.de>2021-07-30 22:08:51 +0000
committerGitHub <noreply@github.com>2021-07-30 22:08:51 +0000
commit5b5a89b52217b672bf31c26ccd6e2a3b6f15a942 (patch)
tree0f076e6b6ee36e6fd8258bbcf677a779b6b794c3 /src/ReadReceiptsModel.h
parentFix crash when we don't have keys for other device when receiving an olm mess... (diff)
parentUse correct date format (diff)
downloadnheko-5b5a89b52217b672bf31c26ccd6e2a3b6f15a942.tar.xz
Merge pull request #655 from LorenDB/qml-all-the-things
QML all the things, part 2: Read receipts dialog
Diffstat (limited to 'src/ReadReceiptsModel.h')
-rw-r--r--src/ReadReceiptsModel.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/ReadReceiptsModel.h b/src/ReadReceiptsModel.h
new file mode 100644

index 00000000..3b45716c --- /dev/null +++ b/src/ReadReceiptsModel.h
@@ -0,0 +1,73 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef READRECEIPTSMODEL_H +#define READRECEIPTSMODEL_H + +#include <QAbstractListModel> +#include <QDateTime> +#include <QObject> +#include <QSortFilterProxyModel> +#include <QString> + +class ReadReceiptsModel : public QAbstractListModel +{ + Q_OBJECT + +public: + 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; + +public slots: + void addUsers(const std::multimap<uint64_t, std::string, std::greater<uint64_t>> &users); + void update(); + +private: + QString dateFormat(const QDateTime &then) const; + + QString event_id_; + QString room_id_; + QVector<QPair<QString, QDateTime>> readReceipts_; +}; + +class ReadReceiptsProxy : public QSortFilterProxyModel +{ + Q_OBJECT + + Q_PROPERTY(QString eventId READ eventId CONSTANT) + Q_PROPERTY(QString roomId READ roomId CONSTANT) + +public: + explicit ReadReceiptsProxy(QString event_id, QString room_id, QObject *parent = nullptr); + + QString eventId() const { return event_id_; } + QString roomId() const { return room_id_; } + +private: + QString event_id_; + QString room_id_; + + ReadReceiptsModel model_; +}; + +#endif // READRECEIPTSMODEL_H