correctly display filename in MimeComponents
(previously it would include the caption text and save with it as filename) Don't append filename to the caption. Relevant spec: https://spec.matrix.org/latest/client-server-api/#mfile
This commit is contained in:
@@ -241,17 +241,19 @@ Qt::TextFormat EventHandler::messageBodyInputFormat(const Quotient::RoomMessageE
|
|||||||
|
|
||||||
QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
|
QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
|
||||||
{
|
{
|
||||||
|
QString body;
|
||||||
|
|
||||||
if (event.hasFileContent()) {
|
if (event.hasFileContent()) {
|
||||||
auto fileCaption = event.content()->fileInfo()->originalName;
|
// if filename is given or body is equal to filename,
|
||||||
if (fileCaption.isEmpty()) {
|
// then body is a caption
|
||||||
fileCaption = event.plainBody();
|
QString fileName = event.content()->fileInfo()->originalName;
|
||||||
} else if (event.content()->fileInfo()->originalName != event.plainBody()) {
|
QString body = event.plainBody();
|
||||||
fileCaption = event.plainBody() + " | "_ls + fileCaption;
|
if (fileName.isEmpty() || fileName == body) {
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
return fileCaption;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString body;
|
|
||||||
if (event.hasTextContent() && event.content()) {
|
if (event.hasTextContent() && event.content()) {
|
||||||
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
||||||
} else {
|
} else {
|
||||||
@@ -660,23 +662,30 @@ QVariantMap EventHandler::getMediaInfoForEvent(const Quotient::RoomEvent *event)
|
|||||||
QString eventId = event->id();
|
QString eventId = event->id();
|
||||||
|
|
||||||
// Get the file info for the event.
|
// Get the file info for the event.
|
||||||
const EventContent::FileInfo *fileInfo;
|
|
||||||
bool isSticker = false;
|
|
||||||
if (event->is<RoomMessageEvent>()) {
|
if (event->is<RoomMessageEvent>()) {
|
||||||
auto roomMessageEvent = eventCast<const RoomMessageEvent>(event);
|
auto roomMessageEvent = eventCast<const RoomMessageEvent>(event);
|
||||||
if (!roomMessageEvent->hasFileContent()) {
|
if (!roomMessageEvent->hasFileContent()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EventContent::FileInfo *fileInfo;
|
||||||
fileInfo = roomMessageEvent->content()->fileInfo();
|
fileInfo = roomMessageEvent->content()->fileInfo();
|
||||||
|
QVariantMap mediaInfo = getMediaInfoFromFileInfo(fileInfo, eventId, false, false);
|
||||||
|
// if filename isn't specifically given, it is in body
|
||||||
|
// https://spec.matrix.org/latest/client-server-api/#mfile
|
||||||
|
mediaInfo["filename"_ls] = (fileInfo->originalName.isEmpty()) ? roomMessageEvent->plainBody() : fileInfo->originalName;
|
||||||
|
|
||||||
|
return mediaInfo;
|
||||||
} else if (event->is<StickerEvent>()) {
|
} else if (event->is<StickerEvent>()) {
|
||||||
|
const EventContent::FileInfo *fileInfo;
|
||||||
|
|
||||||
auto stickerEvent = eventCast<const StickerEvent>(event);
|
auto stickerEvent = eventCast<const StickerEvent>(event);
|
||||||
fileInfo = &stickerEvent->image();
|
fileInfo = &stickerEvent->image();
|
||||||
isSticker = true;
|
|
||||||
|
return getMediaInfoFromFileInfo(fileInfo, eventId, false, true);
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return getMediaInfoFromFileInfo(fileInfo, eventId, false, isSticker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap EventHandler::getMediaInfoFromFileInfo(const EventContent::FileInfo *fileInfo, const QString &eventId, bool isThumbnail, bool isSticker) const
|
QVariantMap EventHandler::getMediaInfoFromFileInfo(const EventContent::FileInfo *fileInfo, const QString &eventId, bool isThumbnail, bool isSticker) const
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ ColumnLayout {
|
|||||||
* - width - The width in pixels of the audio media.
|
* - width - The width in pixels of the audio media.
|
||||||
* - height - The height in pixels of the audio media.
|
* - height - The height in pixels of the audio media.
|
||||||
* - tempInfo - mediaInfo (with the same properties as this except no tempInfo) for a temporary image while the file downloads.
|
* - tempInfo - mediaInfo (with the same properties as this except no tempInfo) for a temporary image while the file downloads.
|
||||||
|
* - filename
|
||||||
*/
|
*/
|
||||||
required property var mediaInfo
|
required property var mediaInfo
|
||||||
|
|
||||||
@@ -155,7 +156,7 @@ ColumnLayout {
|
|||||||
spacing: 0
|
spacing: 0
|
||||||
QQC2.Label {
|
QQC2.Label {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
text: root.display
|
text: root.mediaInfo.filename
|
||||||
wrapMode: Text.Wrap
|
wrapMode: Text.Wrap
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,13 +69,12 @@ DelegateChooser {
|
|||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
roleValue: MessageComponentType.Video
|
roleValue: MessageComponentType.Video
|
||||||
delegate: MimeComponent {
|
delegate: MimeComponent {
|
||||||
required property string display
|
|
||||||
required property var mediaInfo
|
required property var mediaInfo
|
||||||
|
|
||||||
mimeIconSource: mediaInfo.mimeIcon
|
mimeIconSource: mediaInfo.mimeIcon
|
||||||
size: mediaInfo.size
|
size: mediaInfo.size
|
||||||
duration: mediaInfo.duration
|
duration: mediaInfo.duration
|
||||||
label: display
|
label: mediaInfo.filename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +115,7 @@ DelegateChooser {
|
|||||||
mimeIconSource: mediaInfo.mimeIcon
|
mimeIconSource: mediaInfo.mimeIcon
|
||||||
size: mediaInfo.size
|
size: mediaInfo.size
|
||||||
duration: mediaInfo.duration
|
duration: mediaInfo.duration
|
||||||
label: display
|
label: mediaInfo.filename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +127,7 @@ DelegateChooser {
|
|||||||
|
|
||||||
mimeIconSource: mediaInfo.mimeIcon
|
mimeIconSource: mediaInfo.mimeIcon
|
||||||
size: mediaInfo.size
|
size: mediaInfo.size
|
||||||
label: display
|
label: mediaInfo.filename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user