From 01798daf56979467b025ccabf322e80d7003e07b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jan 2022 23:26:44 -0700 Subject: [PATCH] Update AP helpers, import Emoji tags --- app/Services/CustomEmojiService.php | 4 ++-- app/Util/ActivityPub/Helpers.php | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/Services/CustomEmojiService.php b/app/Services/CustomEmojiService.php index 1a64784bb..3311e5117 100644 --- a/app/Services/CustomEmojiService.php +++ b/app/Services/CustomEmojiService.php @@ -8,12 +8,12 @@ use App\Models\CustomEmoji; class CustomEmojiService { - public static function getByShortcode($shortcode) + public static function get($shortcode) { return CustomEmoji::whereShortcode($shortcode)->first(); } - public static function getByUrl($url) + public static function import($url) { if(Helpers::validateUrl($url) == false) { return; diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index c2a88ed5c..1413f5106 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -27,6 +27,7 @@ use App\Util\ActivityPub\HttpSignature; use Illuminate\Support\Str; use App\Services\ActivityPubFetchService; use App\Services\ActivityPubDeliveryService; +use App\Services\CustomEmojiService; use App\Services\InstanceService; use App\Services\MediaPathService; use App\Services\MediaStorageService; @@ -368,7 +369,6 @@ class Helpers { $cw = true; } - $statusLockKey = 'helpers:status-lock:' . hash('sha256', $res['id']); $status = Cache::lock($statusLockKey) ->get(function () use( @@ -381,6 +381,20 @@ class Helpers { $scope, $id ) { + if(isset($res['tag']) && is_array($res['tag']) && !empty($res['tag'])) { + collect($res['tag']) + ->filter(function($tag) { + // todo: finish hashtag + mention import + // return in_array($tag['type'], ['Emoji', 'Hashtag', 'Mention']); + return in_array($tag['type'], ['Emoji']); + }) + ->each(function($tag) { + if(isset($tag['id'])) { + CustomEmojiService::import($tag['id']); + } + }); + } + if($res['type'] === 'Question') { $status = self::storePoll( $profile,