Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
MessageFormatter Class Reference

Provides static utility functions for formatting messages into HTML strings. More...

#include <message_formatter.h>

Collaboration diagram for MessageFormatter:

Static Public Member Functions

static QString FormatFileSize (qint64 size_in_bytes)
 Formats a file size in bytes into a human-readable string (e.g., "1.2 MB").
 
static QString FormatMessage (const QJsonObject &message_object, const QString &frequency)
 Formats a message represented by a JSON object into an HTML string.
 
static QString FormatSystemMessage (const QString &message)
 Formats a simple string as a system message.
 

Detailed Description

Provides static utility functions for formatting messages into HTML strings.

This class handles the conversion of message data (from JSON objects or simple strings) into HTML suitable for display in the chat interface. It manages timestamps, sender identification, text formatting, and attachment handling (using placeholders).

Member Function Documentation

◆ FormatFileSize()

QString MessageFormatter::FormatFileSize ( qint64 size_in_bytes)
static

Formats a file size in bytes into a human-readable string (e.g., "1.2 MB").

Converts the byte count into KB, MB, or GB with appropriate precision.

Parameters
size_in_bytesThe file size in bytes.
Returns
A QString representing the formatted file size.

◆ FormatMessage()

QString MessageFormatter::FormatMessage ( const QJsonObject & message_object,
const QString & frequency )
static

Formats a message represented by a JSON object into an HTML string.

Extracts sender, content, timestamp, and attachment information from the JSON. Determines if the message is from the current user ("You"). For attachments, it stores the base64 data (if present and not already stored) in the AttachmentDataStore and generates an HTML placeholder div element. This placeholder contains data-* attributes (like data-attachment-id, data-mime-type, data-filename) that reference the stored data, keeping the HTML itself lightweight. For text messages, it formats the content with appropriate sender info and timestamp.

Parameters
message_objectThe JSON object containing the message details. Expected keys include "content", "sender"/"senderId", "timestamp", "isSelf", "hasAttachment", "attachmentType", "attachmentName", "attachmentMimeType", "attachmentData".
frequencyThe frequency identifier, used to look up sender names via WavelengthRegistry if only senderId is present.
Returns
An HTML formatted QString representing the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FormatSystemMessage()

QString MessageFormatter::FormatSystemMessage ( const QString & message)
static

Formats a simple string as a system message.

Prepends the current timestamp and applies specific styling (yellow color) to the message text.

Parameters
messageThe text content of the system message.
Returns
An HTML formatted QString representing the system message.
Here is the caller graph for this function:

The documentation for this class was generated from the following files: