cachePrefix . 'blocked_domains'; if (! ($found = cache($cacheName))) { $found = $this->findAll(); cache() ->save($cacheName, $found, DECADE); } return $found; } public function isDomainBlocked(string $name): bool { $hashedDomainName = md5($name); $cacheName = config(Fediverse::class) ->cachePrefix . "domain#{$hashedDomainName}_isBlocked"; if (! ($found = cache($cacheName))) { $found = (bool) $this->find($name); cache() ->save($cacheName, $found, DECADE); } return $found; } public function blockDomain(string $name): int | bool { $hashedDomain = md5($name); $prefix = config(Fediverse::class) ->cachePrefix; cache() ->delete($prefix . "domain#{$hashedDomain}_isBlocked"); cache() ->delete($prefix . 'blocked_domains'); cache() ->deleteMatching($prefix . '*replies'); $this->db->transStart(); // set all actors from the domain as blocked model('ActorModel', false) ->where('domain', $name) ->set('is_blocked', '1') ->update(); $result = $this->insert([ 'name' => $name, ]); Events::trigger('on_block_domain', $name); $this->db->transComplete(); return $result; } public function unblockDomain(string $name): BaseResult | bool { $hashedDomain = md5($name); $prefix = config(Fediverse::class) ->cachePrefix; cache() ->delete($prefix . "domain#{$hashedDomain}_isBlocked"); cache() ->delete($prefix . 'blocked_domains'); cache() ->deleteMatching($prefix . '*replies'); $this->db->transStart(); // unblock all actors from the domain model('ActorModel', false) ->where('domain', $name) ->set('is_blocked', '0') ->update(); $result = $this->delete($name); Events::trigger('on_unblock_domain', $name); $this->db->transComplete(); return $result; } }