|
|
|
@ -184,14 +184,12 @@
|
|
|
|
|
return $this->language_flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$room_identifier = $this->get_room_identifier();
|
|
|
|
|
$server_pubkey = $this->server->get_pubkey();
|
|
|
|
|
|
|
|
|
|
if (isset($languages[$room_identifier])) {
|
|
|
|
|
return $languages[$room_identifier];
|
|
|
|
|
} elseif (isset($languages[$server_pubkey])) {
|
|
|
|
|
return $languages[$server_pubkey];
|
|
|
|
|
foreach ($languages as $key => $flag) {
|
|
|
|
|
if ($this->matched_by_identifier($key)) {
|
|
|
|
|
return $flag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -397,12 +395,12 @@
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a globally unique room identifier.
|
|
|
|
|
* @return string String in the form `token+pubkey[:4]`.
|
|
|
|
|
* @return string String in the form `token+hex[8]`.
|
|
|
|
|
*/
|
|
|
|
|
function get_room_identifier(): string {
|
|
|
|
|
$token = $this->token;
|
|
|
|
|
$pubkey_4 = substr($this->server->get_pubkey(), 0, 4);
|
|
|
|
|
return "$token+$pubkey_4";
|
|
|
|
|
$server_id = $this->server->get_server_id();
|
|
|
|
|
return "$token+$server_id";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -468,16 +466,60 @@
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether the given identifier matches the current Community or its parent server.
|
|
|
|
|
* @param string $identifier Server pubkey, server ID, server hostname or room ID prefix.
|
|
|
|
|
* @return bool True if the string matches the Community, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
public function matched_by_identifier(string $identifier): bool {
|
|
|
|
|
if ($identifier == "*" ||
|
|
|
|
|
$identifier == $this->server->get_pubkey() ||
|
|
|
|
|
$identifier == $this->server->get_hostname() ||
|
|
|
|
|
$identifier == $this->server->get_server_id()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Legacy identifier check
|
|
|
|
|
return (
|
|
|
|
|
str_starts_with($this->get_room_identifier(), $identifier) &&
|
|
|
|
|
str_contains($identifier, "+")
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether the given list matches the current Community or its parent server.
|
|
|
|
|
* @param string[] $filter
|
|
|
|
|
* Array of unique room identifiers, server pubkeys and/or server hostnames.
|
|
|
|
|
* @param string $matchee String matching room. Output parameter.
|
|
|
|
|
* @return bool True if the array matches the Community, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
public function matched_by_list(array $filter): bool {
|
|
|
|
|
return in_array($this->get_room_identifier(), $filter) ||
|
|
|
|
|
in_array($this->server->get_pubkey(), $filter) ||
|
|
|
|
|
in_array($this->server->get_hostname(), $filter);
|
|
|
|
|
public function matched_by_list(array $filter, string &$matchee): bool {
|
|
|
|
|
foreach ($filter as $filter_item) {
|
|
|
|
|
if ($this->matched_by_identifier($filter_item)) {
|
|
|
|
|
$matchee = $filter_item;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param CommunityRoom[] $rooms
|
|
|
|
|
* @param string[] $filter
|
|
|
|
|
* @param string[] $matchees output parameter
|
|
|
|
|
* @return CommunityRoom[]
|
|
|
|
|
*/
|
|
|
|
|
public static function select_rooms(array $rooms, array|string $filter, array &$matchees): array {
|
|
|
|
|
$_matchees = [];
|
|
|
|
|
$rooms = array_values(array_filter($rooms, function(CommunityRoom $room) use ($filter, $_matchees) {
|
|
|
|
|
$matchee = null;
|
|
|
|
|
$success = $room->matched_by_list($filter, $matchee);
|
|
|
|
|
if ($matchee != null) $_matchees[] = $matchee;
|
|
|
|
|
return $success;
|
|
|
|
|
}));
|
|
|
|
|
$matchees = $_matchees;
|
|
|
|
|
return $rooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|