Browse Source

Update HomeTimelineService, add domain blocks filtering to warmCache method

Daniel Supernault 1 year ago
parent
commit
b3148b788e
1 changed files with 13 additions and 0 deletions
  1. 13 0
      app/Services/HomeTimelineService.php

+ 13 - 0
app/Services/HomeTimelineService.php

@@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Redis;
 use App\Follower;
 use App\Status;
+use App\Models\UserDomainBlock;
 
 class HomeTimelineService
 {
@@ -81,6 +82,8 @@ class HomeTimelineService
                 $following = array_diff($following, $filters);
             }
 
+            $domainBlocks = UserDomainBlock::whereProfileId($id)->pluck('domain')->toArray();
+
             $ids = Status::where('id', '>', $minId)
                 ->whereIn('profile_id', $following)
                 ->whereNull(['in_reply_to_id', 'reblog_of_id'])
@@ -91,6 +94,16 @@ class HomeTimelineService
                 ->pluck('id');
 
             foreach($ids as $pid) {
+                $status = StatusService::get($pid, false);
+                if(!$status || !isset($status['account'], $status['url'])) {
+                    continue;
+                }
+                if($domainBlocks && count($domainBlocks)) {
+                    $domain = strtolower(parse_url($status['url'], PHP_URL_HOST));
+                    if(in_array($domain, $domainBlocks)) {
+                        continue;
+                    }
+                }
                 self::add($id, $pid);
             }