Files
amnezia-client/client/ui/models/newsModel.h
T

68 lines
1.8 KiB
C++
Raw Normal View History

2025-10-06 08:06:36 +04:00
#ifndef NEWSMODEL_H
#define NEWSMODEL_H
#include <QAbstractListModel>
#include <QDateTime>
#include <QJsonArray>
#include <QSet>
#include <QString>
#include <QVector>
2026-05-04 07:37:19 +03:00
#include <optional>
2025-10-06 08:06:36 +04:00
struct NewsItem
{
QString id;
QString title;
QString content;
QDateTime timestamp;
2026-05-04 07:37:19 +03:00
bool isUpdate = false;
2025-10-06 08:06:36 +04:00
};
class NewsModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles {
IdRole = Qt::UserRole + 1,
TitleRole,
ContentRole,
TimestampRole,
IsReadRole,
2026-05-04 07:37:19 +03:00
IsProcessedRole,
IsUpdateRole
2025-10-06 08:06:36 +04:00
};
explicit NewsModel(class SecureAppSettingsRepository* appSettingsRepository, QObject *parent = nullptr);
2025-10-06 08:06:36 +04:00
Q_INVOKABLE void markAsRead(int index);
2026-05-04 07:37:19 +03:00
Q_INVOKABLE void markUpdateAsSkipped();
2025-10-06 08:06:36 +04:00
Q_PROPERTY(int processedIndex READ processedIndex WRITE setProcessedIndex NOTIFY processedIndexChanged)
Q_PROPERTY(bool hasUnread READ hasUnread NOTIFY hasUnreadChanged)
int processedIndex() const;
void setProcessedIndex(int index);
2026-05-04 07:37:19 +03:00
void setNewsList(const QJsonArray &items);
void setUpdateNotification(const QString &id, const QString &title, const QString &content);
2025-10-06 08:06:36 +04:00
bool hasUnread() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
signals:
void processedIndexChanged(int index);
void hasUnreadChanged();
private:
QVector<NewsItem> m_items;
2026-05-04 07:37:19 +03:00
QVector<NewsItem> m_apiItems;
std::optional<NewsItem> m_updateItem;
2025-10-06 08:06:36 +04:00
int m_processedIndex = -1;
class SecureAppSettingsRepository* m_appSettingsRepository;
2025-10-06 08:06:36 +04:00
QSet<QString> m_readIds;
void loadReadIds();
void saveReadIds() const;
2026-05-04 07:37:19 +03:00
void updateModel();
2025-10-06 08:06:36 +04:00
};
#endif // NEWSMODEL_H