2026-04-17 15:43:49 +02:00
|
|
|
#ifndef MESSAGE_LIST_MODEL_H
|
|
|
|
|
#define MESSAGE_LIST_MODEL_H
|
|
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
|
|
struct MessageItem {
|
|
|
|
|
QString sender;
|
|
|
|
|
QString content;
|
|
|
|
|
QDateTime timestamp;
|
|
|
|
|
bool isMe;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MessageListModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum Roles {
|
|
|
|
|
SenderRole = Qt::UserRole + 1,
|
|
|
|
|
ContentRole,
|
|
|
|
|
TimestampRole,
|
2026-07-17 09:18:54 +02:00
|
|
|
IsMeRole,
|
|
|
|
|
// Neighbour-derived, computed from the chronologically previous (older)
|
|
|
|
|
// message at index+1 (the model is newest-first). Used to group a run of
|
|
|
|
|
// messages and to break the run with a day heading.
|
|
|
|
|
SameSenderAsPreviousRole,
|
|
|
|
|
ShowDaySeparatorRole,
|
2026-07-29 22:10:19 +02:00
|
|
|
DayLabelRole,
|
|
|
|
|
// Clock time for the bubble, formatted here so every timestamp in the UI
|
|
|
|
|
// shares one locale and shape.
|
|
|
|
|
TimeDisplayRole,
|
|
|
|
|
// Avatar identity for the sender, on the same rule as the roster's, so
|
|
|
|
|
// a member wears one colour in the thread and in the member list.
|
|
|
|
|
AvatarInitialsRole,
|
|
|
|
|
AvatarRampRole
|
2026-04-17 15:43:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
explicit MessageListModel(QObject* parent = nullptr);
|
|
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
|
|
|
QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
|
|
|
|
void addMessage(const QString& sender, const QString& content,
|
|
|
|
|
const QDateTime& timestamp, bool isMe);
|
|
|
|
|
void addMessages(QVector<MessageItem> items);
|
2026-07-15 08:16:41 +02:00
|
|
|
void setMessages(QVector<MessageItem> items);
|
2026-04-17 15:43:49 +02:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
|
|
private:
|
2026-07-17 09:18:54 +02:00
|
|
|
// "Today" / "Yesterday" / short date for a day-separator heading.
|
|
|
|
|
QString dayLabel(const QDateTime& timestamp) const;
|
|
|
|
|
|
2026-04-17 15:43:49 +02:00
|
|
|
QVector<MessageItem> m_items;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|