Pārlūkot izejas kodu

Merge pull request #4136 from pixelfed/staging

Staging
daniel 2 gadi atpakaļ
vecāks
revīzija
df52422b4a

+ 2 - 0
CHANGELOG.md

@@ -84,6 +84,8 @@
 - Update AdminApiController, fix postgres support ([84fb59d0](https://github.com/pixelfed/pixelfed/commit/84fb59d0))
 - Update StatusReplyPipeline, fix comment counts ([164aa577](https://github.com/pixelfed/pixelfed/commit/164aa577))
 - Update ComposeModal, add Alt Text button to caption screen ([4db48188](https://github.com/pixelfed/pixelfed/commit/4db48188))
+- Update AccountService, fix actor cache invalidation ([498b46f7](https://github.com/pixelfed/pixelfed/commit/498b46f7))
+- Update SharePipeline, fix share handling and notification generation ([83e1e203](https://github.com/pixelfed/pixelfed/commit/83e1e203))
 -  ([](https://github.com/pixelfed/pixelfed/commit/))
 
 ## [v0.11.4 (2022-10-04)](https://github.com/pixelfed/pixelfed/compare/v0.11.3...v0.11.4)

+ 2 - 4
app/Http/Controllers/Api/ApiV1Controller.php

@@ -2814,9 +2814,7 @@ class ApiV1Controller extends Controller
 			'visibility' => 'public'
 		]);
 
-		if($share->wasRecentlyCreated == true) {
-			SharePipeline::dispatch($share);
-		}
+		SharePipeline::dispatch($share)->onQueue('low');
 
 		StatusService::del($status->id);
 		ReblogService::add($user->profile_id, $status->id);
@@ -2858,7 +2856,7 @@ class ApiV1Controller extends Controller
 			return $this->json($res);
 		}
 
-		UndoSharePipeline::dispatch($reblog);
+		UndoSharePipeline::dispatch($reblog)->onQueue('low');
 		ReblogService::del($user->profile_id, $status->id);
 
 		$res = StatusService::getMastodon($status->id);

+ 1 - 1
app/Http/Controllers/BookmarkController.php

@@ -31,7 +31,7 @@ class BookmarkController extends Controller
             abort_if(
                 $profile->id !== $status->profile_id && !FollowerService::follows($profile->id, $status->profile_id),
                 404,
-                'Error: Cannot bookmark private posts from accounts you do not follow.'
+                'Error: You cannot bookmark private posts from accounts you do not follow.'
             );
         }
 

+ 16 - 31
app/Jobs/SharePipeline/SharePipeline.php

@@ -58,47 +58,32 @@ class SharePipeline implements ShouldQueue
 			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) {
 			$this->remoteAnnounceDeliver();
 			return true;
 		}
 
-		if($exists === true) {
-			return true;
-		}
-
-		$this->remoteAnnounceDeliver();
-
 		ReblogService::addPostReblog($parent->id, $status->id);
 
-		$parent->reblogs_count = $parent->shares()->count();
+		$parent->reblogs_count = $parent->reblogs_count + 1;
 		$parent->save();
 		StatusService::del($parent->id);
 
-		try {
-			$notification = new Notification;
-			$notification->profile_id = $target->id;
-			$notification->actor_id = $actor->id;
-			$notification->action = 'share';
-			$notification->message = $status->shareToText();
-			$notification->rendered = $status->shareToHtml();
-			$notification->item_id = $status->reblog_of_id ?? $status->id;
-			$notification->item_type = "App\Status";
-			$notification->save();
-
-			$redis = Redis::connection();
-			$key = config('cache.prefix').':user.'.$status->profile_id.'.notifications';
-			$redis->lpush($key, $notification->id);
-		} catch (Exception $e) {
-			Log::error($e);
-		}
+		Notification::firstOrCreate(
+			[
+				'profile_id' => $target->id,
+				'actor_id' => $actor->id,
+				'action' => 'share',
+				'item_type' => 'App\Status',
+				'item_id' => $status->reblog_of_id ?? $status->id,
+			],
+			[
+				'message' => $status->shareToText(),
+				'rendered' => $status->shareToHtml()
+			]
+		);
+
+		return $this->remoteAnnounceDeliver();
 	}
 
 	public function remoteAnnounceDeliver()

+ 29 - 22
app/Jobs/SharePipeline/UndoSharePipeline.php

@@ -33,35 +33,39 @@ class UndoSharePipeline implements ShouldQueue
 	{
 		$status = $this->status;
 		$actor = $status->profile;
-		$parent = $status->parent();
-		$target = $status->parent()->profile;
+		$parent = Status::find($status->reblog_of_id);
 
-		ReblogService::removePostReblog($parent->id, $status->id);
+		if($parent) {
+			$target = $parent->profile_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();
-		}
+			if($parent->reblogs_count > 0) {
+				$parent->reblogs_count = $parent->reblogs_count - 1;
+				$parent->save();
+				StatusService::del($parent->id);
+			}
 
-		$this->remoteAnnounceDeliver();
+			$notification = Notification::whereProfileId($target)
+				->whereActorId($status->profile_id)
+				->whereAction('share')
+				->whereItemId($status->reblog_of_id)
+				->whereItemType('App\Status')
+				->first();
 
-		if($parent->reblogs_count > 0) {
-			$parent->reblogs_count = $parent->reblogs_count - 1;
-			$parent->save();
-			StatusService::del($parent->id);
+			if($notification) {
+				$notification->forceDelete();
+			}
 		}
 
-		$status->forceDelete();
+		if ($status->uri != null) {
+			return;
+		}
 
-		return 1;
+		if(config_cache('federation.activitypub.enabled') == false) {
+			return $status->delete();
+		} else {
+			return $this->remoteAnnounceDeliver();
+		}
 	}
 
 	public function remoteAnnounceDeliver()
@@ -124,5 +128,8 @@ class UndoSharePipeline implements ShouldQueue
 
 		$promise->wait();
 
+		$status->delete();
+
+		return 1;
 	}
 }

+ 1 - 1
app/Notification.php

@@ -16,7 +16,7 @@ class Notification extends Model
      */
     protected $dates = ['deleted_at'];
 
-    protected $fillable = ['*'];
+    protected $guarded = [];
 
     public function actor()
     {

+ 13 - 14
app/Util/ActivityPub/Inbox.php

@@ -569,13 +569,9 @@ class Inbox
 			return;
 		}
 
-		if(Helpers::validateLocalUrl($activity) == false) {
-			return;
-		}
-
 		$parent = Helpers::statusFetch($activity);
 
-		if(empty($parent)) {
+		if(!$parent || empty($parent)) {
 			return;
 		}
 
@@ -590,15 +586,18 @@ class Inbox
 			'type' => 'share'
 		]);
 
-		Notification::firstOrCreate([
-			'profile_id' => $parent->profile->id,
-			'actor_id' => $actor->id,
-			'action' => 'share',
-			'message' => $status->replyToText(),
-			'rendered' => $status->replyToHtml(),
-			'item_id' => $parent->id,
-			'item_type' => 'App\Status'
-		]);
+		Notification::firstOrCreate(
+			[
+				'profile_id' => $parent->profile_id,
+				'actor_id' => $actor->id,
+				'action' => 'share',
+				'item_id' => $parent->id,
+				'item_type' => 'App\Status',
+			], [
+				'message' => $status->replyToText(),
+				'rendered' => $status->replyToHtml(),
+			]
+		);
 
 		$parent->reblogs_count = $parent->reblogs_count + 1;
 		$parent->save();

+ 2 - 5
app/Util/ActivityPub/Validator/Announce.php

@@ -11,18 +11,15 @@ class Announce {
 	{
 		$valid = Validator::make($payload, [
 			'@context' => 'required',
-			'id' => 'required|string',
+			'id' => 'required|url',
 			'type' => [
 				'required',
 				Rule::in(['Announce'])
 			],
 			'actor' => 'required|url',
-			'published' => 'required|date',
-			'to'	=> 'required',
-			'cc'	=> 'required',
 			'object' => 'required|url'
 		])->passes();
 
 		return $valid;
 	}
-}
+}

BIN
public/img/pixelfed-icon-black.svg


BIN
public/img/pixelfed-icon-color.svg


BIN
public/img/pixelfed-icon-grey.svg


BIN
public/img/pixelfed-icon-white.svg


+ 0 - 48
tests/Unit/ActivityPub/Verb/AnnounceTest.php

@@ -53,22 +53,6 @@ class AnnounceTest extends TestCase
             'object' => 'https://example.org/p/bob/100000000000000',
         ];
 
-        $this->invalidDate = [
-            '@context' => 'https://www.w3.org/ns/activitystreams',
-            'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
-            'type' => 'Announce',
-            'actor' => 'https://example.org/users/alice',
-            'published' => '2018-12-31T23:59:59ZEZE',
-            'to' => [
-                'https://www.w3.org/ns/activitystreams#Public'
-            ],
-            'cc' => [
-                'https://example.org/users/bob',
-                'https://example.org/users/alice/followers'
-            ],
-            'object' => 'https://example.org/p/bob/100000000000000',
-        ];
-
         $this->contextMissing = [
             'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
             'type' => 'Announce',
@@ -84,25 +68,6 @@ class AnnounceTest extends TestCase
             'object' => 'https://example.org/p/bob/100000000000000',
         ];
 
-        $this->audienceMissing = [
-            'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
-            'type' => 'Announce',
-            'actor' => 'https://example.org/users/alice',
-            'published' => '2018-12-31T23:59:59Z',
-            'object' => 'https://example.org/p/bob/100000000000000',
-        ];
-
-        $this->audienceMissing2 = [
-            '@context' => 'https://www.w3.org/ns/activitystreams',
-            'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
-            'type' => 'Announce',
-            'actor' => 'https://example.org/users/alice',
-            'published' => '2018-12-31T23:59:59Z',
-            'to' => null,
-            'cc' => null,
-            'object' => 'https://example.org/p/bob/100000000000000',
-        ];
-
         $this->invalidActor = [
             '@context' => 'https://www.w3.org/ns/activitystreams',
             'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
@@ -185,25 +150,12 @@ class AnnounceTest extends TestCase
         $this->assertFalse(Announce::validate($this->invalidAnnounce));
     }
 
-    /** @test */
-    public function invalid_date()
-    {
-        $this->assertFalse(Announce::validate($this->invalidDate));
-    }
-
     /** @test */
     public function context_missing()
     {
         $this->assertFalse(Announce::validate($this->contextMissing));
     }
 
-    /** @test */
-    public function audience_missing()
-    {
-        $this->assertFalse(Announce::validate($this->audienceMissing));
-        $this->assertFalse(Announce::validate($this->audienceMissing2));
-    }
-
     /** @test */
     public function invalid_actor()
     {