mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Use the http link for video messages
Add method to convert matrix content URIs to http links
This commit is contained in:
parent
33490eddab
commit
a9f02128a2
5 changed files with 22 additions and 21 deletions
|
@ -187,4 +187,8 @@ levenshtein_distance(const std::string &s1, const std::string &s2);
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
scaleImageToPixmap(const QImage &img, int size);
|
scaleImageToPixmap(const QImage &img, int size);
|
||||||
|
|
||||||
|
//! Convert a Content Matrix URI to an HTTP link.
|
||||||
|
QString
|
||||||
|
mxcToHttp(const QUrl &url, const QString &server, int port);
|
||||||
}
|
}
|
||||||
|
|
12
src/Utils.cc
12
src/Utils.cc
|
@ -174,3 +174,15 @@ utils::scaleImageToPixmap(const QImage &img, int size)
|
||||||
return QPixmap::fromImage(
|
return QPixmap::fromImage(
|
||||||
img.scaled(sz, sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
img.scaled(sz, sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
utils::mxcToHttp(const QUrl &url, const QString &server, int port)
|
||||||
|
{
|
||||||
|
auto mxcParts = mtx::client::utils::parse_mxc_url(url.toString().toStdString());
|
||||||
|
|
||||||
|
return QString("https://%1:%2/_matrix/media/r0/download/%3/%4")
|
||||||
|
.arg(server)
|
||||||
|
.arg(port)
|
||||||
|
.arg(QString::fromStdString(mxcParts.server))
|
||||||
|
.arg(QString::fromStdString(mxcParts.media_id));
|
||||||
|
}
|
||||||
|
|
|
@ -81,12 +81,8 @@ FileItem::openUrl()
|
||||||
if (url_.toString().isEmpty())
|
if (url_.toString().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString());
|
auto urlToOpen = utils::mxcToHttp(
|
||||||
auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4")
|
url_, QString::fromStdString(http::client()->server()), http::client()->port());
|
||||||
.arg(QString::fromStdString(http::client()->server()))
|
|
||||||
.arg(http::client()->port())
|
|
||||||
.arg(QString::fromStdString(mxc_parts.server))
|
|
||||||
.arg(QString::fromStdString(mxc_parts.media_id));
|
|
||||||
|
|
||||||
if (!QDesktopServices::openUrl(urlToOpen))
|
if (!QDesktopServices::openUrl(urlToOpen))
|
||||||
nhlog::ui()->warn("Could not open url: {}", urlToOpen.toStdString());
|
nhlog::ui()->warn("Could not open url: {}", urlToOpen.toStdString());
|
||||||
|
|
|
@ -106,12 +106,8 @@ ImageItem::openUrl()
|
||||||
if (url_.toString().isEmpty())
|
if (url_.toString().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString());
|
auto urlToOpen = utils::mxcToHttp(
|
||||||
auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4")
|
url_, QString::fromStdString(http::client()->server()), http::client()->port());
|
||||||
.arg(QString::fromStdString(http::client()->server()))
|
|
||||||
.arg(http::client()->port())
|
|
||||||
.arg(QString::fromStdString(mxc_parts.server))
|
|
||||||
.arg(QString::fromStdString(mxc_parts.media_id));
|
|
||||||
|
|
||||||
if (!QDesktopServices::openUrl(urlToOpen))
|
if (!QDesktopServices::openUrl(urlToOpen))
|
||||||
nhlog::ui()->warn("could not open url: {}", urlToOpen.toStdString());
|
nhlog::ui()->warn("could not open url: {}", urlToOpen.toStdString());
|
||||||
|
|
|
@ -26,15 +26,8 @@
|
||||||
void
|
void
|
||||||
VideoItem::init()
|
VideoItem::init()
|
||||||
{
|
{
|
||||||
// QList<QString> url_parts = url_.toString().split("mxc://");
|
url_ = utils::mxcToHttp(
|
||||||
// if (url_parts.size() != 2) {
|
url_, QString::fromStdString(http::client()->server()), http::client()->port());
|
||||||
// qDebug() << "Invalid format for image" << url_.toString();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// QString media_params = url_parts[1];
|
|
||||||
// url_ = QString("%1/_matrix/media/r0/download/%2")
|
|
||||||
// .arg(http::client()->getHomeServer().toString(), media_params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoItem::VideoItem(const mtx::events::RoomEvent<mtx::events::msg::Video> &event, QWidget *parent)
|
VideoItem::VideoItem(const mtx::events::RoomEvent<mtx::events::msg::Video> &event, QWidget *parent)
|
||||||
|
|
Loading…
Reference in a new issue