ChatMessageModel

List model holding finalized chat messages for display in a QListView.

Inherits QAbstractListModel
Group libwidgets

Declared in src/libs/libwidgets/widgets/chat/ChatMessageModel.hpp.

Detailed description

Stores only finalized (non-streaming) messages. Each row exposes its role, timestamp, content blocks, and metadata through custom data roles. Streaming content is handled externally by ChatStreamWidget.

A window of rows

A session can hold one million events (trove-parts §TPN-10). The model shows a window of them and loads older rows on demand, with Qt's own mechanism. openHistory() makes the newest windowRows() messages rows and holds the rest. fetchMore() inserts the next older window at row 0, from the held messages and then from an optional setOlderSource() source. canFetchMore() tells a view that older rows wait, unless the fetchTrigger() is FetchTrigger::Owner: a Qt view fetches when its last row shows, and a chat keeps its older rows above.

New messages append at the bottom. appendMessages() appends a batch with one beginInsertRows()/endInsertRows() pair, so a view lays the batch out once.

Every message gets a key when it is stored, available through KeyRole. A key stays with its message when rows move, and the model never gives it to another message. ChatBubbleDelegate keys its caches on it, so a load at the top does not invalidate them.

A row number is a position in the window. A fetchMore() moves every row down by the number of rows that it loads. A caller that keeps a row number across a fetch must add that number, or keep the key instead.

See also ChatStreamWidget, ChatBubbleDelegate, ChatMessage.

In this section