Interprets and emits structured signals based on incoming JSON messages. More...
Header: | #include <MessageBroker> |
Inherits: | QObject |
MessageBroker(QObject *parent = nullptr) | |
ChatMessageModel & | messageModel() |
PrivateMessageModel & | privateMessageModel() |
void | processMessage(const QString &message) |
void | sendChatMessage(const QString &message) |
void | sendPrivateChatMessage(const QString &message) |
void | activeChannelsReceived(const QList<ChannelPayload> &channels) |
void | connectedUsersReceived(QList<UserStatusPayload> users) |
void | outboundMessageReady(const QString &message) |
void | userStatusUpdated(const UserStatusPayload &payload) |
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.
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
handleChatMessage(ChatMessagePayload)
– adds a chat message to the message model.handleBulkChatMessages(QList<ChatMessagePayload>)
– adds multiple chat messages to the message model.handlePrivateChatMessage(PrivateMessagePayload)
– adds a private chat message to the private chat message model.handleBulkPrivateChatMessages(QList<PrivateMessagePayload>)
– adds multiple private chat message to the private chat message model.Private Variables
m_messageModel (ChatMessageModel)
– Stores the chat messagesm_privateMessageModel (PrivateMessageModel)
– Stores the private chat messagesSee also QObject and QQmlEngine.
[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.
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.
Returns the unfiltered model of all private chat messages.
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).