Link preview messageeventmodel parameters

This move the finding of links and the creation of a `linkpreviewer` into c++.

- The links are now extracted from the text in `texthandler`
- The `messageeventmodel` now creates and stores `linkpreviewers` for events that have links in the current room.

Two new model roles have been created to let a text delegate know when the link preview should be shown (`showLinkPreview`) and pass the link previewer (`linkPreviewer`). Empty link previewer are returned where link don't exist so the qml doesn't have to have checks for whether the parameters are undefined.
This commit is contained in:
James Graham
2023-05-08 08:18:49 +00:00
committed by Tobias Fella
parent b82d3ab5ad
commit 72de7c6cfb
9 changed files with 187 additions and 73 deletions

View File

@@ -5,6 +5,7 @@
#include <QAbstractListModel>
#include "linkpreviewer.h"
#include "neochatroom.h"
/**
@@ -70,6 +71,9 @@ public:
FormattedBodyRole, /**< The formatted body of a rich message. */
GenericDisplayRole, /**< A generic string based upon the message type. */
ShowLinkPreviewRole, /**< Whether a link preview should be shown. */
LinkPreviewRole, /**< The link preview details. */
MediaInfoRole, /**< The media info for the event. */
MimeTypeRole, /**< The mime type of the message's file or media. */
@@ -180,6 +184,8 @@ private:
int rowBelowInserted = -1;
bool movingEvent = false;
QMap<QString, LinkPreviewer *> m_linkPreviewers;
[[nodiscard]] int timelineBaseIndex() const;
[[nodiscard]] QDateTime makeMessageTimestamp(const Quotient::Room::rev_iter_t &baseIt) const;
[[nodiscard]] static QString renderDate(const QDateTime &timestamp);
@@ -195,6 +201,7 @@ private:
const Quotient::RoomEvent *getReplyForEvent(const Quotient::RoomEvent &event) const;
QVariantMap getMediaInfoForEvent(const Quotient::RoomEvent &event) const;
QVariantMap getMediaInfoFromFileInfo(const Quotient::EventContent::FileInfo *fileInfo, const QString &eventId, bool isThumbnail = false) const;
void createLinkPreviewerForEvent(const Quotient::RoomMessageEvent *event);
std::vector<Quotient::event_ptr_tt<Quotient::RoomEvent>> m_extraEvents;
// Hack to ensure that we don't call endInsertRows when we haven't called beginInsertRows