Skip to content

Commit

Permalink
Open links from link attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
curoviyxru committed Sep 13, 2023
1 parent b52df58 commit 904e27b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion messagesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ QHash<int, QByteArray> MessagesModel::roleNames() const
roles[MediaDownloadableRole] = "mediaDownloadable";
roles[MessageIdRole] = "messageId";
roles[ForwardedFromRole] = "forwardedFrom";
roles[MediaUrlRole] = "mediaUrl";

return roles;
}
Expand Down Expand Up @@ -446,6 +447,7 @@ TgObject MessagesModel::createRow(TgObject message, TgObject sender, TgList user
row["hasMedia"] = GETID(media) != 0 ? 1 : 0;
row["mediaDownloadable"] = false;

row["mediaUrl"] = "";
switch (GETID(media)) {
//TODO image viewer and preview
case MessageMediaPhoto:
Expand Down Expand Up @@ -516,6 +518,7 @@ TgObject MessagesModel::createRow(TgObject message, TgObject sender, TgList user
row["mediaTitle"] = "Webpage";
row["mediaText"] = media["webpage"].toMap()["title"].toString();
if (row["mediaText"].toString().isEmpty()) row["mediaText"] = "unknown link";
row["mediaUrl"] = media["webpage"].toMap()["url"].toString();
break;
case MessageMediaVenue:
row["mediaImage"] = "../../img/media/map-marker.png";
Expand Down Expand Up @@ -593,7 +596,12 @@ void MessagesModel::linkActivated(QString link, qint32 listIndex)
emit dataChanged(index(listIndex), index(listIndex));
}
}
else QDesktopServices::openUrl(url);
else openUrl(link);
}

void MessagesModel::openUrl(QString url)
{
QDesktopServices::openUrl(QUrl(url));
}

void MessagesModel::avatarDownloaded(TgLongVariant photoId, QString filePath)
Expand Down
5 changes: 4 additions & 1 deletion messagesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class MessagesModel : public QAbstractListModel
MediaTextRole,
MediaDownloadableRole,
MessageIdRole,
ForwardedFromRole
ForwardedFromRole,
MediaUrlRole
};

public:
Expand Down Expand Up @@ -97,6 +98,8 @@ public slots:
void linkActivated(QString link, qint32 index);
void downloadFile(qint32 index);
void cancelDownload(qint32 index);

void openUrl(QString url);
};

#endif // MESSAGESMODEL_H
7 changes: 6 additions & 1 deletion qml/message/MessageDocument.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ Rectangle {

MouseArea {
anchors.fill: parent
enabled: downloadable
enabled: downloadable || mediaUrl.length != 0
onClicked: {
if (mediaUrl.length != 0) {
messagesModel.openUrl(mediaUrl);
return;
}

if (attachButton.state == "NOT_DOWNLOADING") {
messagesModel.downloadFile(rowIndex);
} else {
Expand Down

0 comments on commit 904e27b

Please sign in to comment.