Refactor LinkPreviewer

Refactor `LinkPreviewer` to take an event and put the functions for getting the link in the class itself. This means the functions in `EventHandler` are no longer required.

This mr also sets up `LinkPreviewer` so that it is automatically updated when an event is edited. This includes changing the link if edited, and it can handle a message having a previous link removed or a one added when one didn't exist before.

Also adds test suite.
This commit is contained in:
James Graham
2024-01-07 18:07:13 +00:00
parent f361f4e2d8
commit 51f7de117d
22 changed files with 401 additions and 194 deletions

View File

@@ -493,18 +493,4 @@ QString TextHandler::linkifyUrls(QString stringIn)
return stringIn;
}
QList<QUrl> TextHandler::getLinkPreviews()
{
auto data = m_data.remove(TextRegex::removeRichReply);
auto linksMatch = TextRegex::url.globalMatch(data);
QList<QUrl> links;
while (linksMatch.hasNext()) {
auto link = linksMatch.next().captured();
if (!link.contains(QStringLiteral("matrix.to"))) {
links += QUrl(link);
}
}
return links;
}
#include "moc_texthandler.cpp"