Link Previewer MXC Links
- Update link preview to get valid mxc links. - Get the connection from a room.
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
|
||||
#include "linkpreviewer.h"
|
||||
|
||||
#include "controller.h"
|
||||
|
||||
#include <connection.h>
|
||||
#include <csapi/content-repo.h>
|
||||
|
||||
#include "neochatroom.h"
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
LinkPreviewer::LinkPreviewer(QObject *parent)
|
||||
@@ -16,6 +16,20 @@ LinkPreviewer::LinkPreviewer(QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
NeoChatRoom *LinkPreviewer::room() const
|
||||
{
|
||||
return m_currentRoom;
|
||||
}
|
||||
|
||||
void LinkPreviewer::setRoom(NeoChatRoom *room)
|
||||
{
|
||||
if (room == m_currentRoom) {
|
||||
return;
|
||||
}
|
||||
m_currentRoom = room;
|
||||
Q_EMIT roomChanged();
|
||||
}
|
||||
|
||||
bool LinkPreviewer::loaded() const
|
||||
{
|
||||
return m_loaded;
|
||||
@@ -31,7 +45,7 @@ QString LinkPreviewer::description() const
|
||||
return m_description;
|
||||
}
|
||||
|
||||
QString LinkPreviewer::imageSource() const
|
||||
QUrl LinkPreviewer::imageSource() const
|
||||
{
|
||||
return m_imageSource;
|
||||
}
|
||||
@@ -50,15 +64,28 @@ void LinkPreviewer::setUrl(QUrl url)
|
||||
m_url = url;
|
||||
Q_EMIT urlChanged();
|
||||
|
||||
auto conn = Controller::instance().activeConnection();
|
||||
|
||||
auto conn = m_currentRoom->connection();
|
||||
GetUrlPreviewJob *job = conn->callApi<GetUrlPreviewJob>(m_url.toString());
|
||||
|
||||
connect(job, &BaseJob::success, this, [this, job]() {
|
||||
connect(job, &BaseJob::success, this, [this, job, conn]() {
|
||||
const auto json = job->jsonData();
|
||||
m_title = json["og:title"].toString().trimmed();
|
||||
m_description = json["og:description"].toString().trimmed().replace("\n", " ");
|
||||
m_imageSource = json["og:image"].toString();
|
||||
|
||||
auto imageUrl = QUrl(json["og:image"].toString());
|
||||
if (imageUrl.isValid() && imageUrl.scheme() == QStringLiteral("mxc")) {
|
||||
#ifdef QUOTIENT_07
|
||||
m_imageSource = conn->makeMediaUrl(imageUrl);
|
||||
#else
|
||||
QUrlQuery q(imageUrl.query());
|
||||
q.addQueryItem(QStringLiteral("user_id"), conn->userId());
|
||||
imageUrl.setQuery(q);
|
||||
m_imageSource = imageUrl;
|
||||
#endif
|
||||
} else {
|
||||
m_imageSource = QUrl();
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT descriptionChanged();
|
||||
|
||||
Reference in New Issue
Block a user