• ClientManager
  • ClientManager Class

    Manages client-side connection, session state, and proxy model wiring. More...

    Header: #include <ClientManager>
    Inherits: QObject

    Properties

    Public Functions

    ClientManager(QObject *parent = nullptr)
    ClientManager(const DiscoveryPayload &payload, const QString &token, QObject *parent)
    QObject *broker()
    QObject *channelModel()
    QList<ChannelMessageProxyModel *> channelProxyList() const
    void connectToServer()
    QList<PrivateMessageProxyModel *> privateMessageProxyList() const
    QObject *proxyForChannel(const QString &channelName) const
    QObject *proxyForPrivateUser(const QString &userId)
    void setAccessToken(const QString &token)
    void setDiscoveryPayload(const DiscoveryPayload &payload)
    ClientUserPayload user()

    Signals

    void activeChannelsReady(const QList<ChannelMessageProxyModel *> &proxies)
    void activeChannelsReceived(const QList<ChannelPayload> &channels)
    void connected()
    void connectionError(const QString &message)
    void disconnected()
    void privateMessageProxyListChanged(const QList<PrivateMessageProxyModel *> &proxies)

    Detailed Description

    Overview

    ClientManager sets up the WebSocket connection, manages user identity via JWT, routes messages through the MessageBroker, and provides access to chat models and filtered proxies for QML.

    Internal Members

    The following private member variables and utility functions are used internally by ClientManager and are referenced here for developer clarity. Full documentation is available in the source file:

    Private Variables

    • m_websocketManager (WebsocketManager) – Maintains the active WebSocket connection and emits raw messages.
    • m_messageBroker (MessageBroker) – Parses and dispatches incoming/outgoing structured chat messages.
    • m_user (ClientUserPayload) – Holds decoded user information from the JWT token.
    • m_accessToken (QString) – The current JWT access token for this session.
    • m_payload (DiscoveryPayload) – Connection metadata such as server URLs.
    • m_channelProxies (QHash<QString, ChannelProxyModel*>) – Proxies for filtering public chat messages by channel.
    • m_privateChatProxies (QHash<QString, PrivateMessageProxyModel*>) – Proxies for filtering private messages by user.
    • m_channelModel (ChannelModel) – Maintains the list of all known channels.

    Internal Functions

    • parseJwtClaims(QString) – Parses a JWT token and returns its claims as a QVariantMap.
    • logJwtClaims(QString) – Logs the contents of a JWT to the debug console.
    • handleActiveChannels(QList<ChannelPayload>) – Initializes proxies and populates the channel model from server data.

    Property Documentation

    [read-only] broker : QObject* const

    Returns the internal MessageBroker responsible for routing and parsing messages.

    Access functions:

    QObject *broker()

    [read-only] channelModel : QObject* const

    Returns the ChannelModel instance representing all known channels.

    Access functions:

    QObject *channelModel()

    [read-only] channelProxyList : QList<ChannelMessageProxyModel*> const

    Returns a locale-aware sorted list of all available channel proxies.

    Access functions:

    QList<ChannelMessageProxyModel *> channelProxyList() const

    Notifier signal:

    void activeChannelsReady(const QList<ChannelMessageProxyModel *> &proxies)

    [read-only] privateMessageProxyList : QList<PrivateMessageProxyModel*> const

    Returns all private chat proxies that have been created.

    Access functions:

    QList<PrivateMessageProxyModel *> privateMessageProxyList() const

    Notifier signal:

    void privateMessageProxyListChanged(const QList<PrivateMessageProxyModel *> &proxies)

    [read-only] user : const ClientUserPayload

    Returns parsed user information extracted from the access token.

    Access functions:

    ClientUserPayload user()

    Member Function Documentation

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

    Constructs a ClientManager instance with no token or payload.

    This is the default constructor for QML and requires setDiscoveryPayload(payload) and setAccessToken(token) to be called before connectToServer().

    parent is the optional parent object.

    ClientManager::ClientManager(const DiscoveryPayload &payload, const QString &token, QObject *parent)

    Constructs a ClientManager with an access token and discovery payload.

    payload is used to configure connection endpoints. token is a JWT used to derive the current user identity. parent is the optional QObject parent.

    [signal] void ClientManager::activeChannelsReceived(const QList<ChannelPayload> &channels)

    This signal is emitted when the list of active channels is received from the server.

    The channels list contains metadata about each available channel. This data is used to populate models and proxies in the chat UI.

    [invokable] void ClientManager::connectToServer()

    Connects to the WebSocket server using the current discovery payload and access token.

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

    [signal] void ClientManager::connected()

    This signal is emitted when a connection to the chat server is successfully established.

    This indicates that the WebSocket handshake and authentication flow completed successfully.

    [signal] void ClientManager::connectionError(const QString &message)

    This signal is emitted when an error occurs during connection.

    message contains the error description, suitable for display in the UI.

    [signal] void ClientManager::disconnected()

    This signal is emitted when the chat server connection is closed.

    This could be due to a user action, a dropped network connection, or a server-initiated disconnect.

    [signal] void ClientManager::privateMessageProxyListChanged(const QList<PrivateMessageProxyModel *> &proxies)

    This signal is emitted when the list of private chat proxies changes.

    This occurs when a new proxy for a private conversation is created. proxies is the full updated list of proxies.

    Note: Notifier signal for property privateMessageProxyList.

    [invokable] QObject *ClientManager::proxyForChannel(const QString &channelName) const

    Returns a proxy model that filters chat messages by public channel.

    The proxy filters the global chat message model to only include messages associated with the given channelName.

    Returns nullptr if no proxy has been created yet for the channel.

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

    [invokable] QObject *ClientManager::proxyForPrivateUser(const QString &userId)

    Returns a proxy model that filters private chat messages exchanged with a specific user.

    The proxy filters the full private chat message model to only include messages between the current user and the specified userId. If a proxy does not already exist, it is created and configured automatically.

    Returns a pointer to the proxy model for the given user.

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

    [invokable] void ClientManager::setAccessToken(const QString &token)

    Updates the internal access token and logs decoded claims.

    token is the new JWT to use for authentication and user identification.

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

    [invokable] void ClientManager::setDiscoveryPayload(const DiscoveryPayload &payload)

    Updates the internal discovery configuration.

    payload provides updated server endpoint information.

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