diff options
author | Loren Burkholder <computersemiexpert@outlook.com> | 2021-07-23 18:11:33 -0400 |
---|---|---|
committer | Loren Burkholder <computersemiexpert@outlook.com> | 2021-07-29 21:07:16 -0400 |
commit | 4dd994ae009b622cd35e292d1170a3f60a26c4d6 (patch) | |
tree | af3a825decdd96963a9cf0c9efcd57a3d8db1ed4 /src/ReadReceiptsModel.h | |
parent | Port to explicit connect syntax (diff) | |
download | nheko-4dd994ae009b622cd35e292d1170a3f60a26c4d6.tar.xz |
QML the read receipts list
There are probably a few things wrong with this, but I'm going to call it good enough for an initial commit
Diffstat (limited to 'src/ReadReceiptsModel.h')
-rw-r--r-- | src/ReadReceiptsModel.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/ReadReceiptsModel.h b/src/ReadReceiptsModel.h new file mode 100644 index 00000000..d90bf7c1 --- /dev/null +++ b/src/ReadReceiptsModel.h @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef READRECEIPTSMODEL_H +#define READRECEIPTSMODEL_H + +#include <QAbstractListModel> +#include <QObject> +#include <QString> + +class ReadReceipt : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString mxid READ mxid CONSTANT) + Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged) + Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged) + Q_PROPERTY(QString timestamp READ timestamp CONSTANT) + +public: + explicit ReadReceipt(QString mxid, + QString room_id, + uint64_t timestamp, + QObject *parent = nullptr); + + QString mxid() const { return mxid_; } + QString displayName() const { return displayName_; } + QString avatarUrl() const { return avatarUrl_; } + QString timestamp() const; + +signals: + void displayNameChanged(); + void avatarUrlChanged(); + +private: + QString dateFormat(const QDateTime &then) const; + + QString mxid_; + QString room_id_; + QString displayName_; + QString avatarUrl_; + uint64_t timestamp_; +}; + +class ReadReceiptsModel : public QAbstractListModel +{ + Q_OBJECT + + Q_PROPERTY(QString eventId READ eventId CONSTANT) + Q_PROPERTY(QString roomId READ roomId CONSTANT) + +public: + enum Roles + { + Mxid, + DisplayName, + AvatarUrl, + Timestamp, + }; + + explicit ReadReceiptsModel(QString event_id, QString room_id, QObject *parent = nullptr); + ~ReadReceiptsModel() override; + + 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); + +private: + QString event_id_; + QString room_id_; + QVector<ReadReceipt *> readReceipts_; + std::multimap<uint64_t, std::string, std::greater<uint64_t>> users_; +}; + +#endif // READRECEIPTSMODEL_H |