[ATTACHMENTS][Embed][UI] Allow plugins to provide a title for an attachment, if a note has none, implement such a mechanism in Embed and cache the result, since it is potentially costly

This commit is contained in:
2021-09-15 16:49:29 +01:00
committed by Diogo Peralta Cordeiro
parent 15a2a69274
commit f344ed376c
2 changed files with 31 additions and 6 deletions

View File

@@ -485,6 +485,17 @@ class Embed extends Plugin
return HTTPClient::get($url)->getContent();
}
public function onAttachmentGetBestTitle(Attachment $attachment, Note $note, ?string &$title)
{
try {
$embed = DB::findOneBy('attachment_embed', ['attachment_id' => $attachment->getId()]);
$title = $embed->getTitle();
return Event::stop;
} catch (NotFoundException) {
}
return Event::next;
}
/**
* Event raised when GNU social polls the plugin for information about it.
* Adds this plugin's version information to $versions array