mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Update SharePipeline, fix share handling and notification generation
This commit is contained in:
parent
df1327f415
commit
83e1e203ce
6 changed files with 63 additions and 77 deletions
|
@ -2814,9 +2814,7 @@ class ApiV1Controller extends Controller
|
||||||
'visibility' => 'public'
|
'visibility' => 'public'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if($share->wasRecentlyCreated == true) {
|
SharePipeline::dispatch($share)->onQueue('low');
|
||||||
SharePipeline::dispatch($share);
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id);
|
||||||
ReblogService::add($user->profile_id, $status->id);
|
ReblogService::add($user->profile_id, $status->id);
|
||||||
|
@ -2858,7 +2856,7 @@ class ApiV1Controller extends Controller
|
||||||
return $this->json($res);
|
return $this->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
UndoSharePipeline::dispatch($reblog);
|
UndoSharePipeline::dispatch($reblog)->onQueue('low');
|
||||||
ReblogService::del($user->profile_id, $status->id);
|
ReblogService::del($user->profile_id, $status->id);
|
||||||
|
|
||||||
$res = StatusService::getMastodon($status->id);
|
$res = StatusService::getMastodon($status->id);
|
||||||
|
|
|
@ -58,47 +58,32 @@ class SharePipeline implements ShouldQueue
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$exists = Notification::whereProfileId($target->id)
|
|
||||||
->whereActorId($status->profile_id)
|
|
||||||
->whereAction('share')
|
|
||||||
->whereItemId($status->reblog_of_id)
|
|
||||||
->whereItemType('App\Status')
|
|
||||||
->exists();
|
|
||||||
|
|
||||||
if($target->id === $status->profile_id) {
|
if($target->id === $status->profile_id) {
|
||||||
$this->remoteAnnounceDeliver();
|
$this->remoteAnnounceDeliver();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($exists === true) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->remoteAnnounceDeliver();
|
|
||||||
|
|
||||||
ReblogService::addPostReblog($parent->id, $status->id);
|
ReblogService::addPostReblog($parent->id, $status->id);
|
||||||
|
|
||||||
$parent->reblogs_count = $parent->shares()->count();
|
$parent->reblogs_count = $parent->reblogs_count + 1;
|
||||||
$parent->save();
|
$parent->save();
|
||||||
StatusService::del($parent->id);
|
StatusService::del($parent->id);
|
||||||
|
|
||||||
try {
|
Notification::firstOrCreate(
|
||||||
$notification = new Notification;
|
[
|
||||||
$notification->profile_id = $target->id;
|
'profile_id' => $target->id,
|
||||||
$notification->actor_id = $actor->id;
|
'actor_id' => $actor->id,
|
||||||
$notification->action = 'share';
|
'action' => 'share',
|
||||||
$notification->message = $status->shareToText();
|
'item_type' => 'App\Status',
|
||||||
$notification->rendered = $status->shareToHtml();
|
'item_id' => $status->reblog_of_id ?? $status->id,
|
||||||
$notification->item_id = $status->reblog_of_id ?? $status->id;
|
],
|
||||||
$notification->item_type = "App\Status";
|
[
|
||||||
$notification->save();
|
'message' => $status->shareToText(),
|
||||||
|
'rendered' => $status->shareToHtml()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$redis = Redis::connection();
|
return $this->remoteAnnounceDeliver();
|
||||||
$key = config('cache.prefix').':user.'.$status->profile_id.'.notifications';
|
|
||||||
$redis->lpush($key, $notification->id);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
Log::error($e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remoteAnnounceDeliver()
|
public function remoteAnnounceDeliver()
|
||||||
|
|
|
@ -33,35 +33,39 @@ class UndoSharePipeline implements ShouldQueue
|
||||||
{
|
{
|
||||||
$status = $this->status;
|
$status = $this->status;
|
||||||
$actor = $status->profile;
|
$actor = $status->profile;
|
||||||
$parent = $status->parent();
|
$parent = Status::find($status->reblog_of_id);
|
||||||
$target = $status->parent()->profile;
|
|
||||||
|
|
||||||
|
if($parent) {
|
||||||
|
$target = $parent->profile_id;
|
||||||
ReblogService::removePostReblog($parent->id, $status->id);
|
ReblogService::removePostReblog($parent->id, $status->id);
|
||||||
|
|
||||||
if ($status->uri !== null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($target->domain === null) {
|
|
||||||
Notification::whereProfileId($target->id)
|
|
||||||
->whereActorId($status->profile_id)
|
|
||||||
->whereAction('share')
|
|
||||||
->whereItemId($status->reblog_of_id)
|
|
||||||
->whereItemType('App\Status')
|
|
||||||
->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->remoteAnnounceDeliver();
|
|
||||||
|
|
||||||
if($parent->reblogs_count > 0) {
|
if($parent->reblogs_count > 0) {
|
||||||
$parent->reblogs_count = $parent->reblogs_count - 1;
|
$parent->reblogs_count = $parent->reblogs_count - 1;
|
||||||
$parent->save();
|
$parent->save();
|
||||||
StatusService::del($parent->id);
|
StatusService::del($parent->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$status->forceDelete();
|
$notification = Notification::whereProfileId($target)
|
||||||
|
->whereActorId($status->profile_id)
|
||||||
|
->whereAction('share')
|
||||||
|
->whereItemId($status->reblog_of_id)
|
||||||
|
->whereItemType('App\Status')
|
||||||
|
->first();
|
||||||
|
|
||||||
return 1;
|
if($notification) {
|
||||||
|
$notification->forceDelete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($status->uri != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(config_cache('federation.activitypub.enabled') == false) {
|
||||||
|
return $status->delete();
|
||||||
|
} else {
|
||||||
|
return $this->remoteAnnounceDeliver();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remoteAnnounceDeliver()
|
public function remoteAnnounceDeliver()
|
||||||
|
@ -124,5 +128,8 @@ class UndoSharePipeline implements ShouldQueue
|
||||||
|
|
||||||
$promise->wait();
|
$promise->wait();
|
||||||
|
|
||||||
|
$status->delete();
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Notification extends Model
|
||||||
*/
|
*/
|
||||||
protected $dates = ['deleted_at'];
|
protected $dates = ['deleted_at'];
|
||||||
|
|
||||||
protected $fillable = ['*'];
|
protected $guarded = [];
|
||||||
|
|
||||||
public function actor()
|
public function actor()
|
||||||
{
|
{
|
||||||
|
|
|
@ -569,13 +569,9 @@ class Inbox
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Helpers::validateLocalUrl($activity) == false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$parent = Helpers::statusFetch($activity);
|
$parent = Helpers::statusFetch($activity);
|
||||||
|
|
||||||
if(empty($parent)) {
|
if(!$parent || empty($parent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,15 +586,18 @@ class Inbox
|
||||||
'type' => 'share'
|
'type' => 'share'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Notification::firstOrCreate([
|
Notification::firstOrCreate(
|
||||||
'profile_id' => $parent->profile->id,
|
[
|
||||||
|
'profile_id' => $parent->profile_id,
|
||||||
'actor_id' => $actor->id,
|
'actor_id' => $actor->id,
|
||||||
'action' => 'share',
|
'action' => 'share',
|
||||||
|
'item_id' => $parent->id,
|
||||||
|
'item_type' => 'App\Status',
|
||||||
|
], [
|
||||||
'message' => $status->replyToText(),
|
'message' => $status->replyToText(),
|
||||||
'rendered' => $status->replyToHtml(),
|
'rendered' => $status->replyToHtml(),
|
||||||
'item_id' => $parent->id,
|
]
|
||||||
'item_type' => 'App\Status'
|
);
|
||||||
]);
|
|
||||||
|
|
||||||
$parent->reblogs_count = $parent->reblogs_count + 1;
|
$parent->reblogs_count = $parent->reblogs_count + 1;
|
||||||
$parent->save();
|
$parent->save();
|
||||||
|
|
|
@ -11,15 +11,12 @@ class Announce {
|
||||||
{
|
{
|
||||||
$valid = Validator::make($payload, [
|
$valid = Validator::make($payload, [
|
||||||
'@context' => 'required',
|
'@context' => 'required',
|
||||||
'id' => 'required|string',
|
'id' => 'required|url',
|
||||||
'type' => [
|
'type' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::in(['Announce'])
|
Rule::in(['Announce'])
|
||||||
],
|
],
|
||||||
'actor' => 'required|url',
|
'actor' => 'required|url',
|
||||||
'published' => 'required|date',
|
|
||||||
'to' => 'required',
|
|
||||||
'cc' => 'required',
|
|
||||||
'object' => 'required|url'
|
'object' => 'required|url'
|
||||||
])->passes();
|
])->passes();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue