From 711fc020e76d6ed5cfb4b89edc982b6ac97611ba Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 14 Jul 2020 17:04:51 -0600 Subject: [PATCH] Add Media Tags --- app/Http/Controllers/MediaTagController.php | 55 +++++++++++++++++++ app/MediaTag.php | 13 +++++ ...0_06_30_180159_create_media_tags_table.php | 38 +++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 app/Http/Controllers/MediaTagController.php create mode 100644 app/MediaTag.php create mode 100644 database/migrations/2020_06_30_180159_create_media_tags_table.php diff --git a/app/Http/Controllers/MediaTagController.php b/app/Http/Controllers/MediaTagController.php new file mode 100644 index 000000000..54d2c2620 --- /dev/null +++ b/app/Http/Controllers/MediaTagController.php @@ -0,0 +1,55 @@ +user(), 403); + + $this->validate($request, [ + 'q' => 'required|string|min:1|max:50' + ]); + + $q = $request->input('q'); + + if(Str::of($q)->startsWith('@')) { + if(strlen($q) < 3) { + return []; + } + $q = mb_substr($q, 1); + } + + $blocked = UserFilter::whereFilterableType('App\Profile') + ->whereFilterType('block') + ->whereFilterableId($request->user()->profile_id) + ->pluck('user_id'); + + $blocked->push($request->user()->profile_id); + + $results = Profile::select('id','domain','username') + ->whereNotIn('id', $blocked) + ->whereNull('domain') + ->where('username','like','%'.$q.'%') + ->limit(15) + ->get() + ->map(function($r) { + return [ + 'id' => (string) $r->id, + 'name' => $r->username, + 'privacy' => true, + 'avatar' => $r->avatarUrl() + ]; + }); + + return $results; + } +} diff --git a/app/MediaTag.php b/app/MediaTag.php new file mode 100644 index 000000000..ff5fe9b6e --- /dev/null +++ b/app/MediaTag.php @@ -0,0 +1,13 @@ +belongsTo(Status::class); + } +} diff --git a/database/migrations/2020_06_30_180159_create_media_tags_table.php b/database/migrations/2020_06_30_180159_create_media_tags_table.php new file mode 100644 index 000000000..10b2b721b --- /dev/null +++ b/database/migrations/2020_06_30_180159_create_media_tags_table.php @@ -0,0 +1,38 @@ +id(); + $table->bigInteger('status_id')->unsigned()->index()->nullable(); + $table->bigInteger('media_id')->unsigned()->index(); + $table->bigInteger('profile_id')->unsigned()->index(); + $table->string('tagged_username')->nullable(); + $table->boolean('is_public')->default(true)->index(); + $table->json('metadata')->nullable(); + $table->unique(['media_id', 'profile_id']); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('media_tags'); + } +}