Browse Source

Migrate the Tenor implementation to the v2 of the API

pull/1265/head
Timothée Jaussoin 2 years ago
committed by Timothée Jaussoin
parent
commit
60df77b0f1
  1. 1
      CHANGELOG.md
  2. 46
      app/widgets/Stickers/Stickers.php

1
CHANGELOG.md

@ -17,6 +17,7 @@ v0.22.6 (trunk)
* Upgrade the icon pack from MaterialIcons to MaterialSymbols
* Add support of online/offline browser events to quick disconnect/reconnect on network change
* Implement MAM history retrieval for MUCs and contacts
* Migrate the Tenor implementation to the v2 of the API
v0.22.5
---------------------------

46
app/widgets/Stickers/Stickers.php

@ -186,29 +186,28 @@ class Stickers extends \Movim\Widget\Base
$apiKey = $configuration->gifapikey;
if (empty($apiKey)) return;
$keyword = filter_var($keyword, FILTER_FLAG_STRIP_HIGH);
$keyword = filter_var($keyword, FILTER_SANITIZE_URL);
$keyword = str_replace(' ', '+', $keyword);
requestAsyncURL(
'https://api.tenor.com/v1/search?q=' . $keyword .
'&key=' . $apiKey .
'&limit=' . $this->paginate .
'&pos=' . ($page * $this->paginate)
'https://tenor.googleapis.com/v2/search?q=' . $keyword .
'&media_filter=preview,tinywebm' .
'&key=' . $apiKey .
'&limit=' . $this->paginate .
'&pos=' . ($page * $this->paginate)
)->then(function (ResponseInterface $response) {
$view = $this->tpl();
$results = \json_decode($response->getBody());
if ($results) {
$i = 0;
foreach ($results->results as $result) {
$gif = [
'id' => $result->id,
'url' => $result->media[0]->tinywebm->url,
'preview' => $result->media[0]->tinywebm->preview,
'width' => $result->media[0]->tinywebm->dims[0],
'height' => $result->media[0]->tinywebm->dims[1],
'id' => (string)$result->id,
'url' => (string)$result->media_formats->tinywebm->url,
'preview' => (string)$result->media_formats->preview->url,
'width' => (int)$result->media_formats->tinywebm->dims[0],
'height' => (int)$result->media_formats->tinywebm->dims[1],
];
$view->assign('gif', $gif);
@ -222,13 +221,15 @@ class Stickers extends \Movim\Widget\Base
}
$this->rpc('Stickers.setGifsEvents');
}, function (\Exception $e) {
error_log($e->getMessage());
});
}
/**
* Resolve a GIF and share it as a message
*/
public function ajaxSendGif(string $to, int $gifId, bool $muc = false)
public function ajaxSendGif(string $to, string $gifId, bool $muc = false)
{
$configuration = Configuration::get();
$apiKey = $configuration->gifapikey;
@ -236,8 +237,9 @@ class Stickers extends \Movim\Widget\Base
if (empty($apiKey)) return;
requestAsyncURL(
'https://api.tenor.com/v1/gifs?ids=' . $gifId .
'&key=' . $apiKey
'https://tenor.googleapis.com/v2/posts?ids=' . $gifId .
'&media_filter=preview,tinywebm' .
'&key=' . $apiKey
)->then(function (ResponseInterface $response) use ($to, $muc) {
$results = \json_decode($response->getBody());
@ -246,15 +248,15 @@ class Stickers extends \Movim\Widget\Base
$messageFile = new MessageFile;
$messageFile->name = $result->url;
$messageFile->uri = $result->media[0]->tinywebm->url;
$messageFile->name = (string)$result->url;
$messageFile->uri = (string)$result->media_formats->tinywebm->url;
$messageFile->type = 'video/webm';
$messageFile->size = $result->media[0]->tinywebm->size;
$messageFile->size = (int)$result->media_formats->tinywebm->size;
$messageFile->thumbnail->type = 'image/png';
$messageFile->thumbnail->uri = $result->media[0]->tinywebm->preview;
$messageFile->thumbnail->width = $result->media[0]->tinywebm->dims[0];
$messageFile->thumbnail->height = $result->media[0]->tinywebm->dims[1];
$messageFile->thumbnail->uri = (string)$result->media_formats->preview->url;
$messageFile->thumbnail->width = (int)$result->media_formats->preview->dims[0];
$messageFile->thumbnail->height = (int)$result->media_formats->preview->dims[1];
$chat = new \Chat;
$chat->sendMessage(
@ -265,6 +267,8 @@ class Stickers extends \Movim\Widget\Base
$messageFile
);
}
}, function (\Exception $e) {
error_log($e->getMessage());
});
}

Loading…
Cancel
Save