Verified Commit f6e523f4 authored by Linus Jahn's avatar Linus Jahn 🍙

media-sharing: Recognize specific media type instead

parent 03a6b6ed
Pipeline #230 passed with stage
in 4 minutes and 3 seconds
......@@ -33,6 +33,7 @@
// C++
#include <iostream>
// Qt 5
#include <QMimeType>
#include <QDateTime>
#include <QDebug>
#include <QSqlError>
......@@ -88,6 +89,24 @@ QHash<int, QByteArray> MessageModel::roleNames() const
return roles;
}
MessageType MessageModel::messageTypeFromMimeType(const QMimeType &type)
{
if (type.inherits("image/jpeg") || type.inherits("image/png") ||
type.inherits("image/gif"))
return MessageType::MessageImage;
else if (type.inherits("audio/flac") || type.inherits("audio/mp4") ||
type.inherits("audio/ogg") || type.inherits("audio/wav") ||
type.inherits("audio/mpeg") || type.inherits("audio/webm"))
return MessageType::MessageAudio;
else if (type.inherits("video/mpeg") || type.inherits("video/x-msvideo") ||
type.inherits("video/quicktime") || type.inherits("video/mp4") ||
type.inherits("video/x-matroska"))
return MessageType::MessageVideo;
else if (type.inherits("text/plain"))
return MessageType::MessageDocument;
return MessageType::MessageFile;
}
void MessageModel::setMessageAsSent(const QString msgId)
{
for (int i = 0; i < rowCount(); ++i) {
......
......@@ -36,6 +36,8 @@
using namespace Enums;
class QMimeType;
class MessageModel : public QSqlTableModel
{
Q_OBJECT
......@@ -70,6 +72,8 @@ public:
QString mediaHashes;
};
static MessageType messageTypeFromMimeType(const QMimeType &);
signals:
/**
* Emit when the data has been changed
......
......@@ -80,16 +80,18 @@ void UploadManager::sendFile(QString jid, QString fileUrl, QString body)
QFileInfo file(QUrl(fileUrl).toLocalFile());
int id = manager.uploadFile(file);
QMimeType mimeType = QMimeDatabase().mimeTypeForFile(file);
MessageModel::Message *msg = new MessageModel::Message();
msg->author = client->configuration().jidBare();
msg->recipient = jid;
msg->id = QXmppUtils::generateStanzaHash(48);
msg->sentByMe = true;
msg->message = body;
msg->type = MessageType::MessageFile;
msg->type = MessageModel::messageTypeFromMimeType(mimeType);
msg->timestamp = QDateTime::currentDateTime().toUTC().toString(Qt::ISODate);
msg->mediaSize = file.size();
msg->mediaContentType = QMimeDatabase().mimeTypeForFile(file).name();
msg->mediaContentType = mimeType.name();
msg->mediaLastModified = file.lastModified().currentMSecsSinceEpoch();
msg->mediaLocation = file.absolutePath();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment