2019-08-31 00:20:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QColor>
|
2019-09-01 23:58:26 +03:00
|
|
|
#include <QDate>
|
2019-08-31 23:43:31 +03:00
|
|
|
#include <QHash>
|
2019-08-31 00:20:53 +03:00
|
|
|
|
2019-08-31 23:43:31 +03:00
|
|
|
#include <mtx/responses.hpp>
|
2019-08-31 00:20:53 +03:00
|
|
|
|
2019-09-03 00:28:05 +03:00
|
|
|
namespace qml_mtx_events {
|
|
|
|
Q_NAMESPACE
|
|
|
|
|
|
|
|
enum EventType
|
|
|
|
{
|
|
|
|
// Unsupported event
|
|
|
|
Unsupported,
|
|
|
|
/// m.room_key_request
|
|
|
|
KeyRequest,
|
|
|
|
/// m.room.aliases
|
|
|
|
Aliases,
|
|
|
|
/// m.room.avatar
|
|
|
|
Avatar,
|
|
|
|
/// m.room.canonical_alias
|
|
|
|
CanonicalAlias,
|
|
|
|
/// m.room.create
|
|
|
|
Create,
|
|
|
|
/// m.room.encrypted.
|
|
|
|
Encrypted,
|
|
|
|
/// m.room.encryption.
|
|
|
|
Encryption,
|
|
|
|
/// m.room.guest_access
|
|
|
|
GuestAccess,
|
|
|
|
/// m.room.history_visibility
|
|
|
|
HistoryVisibility,
|
|
|
|
/// m.room.join_rules
|
|
|
|
JoinRules,
|
|
|
|
/// m.room.member
|
|
|
|
Member,
|
|
|
|
/// m.room.name
|
|
|
|
Name,
|
|
|
|
/// m.room.power_levels
|
|
|
|
PowerLevels,
|
|
|
|
/// m.room.tombstone
|
|
|
|
Tombstone,
|
|
|
|
/// m.room.topic
|
|
|
|
Topic,
|
|
|
|
/// m.room.redaction
|
|
|
|
Redaction,
|
|
|
|
/// m.room.pinned_events
|
|
|
|
PinnedEvents,
|
|
|
|
// m.sticker
|
|
|
|
Sticker,
|
|
|
|
// m.tag
|
|
|
|
Tag,
|
|
|
|
/// m.room.message
|
|
|
|
AudioMessage,
|
|
|
|
EmoteMessage,
|
|
|
|
FileMessage,
|
|
|
|
ImageMessage,
|
|
|
|
LocationMessage,
|
|
|
|
NoticeMessage,
|
|
|
|
TextMessage,
|
|
|
|
VideoMessage,
|
|
|
|
UnknownMessage,
|
|
|
|
};
|
|
|
|
Q_ENUM_NS(EventType)
|
|
|
|
}
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
class TimelineModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-09-01 00:44:17 +03:00
|
|
|
explicit TimelineModel(QString room_id, QObject *parent = 0);
|
2019-08-31 00:20:53 +03:00
|
|
|
|
|
|
|
enum Roles
|
|
|
|
{
|
2019-09-01 15:17:33 +03:00
|
|
|
Section,
|
2019-08-31 00:20:53 +03:00
|
|
|
Type,
|
|
|
|
Body,
|
|
|
|
FormattedBody,
|
|
|
|
UserId,
|
|
|
|
UserName,
|
|
|
|
Timestamp,
|
2019-09-08 13:44:46 +03:00
|
|
|
Url,
|
|
|
|
Height,
|
|
|
|
Width,
|
|
|
|
ProportionalHeight,
|
2019-09-08 16:26:46 +03:00
|
|
|
Id,
|
2019-08-31 00:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
2019-09-03 00:28:05 +03:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
2019-08-31 00:20:53 +03:00
|
|
|
|
|
|
|
Q_INVOKABLE QColor userColor(QString id, QColor background);
|
2019-09-01 23:34:36 +03:00
|
|
|
Q_INVOKABLE QString displayName(QString id) const;
|
2019-09-07 23:22:07 +03:00
|
|
|
Q_INVOKABLE QString avatarUrl(QString id) const;
|
2019-09-01 23:58:26 +03:00
|
|
|
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
2019-09-07 03:01:44 +03:00
|
|
|
Q_INVOKABLE QString escapeEmoji(QString str) const;
|
2019-09-08 16:26:46 +03:00
|
|
|
Q_INVOKABLE void viewRawMessage(QString id) const;
|
2019-09-01 00:44:17 +03:00
|
|
|
|
2019-08-31 23:43:31 +03:00
|
|
|
void addEvents(const mtx::responses::Timeline &events);
|
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
public slots:
|
|
|
|
void fetchHistory();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
// Add old events at the top of the timeline.
|
2019-09-03 00:28:05 +03:00
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
void addBackwardsEvents(const mtx::responses::Messages &msgs);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void oldMessagesRetrieved(const mtx::responses::Messages &res);
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
private:
|
2019-08-31 23:43:31 +03:00
|
|
|
QHash<QString, mtx::events::collections::TimelineEvents> events;
|
2019-08-31 00:20:53 +03:00
|
|
|
std::vector<QString> eventOrder;
|
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
QString room_id_;
|
|
|
|
QString prev_batch_token_;
|
|
|
|
|
2019-09-03 09:23:07 +03:00
|
|
|
bool isInitialSync = true;
|
2019-09-01 00:44:17 +03:00
|
|
|
bool paginationInProgress = false;
|
|
|
|
|
2019-08-31 23:43:31 +03:00
|
|
|
QHash<QString, QColor> userColors;
|
2019-08-31 00:20:53 +03:00
|
|
|
};
|