• MessageBroker
  • MessageBroker Class

    Interprets and emits structured signals based on incoming JSON messages. More...

    Header: #include <MessageBroker>
    Inherits: QObject

    Public Functions

    MessageBroker(QObject *parent = nullptr)
    ChatMessageModel &messageModel()
    PrivateMessageModel &privateMessageModel()
    void processMessage(const QString &message)

    Public Slots

    void sendChatMessage(const QString &message)
    void sendPrivateChatMessage(const QString &message)

    Signals

    void activeChannelsReceived(const QList<ChannelPayload> &channels)
    void connectedUsersReceived(QList<UserStatusPayload> users)
    void outboundMessageReady(const QString &message)
    void userStatusUpdated(const UserStatusPayload &payload)

    Detailed Description

    The MessageBroker class handles inbound and outbound message processing for the chat system. It parses raw JSON messages from the server and emits strongly typed Qt signals which QML or C++ components can bind to.

    Internal Members

    Internal Members

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

    Private Functions

    Private Variables

    See also QObject and QQmlEngine.

    Member Function Documentation

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

    Constructs a new MessageBroker instance.

    parent is the optional parent QObject.

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

    This signal is emitted when the server sends a list of active public channels.

    The channels list contains metadata for each public channel, used to populate models and configure proxies.

    [signal] void MessageBroker::connectedUsersReceived(QList<UserStatusPayload> users)

    This signal is emitted when a list of currently connected users is received.

    users contains the user IDs and connection states at the time of receipt.

    ChatMessageModel &MessageBroker::messageModel()

    Returns the unfiltered model of all public chat messages.

    [signal] void MessageBroker::outboundMessageReady(const QString &message)

    This signal is emitted when a validated and serialized message is ready to be sent to the server.

    The message is a compact JSON string to be passed directly to the WebSocket.

    PrivateMessageModel &MessageBroker::privateMessageModel()

    Returns the unfiltered model of all private chat messages.

    void MessageBroker::processMessage(const QString &message)

    Parses and dispatches a raw JSON message from the server.

    The message type is used to determine the appropriate internal handler or signal.

    message is the JSON string received from the WebSocket.

    [slot] void MessageBroker::sendChatMessage(const QString &message)

    Validates and serializes a public chat message.

    Emits outboundMessageReady if the payload is valid.

    message is a JSON string with keys "channel" and "message".

    [slot] void MessageBroker::sendPrivateChatMessage(const QString &message)

    Validates and serializes a private chat message.

    Emits outboundMessageReady if the payload is valid.

    message is a JSON string with keys "recipientId" and "message".

    [signal] void MessageBroker::userStatusUpdated(const UserStatusPayload &payload)

    This signal is emitted when a single user's connection status changes.

    The payload includes the user’s ID, name, and updated connection state (online/offline).