desktop messagelist: decode *<b64> prefix for media message display
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.
This commit is contained in:
1 parent
a0049a4187
commit
4c366f3884
1 file changed
+12
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user