Skip to content

Commit

Permalink
Update profile audience to filter blocked instances
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Dec 31, 2022
1 parent e99b412 commit e0c3dae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
32 changes: 25 additions & 7 deletions app/Services/FollowerService.php
Expand Up @@ -34,8 +34,8 @@ public static function remove($actor, $target)
{
Redis::zrem(self::FOLLOWING_KEY . $actor, $target);
Redis::zrem(self::FOLLOWERS_KEY . $target, $actor);
Cache::forget('pf:services:follow:audience:' . $actor);
Cache::forget('pf:services:follow:audience:' . $target);
Cache::forget('pf:services:follower:audience:' . $actor);
Cache::forget('pf:services:follower:audience:' . $target);
AccountService::del($actor);
AccountService::del($target);
RelationshipService::refresh($actor, $target);
Expand Down Expand Up @@ -151,9 +151,9 @@ public static function softwareAudience($profile, $software = 'pixelfed')

protected function getAudienceInboxes($pid, $scope = null)
{
$key = 'pf:services:follow:audience:' . $pid;
return Cache::remember($key, 86400, function() use($pid) {
$profile = Profile::find($pid);
$key = 'pf:services:follower:audience:' . $pid;
$domains = Cache::remember($key, 432000, function() use($pid) {
$profile = Profile::whereNull(['status', 'domain'])->find($pid);
if(!$profile) {
return [];
}
Expand All @@ -165,9 +165,27 @@ protected function getAudienceInboxes($pid, $scope = null)
})
->filter()
->unique()
->values()
->toArray();
->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()
->toArray();

return $res;
}

public static function mutualCount($pid, $mid)
Expand Down
6 changes: 3 additions & 3 deletions app/Services/InstanceService.php
Expand Up @@ -20,21 +20,21 @@ public static function getByDomain($domain)

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();
});
}

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();
});
}

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();
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/Services/RelationshipService.php
Expand Up @@ -57,8 +57,8 @@ public static function delete($aid, $tid)

public static function refresh($aid, $tid)
{
Cache::forget('pf:services:follow:audience:' . $aid);
Cache::forget('pf:services:follow:audience:' . $tid);
Cache::forget('pf:services:follower:audience:' . $aid);
Cache::forget('pf:services:follower:audience:' . $tid);
self::delete($tid, $aid);
self::delete($aid, $tid);
self::get($tid, $aid);
Expand Down

0 comments on commit e0c3dae

Please sign in to comment.