Skip to content

Commit 8069649

Browse files
committed
Update FeedService
1 parent ac0c933 commit 8069649

5 files changed

Lines changed: 55 additions & 42 deletions

File tree

app/Http/Controllers/Api/AccountController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,6 @@ public function getContentSettings(Request $request)
964964

965965
$res = [
966966
'hide_ai' => $user->hide_ai,
967-
'hide_sensitive' => $user->hide_sensitive,
968967
];
969968

970969
return $this->data($res);
@@ -974,13 +973,12 @@ public function updateContentSettings(Request $request)
974973
{
975974
$validated = $request->validate([
976975
'hide_ai' => 'sometimes|boolean',
977-
'hide_sensitive' => 'sometimes|boolean',
978976
]);
979977

980978
$user = $request->user();
981979

982980
$changes = [
983-
'old' => $user->only(['hide_ai', 'hide_sensitive']),
981+
'old' => $user->only(['hide_ai']),
984982
'new' => $validated,
985983
];
986984

app/Http/Controllers/Api/FeedController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,31 @@ public function selfAccountFeed(Request $request)
4040

4141
public function getForYouFeed(Request $request)
4242
{
43-
if ($request->user()->cannot('viewAny', [Video::class])) {
43+
$user = $request->user();
44+
if ($user->cannot('viewAny', [Video::class])) {
4445
return $this->error('Please finish setting up your account', 403);
4546
}
46-
app(UserActivityService::class)->markActive($request->user());
47+
app(UserActivityService::class)->markActive($user);
4748
FeedService::enforcePaginationLimit($request);
48-
$feed = FeedService::getVideoFeed($request->user()->profile_id, 5);
49+
$hideAi = $user->hide_ai;
50+
$feed = FeedService::getVideoFeed($user->profile_id, 5, $hideAi);
4951

5052
return VideoResource::collection($feed);
5153
}
5254

5355
public function getFollowingFeed(Request $request)
5456
{
55-
if ($request->user()->cannot('viewAny', [Video::class])) {
57+
$user = $request->user();
58+
if ($user->cannot('viewAny', [Video::class])) {
5659
return $this->error('Please finish setting up your account', 403);
5760
}
5861

59-
app(UserActivityService::class)->markActive($request->user());
62+
app(UserActivityService::class)->markActive($user);
6063

6164
FeedService::enforceFollowingPaginationLimit($request);
6265

63-
$me = $request->user()->profile_id;
66+
$me = $user->profile_id;
67+
$hideAi = $user->hide_ai;
6468

6569
$feed = Video::query()
6670
->published()
@@ -73,6 +77,9 @@ public function getFollowingFeed(Request $request)
7377
->where('followers.profile_id', $me);
7478
});
7579
})
80+
->when($hideAi, function ($query, $hideAi) {
81+
$query->where('contains_ai', false);
82+
})
7683
->orderBy('videos.id', 'desc')
7784
->cursorPaginate(5)
7885
->withQueryString();

app/Services/FeedService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function getAccountFeed($profileId, $limit = 10, $sort = 'Latest',
4747
return VideoResource::collection($feed);
4848
}
4949

50-
public static function getVideoFeed($profileId, $limit = 10)
50+
public static function getVideoFeed($profileId, $limit = 10, $hideAi = false)
5151
{
5252
$blockedSubquery = UserFilterService::getFilters($profileId);
5353

@@ -56,10 +56,12 @@ public static function getVideoFeed($profileId, $limit = 10)
5656
$join->on('videos.profile_id', '=', 'blocked.account_id');
5757
})
5858
->whereNull('blocked.account_id')
59+
->when($hideAi, function ($query, $hideAi) {
60+
$query->where('contains_ai', false);
61+
})
5962
->orderBy('videos.id', 'desc')
6063
->where('videos.status', 2)
6164
->where('is_local', true)
62-
->whereNotNull('videos.vid_optimized')
6365
->select('videos.*')
6466
->cursorPaginate($limit)
6567
->withQueryString();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('videos', function (Blueprint $table) {
15+
$table->index(
16+
['status', 'is_local', 'contains_ai'],
17+
'videos_local_feed_index'
18+
);
19+
20+
$table->index(
21+
['status', 'visibility', 'contains_ai', 'created_at'],
22+
'videos_fyp_feed_index'
23+
);
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*/
30+
public function down(): void
31+
{
32+
Schema::table('videos', function (Blueprint $table) {
33+
$table->dropIndex('videos_local_feed_index');
34+
$table->dropIndex('videos_fyp_feed_index');
35+
});
36+
}
37+
};

resources/js/pages/dashboard/account/AccountContent.vue

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,6 @@
2626
<ToggleSwitch v-model="hideAI" />
2727
</div>
2828
</div>
29-
<div class="bg-white rounded-lg shadow-sm dark:bg-gray-800">
30-
<div class="px-4 py-6 flex items-center justify-between">
31-
<div class="flex flex-col max-w-[60%]">
32-
<h3 class="font-medium mb-2 dark:text-gray-300">
33-
Hide Sensitive Content in feeds
34-
</h3>
35-
<p class="text-xs text-gray-500 font-light">
36-
Allow sensitive content to be included in feeds, behind a
37-
content warning.
38-
</p>
39-
</div>
40-
<ToggleSwitch v-model="hideSensitive" />
41-
</div>
42-
</div>
4329
</div>
4430
</section>
4531
</div>
@@ -53,7 +39,6 @@ import ToggleSwitch from '@/components/Form/ToggleSwitch.vue'
5339
5440
const apiClient = useApiClient()
5541
const hideAI = ref(false)
56-
const hideSensitive = ref(false)
5742
const loaded = ref(false)
5843
5944
watch(
@@ -71,26 +56,10 @@ watch(
7156
}
7257
)
7358
74-
watch(
75-
() => hideSensitive.value,
76-
async (newVal, oldVal) => {
77-
if (!loaded.value) {
78-
return
79-
}
80-
if (oldVal === null) return
81-
try {
82-
await apiClient.post('/api/v1/account/settings/content', {
83-
hide_sensitive: newVal
84-
})
85-
} catch {}
86-
}
87-
)
88-
8959
const fetchContentSettings = async () => {
9060
try {
9161
await apiClient.get('/api/v1/account/settings/content').then((res) => {
9262
hideAI.value = res.data.data.hide_ai
93-
hideSensitive.value = res.data.data.hide_sensitive
9463
})
9564
} catch {
9665
} finally {

0 commit comments

Comments
 (0)