1#ifndef MESSAGE_HANDLER_H
2#define MESSAGE_HANDLER_H
35 return QUuid::createUuid().toString(QUuid::WithoutBraces);
48 const QJsonObject ¶ms = QJsonObject());
72 static QJsonObject
ParseMessage(
const QString &message,
bool *ok =
nullptr);
80 return message_object[
"type"].toString();
89 return message_object[
"content"].toString();
98 return message_object[
"frequency"].toString();
107 return message_object[
"senderId"].toString();
116 return message_object[
"messageId"].toString();
126 static QJsonObject
CreateAuthRequest(
const QString &frequency,
const QString &password,
const QString &client_id);
137 const QString &password,
const QString &host_id);
void ClearProcessedMessages()
Clears the internal cache of processed message IDs.
Definition message_handler.h:150
static QString GenerateMessageId()
Generates a unique message identifier using UUID.
Definition message_handler.h:34
MessageHandler(const MessageHandler &)=delete
Deleted copy constructor to prevent copying.
~MessageHandler() override=default
Private destructor.
bool IsMessageProcessed(const QString &message_id) const
Checks if a message with the given ID has already been processed.
Definition message_handler.h:55
static QString GetMessageType(const QJsonObject &message_object)
Extracts the message type string from a parsed message object.
Definition message_handler.h:79
static QString GetMessageFrequency(const QJsonObject &message_object)
Extracts the frequency string from a parsed message object.
Definition message_handler.h:97
static QJsonObject CreateLeaveRequest(const QString &frequency, bool is_host)
Creates a JSON object representing a request to leave or close a frequency.
Definition message_handler.cpp:72
static QJsonObject CreateAuthRequest(const QString &frequency, const QString &password, const QString &client_id)
Creates a JSON object representing an authentication request.
Definition message_handler.cpp:51
MessageHandler & operator=(const MessageHandler &)=delete
Deleted assignment operator to prevent assignment.
static QJsonObject ParseMessage(const QString &message, bool *ok=nullptr)
Parses a JSON string message into a QJsonObject.
Definition message_handler.cpp:39
QSet< QString > processed_message_ids_
Set storing the IDs of messages that have already been processed to prevent duplicates.
Definition message_handler.h:178
static bool SendSystemCommand(QWebSocket *socket, const QString &command, const QJsonObject ¶ms=QJsonObject())
Sends a JSON-formatted system command over the specified WebSocket. Constructs a JSON object with the...
Definition message_handler.cpp:6
MessageHandler(QObject *parent=nullptr)
Private constructor to enforce the singleton pattern.
Definition message_handler.h:159
static QString GetMessageId(const QJsonObject &message_object)
Extracts the message ID string from a parsed message object.
Definition message_handler.h:115
static constexpr int kMaxCachedMessageIds
Maximum number of message IDs to keep in the processed cache before removing older ones.
Definition message_handler.h:180
void MarkMessageAsProcessed(const QString &message_id)
Marks a message ID as processed by adding it to the internal set. Also manages the size of the proces...
Definition message_handler.cpp:25
static QString GetMessageSenderId(const QJsonObject &message_object)
Extracts the sender ID string from a parsed message object.
Definition message_handler.h:106
static QString GetMessageContent(const QJsonObject &message_object)
Extracts the message content string from a parsed message object.
Definition message_handler.h:88
static MessageHandler * GetInstance()
Gets the singleton instance of the MessageHandler.
Definition message_handler.h:25
static QJsonObject CreateRegisterRequest(const QString &frequency, bool is_password_protected, const QString &password, const QString &host_id)
Creates a JSON object representing a request to register a new frequency.
Definition message_handler.cpp:61