fix code preview components
- fix them vanishing after "opening" a file (they get downloaded to /tmp/ without extension, which caused them to lose preview) - make all text/plain mimetype files preview - don't show them in Replies (in consistency with media components)
This commit is contained in:
@@ -437,27 +437,35 @@ QList<MessageComponent> MessageContentModel::componentsForType(MessageComponentT
|
|||||||
QList<MessageComponent> components;
|
QList<MessageComponent> components;
|
||||||
components += MessageComponent{MessageComponentType::File, QString(), {}};
|
components += MessageComponent{MessageComponentType::File, QString(), {}};
|
||||||
const auto event = eventCast<const Quotient::RoomMessageEvent>(m_event);
|
const auto event = eventCast<const Quotient::RoomMessageEvent>(m_event);
|
||||||
auto body = EventHandler::rawMessageBody(*event);
|
|
||||||
components += TextHandler().textComponents(body, EventHandler::messageBodyInputFormat(*event), m_room, event, event->isReplaced());
|
|
||||||
|
|
||||||
if (m_emptyItinerary) {
|
if (m_emptyItinerary) {
|
||||||
auto fileTransferInfo = fileInfo();
|
if (!m_isReply) {
|
||||||
|
auto fileTransferInfo = fileInfo();
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
KSyntaxHighlighting::Repository repository;
|
Q_ASSERT(event->content() != nullptr && event->content()->fileInfo() != nullptr);
|
||||||
const auto definitionForFile = repository.definitionForFileName(fileTransferInfo.localPath.toString());
|
const QMimeType mimeType = event->content()->fileInfo()->mimeType;
|
||||||
if (definitionForFile.isValid() || QFileInfo(fileTransferInfo.localPath.path()).suffix() == QStringLiteral("txt")) {
|
if (mimeType.name() == QStringLiteral("text/plain") || mimeType.parentMimeTypes().contains(QStringLiteral("text/plain"))) {
|
||||||
QFile file(fileTransferInfo.localPath.path());
|
KSyntaxHighlighting::Repository repository;
|
||||||
file.open(QIODevice::ReadOnly);
|
KSyntaxHighlighting::Definition definitionForFile = repository.definitionForFileName(fileTransferInfo.localPath.path());
|
||||||
components += MessageComponent{MessageComponentType::Code,
|
if (!definitionForFile.isValid()) {
|
||||||
QString::fromStdString(file.readAll().toStdString()),
|
definitionForFile = repository.definitionForFileName(event->content()->fileInfo()->originalName);
|
||||||
{{QStringLiteral("class"), definitionForFile.name()}}};
|
}
|
||||||
}
|
if (!definitionForFile.isValid()) {
|
||||||
|
definitionForFile = repository.definitionForMimeType(mimeType.name());
|
||||||
|
}
|
||||||
|
QFile file(fileTransferInfo.localPath.path());
|
||||||
|
file.open(QIODevice::ReadOnly);
|
||||||
|
components += MessageComponent{MessageComponentType::Code,
|
||||||
|
QString::fromStdString(file.readAll().toStdString()),
|
||||||
|
{{QStringLiteral("class"), definitionForFile.name()}}};
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (FileType::instance().fileHasImage(fileTransferInfo.localPath)) {
|
if (FileType::instance().fileHasImage(fileTransferInfo.localPath)) {
|
||||||
QImageReader reader(fileTransferInfo.localPath.path());
|
QImageReader reader(fileTransferInfo.localPath.path());
|
||||||
components += MessageComponent{MessageComponentType::Pdf, QString(), {{QStringLiteral("size"), reader.size()}}};
|
components += MessageComponent{MessageComponentType::Pdf, QString(), {{QStringLiteral("size"), reader.size()}}};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (m_itineraryModel != nullptr) {
|
} else if (m_itineraryModel != nullptr) {
|
||||||
components += MessageComponent{MessageComponentType::Itinerary, QString(), {}};
|
components += MessageComponent{MessageComponentType::Itinerary, QString(), {}};
|
||||||
@@ -467,6 +475,8 @@ QList<MessageComponent> MessageContentModel::componentsForType(MessageComponentT
|
|||||||
} else {
|
} else {
|
||||||
updateItineraryModel();
|
updateItineraryModel();
|
||||||
}
|
}
|
||||||
|
auto body = EventHandler::rawMessageBody(*event);
|
||||||
|
components += TextHandler().textComponents(body, EventHandler::messageBodyInputFormat(*event), m_room, event, event->isReplaced());
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
case MessageComponentType::Image:
|
case MessageComponentType::Image:
|
||||||
|
|||||||
Reference in New Issue
Block a user