mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Merge pull request #4973 from pixelfed/staging
Update ApiV1Controller, fix Notifications endpoint
This commit is contained in:
commit
eb19c35343
5 changed files with 1450 additions and 1369 deletions
|
@ -26,6 +26,8 @@
|
|||
- Update AdminCuratedRegisterController, filter confirmation activities from activitylog ([ab9ecb6e](https://github.com/pixelfed/pixelfed/commit/ab9ecb6e))
|
||||
- Update Inbox, fix flag validation condition, allow profile reports ([402a4607](https://github.com/pixelfed/pixelfed/commit/402a4607))
|
||||
- Update AccountTransformer, fix follower/following count visibility bug ([542d1106](https://github.com/pixelfed/pixelfed/commit/542d1106))
|
||||
- Update ProfileMigration model, add target relation ([3f053997](https://github.com/pixelfed/pixelfed/commit/3f053997))
|
||||
- Update ApiV1Controller, update Notifications endpoint to filter notifications with missing activities ([a933615b](https://github.com/pixelfed/pixelfed/commit/a933615b))
|
||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||
|
||||
## [v0.11.12 (2024-02-16)](https://github.com/pixelfed/pixelfed/compare/v0.11.11...v0.11.12)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,6 +8,12 @@ class MediaTag extends Model
|
|||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $visible = [
|
||||
'status_id',
|
||||
'profile_id',
|
||||
'tagged_username',
|
||||
];
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo(Status::class);
|
||||
|
|
|
@ -2,23 +2,22 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Jobs\InternalPipeline\NotificationEpochUpdatePipeline;
|
||||
use App\Notification;
|
||||
use App\Transformer\Api\NotificationTransformer;
|
||||
use Cache;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\{
|
||||
Notification,
|
||||
Profile
|
||||
};
|
||||
use App\Transformer\Api\NotificationTransformer;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use App\Jobs\InternalPipeline\NotificationEpochUpdatePipeline;
|
||||
|
||||
class NotificationService {
|
||||
|
||||
class NotificationService
|
||||
{
|
||||
const CACHE_KEY = 'pf:services:notifications:ids:';
|
||||
|
||||
const EPOCH_CACHE_KEY = 'pf:services:notifications:epoch-id:by-months:';
|
||||
|
||||
const ITEM_CACHE_TTL = 86400;
|
||||
|
||||
const MASTODON_TYPES = [
|
||||
'follow',
|
||||
'follow_request',
|
||||
|
@ -26,7 +25,7 @@ class NotificationService {
|
|||
'reblog',
|
||||
'favourite',
|
||||
'poll',
|
||||
'status'
|
||||
'status',
|
||||
];
|
||||
|
||||
public static function get($id, $start = 0, $stop = 400)
|
||||
|
@ -44,6 +43,7 @@ class NotificationService {
|
|||
$res->push($n);
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,10 @@ class NotificationService {
|
|||
$epoch = Cache::get(self::EPOCH_CACHE_KEY.$months);
|
||||
if (! $epoch) {
|
||||
NotificationEpochUpdatePipeline::dispatch();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $epoch;
|
||||
}
|
||||
|
||||
|
@ -69,6 +71,7 @@ class NotificationService {
|
|||
foreach ($ids as $key) {
|
||||
self::set($id, $key);
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
@ -87,6 +90,7 @@ class NotificationService {
|
|||
$res->push($n);
|
||||
}
|
||||
}
|
||||
|
||||
return $res->toArray();
|
||||
}
|
||||
|
||||
|
@ -105,10 +109,10 @@ class NotificationService {
|
|||
$res->push($n);
|
||||
}
|
||||
}
|
||||
|
||||
return $res->toArray();
|
||||
}
|
||||
|
||||
|
||||
public static function getMaxMastodon($id = false, $start = 0, $limit = 10)
|
||||
{
|
||||
$ids = self::getRankedMaxId($id, $start, $limit);
|
||||
|
@ -129,6 +133,11 @@ class NotificationService {
|
|||
unset($n['relationship']);
|
||||
}
|
||||
|
||||
if ($n['type'] === 'mention' && isset($n['tagged'], $n['tagged']['status_id'])) {
|
||||
$n['status'] = StatusService::getMastodon($n['tagged']['status_id'], false);
|
||||
unset($n['tagged']);
|
||||
}
|
||||
|
||||
if (isset($n['status'])) {
|
||||
$n['status'] = StatusService::getMastodon($n['status']['id'], false);
|
||||
}
|
||||
|
@ -136,6 +145,7 @@ class NotificationService {
|
|||
$res->push($n);
|
||||
}
|
||||
}
|
||||
|
||||
return $res->toArray();
|
||||
}
|
||||
|
||||
|
@ -159,6 +169,11 @@ class NotificationService {
|
|||
unset($n['relationship']);
|
||||
}
|
||||
|
||||
if ($n['type'] === 'mention' && isset($n['tagged'], $n['tagged']['status_id'])) {
|
||||
$n['status'] = StatusService::getMastodon($n['tagged']['status_id'], false);
|
||||
unset($n['tagged']);
|
||||
}
|
||||
|
||||
if (isset($n['status'])) {
|
||||
$n['status'] = StatusService::getMastodon($n['status']['id'], false);
|
||||
}
|
||||
|
@ -166,6 +181,7 @@ class NotificationService {
|
|||
$res->push($n);
|
||||
}
|
||||
}
|
||||
|
||||
return $res->toArray();
|
||||
}
|
||||
|
||||
|
@ -177,7 +193,7 @@ class NotificationService {
|
|||
|
||||
return array_keys(Redis::zrevrangebyscore(self::CACHE_KEY.$id, $start, '-inf', [
|
||||
'withscores' => true,
|
||||
'limit' => [1, $limit]
|
||||
'limit' => [1, $limit],
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -189,7 +205,7 @@ class NotificationService {
|
|||
|
||||
return array_keys(Redis::zrevrangebyscore(self::CACHE_KEY.$id, '+inf', $end, [
|
||||
'withscores' => true,
|
||||
'limit' => [0, $limit]
|
||||
'limit' => [0, $limit],
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -207,6 +223,10 @@ class NotificationService {
|
|||
$notification['type'] = 'reblog';
|
||||
}
|
||||
|
||||
if ($notification['type'] === 'tagged') {
|
||||
$notification['type'] = 'mention';
|
||||
}
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
|
@ -215,12 +235,14 @@ class NotificationService {
|
|||
if (self::count($id) > 400) {
|
||||
Redis::zpopmin(self::CACHE_KEY.$id);
|
||||
}
|
||||
|
||||
return Redis::zadd(self::CACHE_KEY.$id, $val, $val);
|
||||
}
|
||||
|
||||
public static function del($id, $val)
|
||||
{
|
||||
Cache::forget('service:notification:'.$val);
|
||||
|
||||
return Redis::zrem(self::CACHE_KEY.$id, $val);
|
||||
}
|
||||
|
||||
|
@ -257,6 +279,7 @@ class NotificationService {
|
|||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($n, new NotificationTransformer());
|
||||
|
||||
return $fractal->createData($resource)->toArray();
|
||||
});
|
||||
|
||||
|
@ -277,6 +300,7 @@ class NotificationService {
|
|||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($notification, new NotificationTransformer());
|
||||
|
||||
return $fractal->createData($resource)->toArray();
|
||||
});
|
||||
}
|
||||
|
@ -292,8 +316,10 @@ class NotificationService {
|
|||
foreach ($ids as $key) {
|
||||
self::set($id, $key);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace App\Transformer\Api;
|
|||
|
||||
use App\Notification;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\RelationshipService;
|
||||
use App\Services\StatusService;
|
||||
use League\Fractal;
|
||||
|
@ -37,7 +36,7 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
|||
if ($ml && $ml->object_uid) {
|
||||
$res['modlog'] = [
|
||||
'id' => $ml->object_uid,
|
||||
'url' => url('/i/admin/users/modlogs/' . $ml->object_uid)
|
||||
'url' => url('/i/admin/users/modlogs/'.$ml->object_uid),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -45,12 +44,17 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
|||
if ($n->item_id && $n->item_type == 'App\MediaTag') {
|
||||
$ml = $n->item;
|
||||
if ($ml && $ml->tagged_username) {
|
||||
$np = StatusService::get($ml->status_id, false);
|
||||
if ($np && isset($np['id'])) {
|
||||
$res['tagged'] = [
|
||||
'username' => $ml->tagged_username,
|
||||
'post_url' => '/p/'.HashidService::encode($ml->status_id)
|
||||
'post_url' => $np['url'],
|
||||
'status_id' => $ml->status_id,
|
||||
'profile_id' => $ml->profile_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -64,7 +68,6 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
|||
'reblog' => 'share',
|
||||
'share' => 'share',
|
||||
'like' => 'favourite',
|
||||
'group:like' => 'favourite',
|
||||
'comment' => 'comment',
|
||||
'admin.user.modlog.comment' => 'modlog',
|
||||
'tagged' => 'tagged',
|
||||
|
|
Loading…
Reference in a new issue