nheko/src/timeline/ReactionsModel.h

42 lines
1.2 KiB
C
Raw Normal View History

2020-05-04 13:14:54 +02:00
#pragma once
#include <QAbstractListModel>
#include <QHash>
#include <utility>
#include <vector>
#include <mtx/events/collections.hpp>
class ReactionsModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit ReactionsModel(QObject *parent = nullptr) { Q_UNUSED(parent); }
enum Roles
{
Key,
Count,
Users,
SelfReacted,
};
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
public slots:
2020-05-06 11:28:24 +02:00
void addReaction(const std::string &room_id,
const mtx::events::RoomEvent<mtx::events::msg::Reaction> &reaction);
2020-05-04 13:14:54 +02:00
void removeReaction(const mtx::events::RoomEvent<mtx::events::msg::Reaction> &reaction);
private:
struct KeyReaction
{
std::string key;
2020-05-06 11:15:45 +02:00
std::map<std::string, mtx::events::RoomEvent<mtx::events::msg::Reaction>> reactions;
2020-05-04 13:14:54 +02:00
};
2020-05-06 11:28:24 +02:00
std::string room_id_;
2020-05-04 13:14:54 +02:00
std::vector<KeyReaction> reactions;
};