From 4c366f3884708740e30eaae95027de4a1498cba1 Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 3 Aug 2026 23:17:28 +0300 Subject: [PATCH] desktop messagelist: decode * prefix for media message display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setVoiceMessageRoles now checks for '*' marker, translates URL-safe base64 (-_ → +/) and decodes to restore original display data. Fixes attachment filenames and voice waveform for new messages. --- tools/chatgui/src/messagelist.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/chatgui/src/messagelist.cpp b/tools/chatgui/src/messagelist.cpp index 2d808832..2a5706d0 100644 --- a/tools/chatgui/src/messagelist.cpp +++ b/tools/chatgui/src/messagelist.cpp @@ -93,6 +93,16 @@ static QString contentTypeFromJson(const QByteArray& data) { static void setVoiceMessageRoles(QStandardItem* item, const QByteArray& data, const QString& contentType, const QString& mediaDirBase, const QString& channelId, const QByteArray& localAttrs) { + QByteArray body = data; + if (body.startsWith('*')) { + int pipePos = body.indexOf('|'); + if (pipePos > 1) { + QByteArray b64 = body.mid(1, pipePos - 1); + b64.replace('-', '+'); + b64.replace('_', '/'); + body = QByteArray::fromBase64(b64) + body.mid(pipePos); + } + } QString ct = contentType; if (ct.isEmpty()) ct = contentTypeFromJson(data); if (ct.isEmpty()) ct = "text/plain"; @@ -100,7 +110,7 @@ static void setVoiceMessageRoles(QStandardItem* item, const QByteArray& data, item->setData(channelId, MsgChannelIdRole); if (ct == "audio/opus") { - QString raw = QString::fromUtf8(data); + QString raw = QString::fromUtf8(body); if (raw.startsWith('{')) return; /* unified format: wf={base64};dur={ms};|{file_size}|{block_size}|{num_blocks}|{sigs} */ @@ -161,7 +171,7 @@ static void setVoiceMessageRoles(QStandardItem* item, const QByteArray& data, } } if (ct == "application/octet-stream") { - QString raw = QString::fromUtf8(data); + QString raw = QString::fromUtf8(body); int pipePos = raw.indexOf('|'); QString fname = (pipePos > 0) ? raw.left(pipePos) : raw; item->setData(fname, MsgFileDisplayNameRole);