Update profile audience to filter blocked instances

This commit is contained in:
Daniel Supernault 2022-12-31 06:25:43 -07:00
parent e99b41292a
commit e0c3dae324
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 30 additions and 12 deletions

View file

@ -34,8 +34,8 @@ class FollowerService
{ {
Redis::zrem(self::FOLLOWING_KEY . $actor, $target); Redis::zrem(self::FOLLOWING_KEY . $actor, $target);
Redis::zrem(self::FOLLOWERS_KEY . $target, $actor); Redis::zrem(self::FOLLOWERS_KEY . $target, $actor);
Cache::forget('pf:services:follow:audience:' . $actor); Cache::forget('pf:services:follower:audience:' . $actor);
Cache::forget('pf:services:follow:audience:' . $target); Cache::forget('pf:services:follower:audience:' . $target);
AccountService::del($actor); AccountService::del($actor);
AccountService::del($target); AccountService::del($target);
RelationshipService::refresh($actor, $target); RelationshipService::refresh($actor, $target);
@ -151,9 +151,9 @@ class FollowerService
protected function getAudienceInboxes($pid, $scope = null) protected function getAudienceInboxes($pid, $scope = null)
{ {
$key = 'pf:services:follow:audience:' . $pid; $key = 'pf:services:follower:audience:' . $pid;
return Cache::remember($key, 86400, function() use($pid) { $domains = Cache::remember($key, 432000, function() use($pid) {
$profile = Profile::find($pid); $profile = Profile::whereNull(['status', 'domain'])->find($pid);
if(!$profile) { if(!$profile) {
return []; return [];
} }
@ -165,9 +165,27 @@ class FollowerService
}) })
->filter() ->filter()
->unique() ->unique()
->values();
});
if(!$domains || !$domains->count()) {
return [];
}
$banned = InstanceService::getBannedDomains();
if(!$banned || count($banned) === 0) {
return $domains->toArray();
}
$res = $domains->filter(function($domain) use($banned) {
$parsed = parse_url($domain, PHP_URL_HOST);
return !in_array($parsed, $banned);
})
->values() ->values()
->toArray(); ->toArray();
});
return $res;
} }
public static function mutualCount($pid, $mid) public static function mutualCount($pid, $mid)

View file

@ -20,21 +20,21 @@ class InstanceService
public static function getBannedDomains() public static function getBannedDomains()
{ {
return Cache::remember(self::CACHE_KEY_BANNED_DOMAINS, now()->addHours(12), function() { return Cache::remember(self::CACHE_KEY_BANNED_DOMAINS, 1209600, function() {
return Instance::whereBanned(true)->pluck('domain')->toArray(); return Instance::whereBanned(true)->pluck('domain')->toArray();
}); });
} }
public static function getUnlistedDomains() public static function getUnlistedDomains()
{ {
return Cache::remember(self::CACHE_KEY_UNLISTED_DOMAINS, now()->addHours(12), function() { return Cache::remember(self::CACHE_KEY_UNLISTED_DOMAINS, 1209600, function() {
return Instance::whereUnlisted(true)->pluck('domain')->toArray(); return Instance::whereUnlisted(true)->pluck('domain')->toArray();
}); });
} }
public static function getNsfwDomains() public static function getNsfwDomains()
{ {
return Cache::remember(self::CACHE_KEY_NSFW_DOMAINS, now()->addHours(12), function() { return Cache::remember(self::CACHE_KEY_NSFW_DOMAINS, 1209600, function() {
return Instance::whereAutoCw(true)->pluck('domain')->toArray(); return Instance::whereAutoCw(true)->pluck('domain')->toArray();
}); });
} }

View file

@ -57,8 +57,8 @@ class RelationshipService
public static function refresh($aid, $tid) public static function refresh($aid, $tid)
{ {
Cache::forget('pf:services:follow:audience:' . $aid); Cache::forget('pf:services:follower:audience:' . $aid);
Cache::forget('pf:services:follow:audience:' . $tid); Cache::forget('pf:services:follower:audience:' . $tid);
self::delete($tid, $aid); self::delete($tid, $aid);
self::delete($aid, $tid); self::delete($aid, $tid);
self::get($tid, $aid); self::get($tid, $aid);