mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +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
|
||||
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(
|
||||
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())
|
||||
return;
|
||||
|
||||
auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString());
|
||||
auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4")
|
||||
.arg(QString::fromStdString(http::client()->server()))
|
||||
.arg(http::client()->port())
|
||||
.arg(QString::fromStdString(mxc_parts.server))
|
||||
.arg(QString::fromStdString(mxc_parts.media_id));
|
||||
auto urlToOpen = utils::mxcToHttp(
|
||||
url_, QString::fromStdString(http::client()->server()), http::client()->port());
|
||||
|
||||
if (!QDesktopServices::openUrl(urlToOpen))
|
||||
nhlog::ui()->warn("Could not open url: {}", urlToOpen.toStdString());
|
||||
|
|
|
@ -106,12 +106,8 @@ ImageItem::openUrl()
|
|||
if (url_.toString().isEmpty())
|
||||
return;
|
||||
|
||||
auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString());
|
||||
auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4")
|
||||
.arg(QString::fromStdString(http::client()->server()))
|
||||
.arg(http::client()->port())
|
||||
.arg(QString::fromStdString(mxc_parts.server))
|
||||
.arg(QString::fromStdString(mxc_parts.media_id));
|
||||
auto urlToOpen = utils::mxcToHttp(
|
||||
url_, QString::fromStdString(http::client()->server()), http::client()->port());
|
||||
|
||||
if (!QDesktopServices::openUrl(urlToOpen))
|
||||
nhlog::ui()->warn("could not open url: {}", urlToOpen.toStdString());
|
||||
|
|
|
@ -26,15 +26,8 @@
|
|||
void
|
||||
VideoItem::init()
|
||||
{
|
||||
// QList<QString> url_parts = url_.toString().split("mxc://");
|
||||
// if (url_parts.size() != 2) {
|
||||
// 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);
|
||||
url_ = utils::mxcToHttp(
|
||||
url_, QString::fromStdString(http::client()->server()), http::client()->port());
|
||||
}
|
||||
|
||||
VideoItem::VideoItem(const mtx::events::RoomEvent<mtx::events::msg::Video> &event, QWidget *parent)
|
||||
|
|
Loading…
Reference in a new issue