• PrivateMessageModel
  • PrivateMessageModel Class

    Stores all private chat messages and provides the source for filtering. More...

    Header: #include <PrivateMessageModel>
    Inherits: QAbstractListModel

    Public Functions

    PrivateMessageModel(QObject *parent = nullptr)
    void appendMessage(const PrivateMessagePayload &msg)
    void clear()
    const QList<PrivateMessagePayload> &messages() const

    Reimplemented Public Functions

    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
    virtual QHash<int, QByteArray> roleNames() const override
    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override

    Detailed Description

    Overview

    PrivateMessageModel is a QAbstractListModel that holds a list of PrivateMessagePayload objects, representing one-on-one direct messages between users. It is not exposed directly to QML; instead, it is consumed internally by PrivateMessageProxyModel, which filters messages by user and is exposed to the UI through the ClientManager.

    The model supports prepending new messages, clearing its contents, and retrieving the full internal list for use by message controllers or proxies.

    Internal Members

    Private Variables

    • m_messages (QList<PrivateMessagePayload>) — Stores private messages in reverse-chronological order

    See also PrivateMessageProxyModel.

    Member Function Documentation

    [explicit] PrivateMessageModel::PrivateMessageModel(QObject *parent = nullptr)

    Constructs an empty private message model.

    parent is the optional QObject parent.

    [invokable] void PrivateMessageModel::appendMessage(const PrivateMessagePayload &msg)

    Prepends a private message msg to the model.

    New messages appear at the top of the list.

    Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

    void PrivateMessageModel::clear()

    Clears all private messages from the model.

    [override virtual] QVariant PrivateMessageModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const

    Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.

    Returns the data for the message at index for the given role.

    This includes fields such as sender, recipient, and timestamp. Returns an invalid QVariant if the index is out of bounds.

    const QList<PrivateMessagePayload> &PrivateMessageModel::messages() const

    Returns a const reference to the internal message list.

    [override virtual] QHash<int, QByteArray> PrivateMessageModel::roleNames() const

    Reimplements: QAbstractItemModel::roleNames() const.

    Returns a mapping from role IDs to QML role names.

    This allows QML views to bind to message properties like username, message, etc.

    [override virtual] int PrivateMessageModel::rowCount(const QModelIndex &parent = QModelIndex()) const

    Reimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.

    Returns the number of messages in the model.

    parent is unused in this flat list implementation.