|
|
|
@ -31,22 +31,15 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the icon of the given room and return its relative path.
|
|
|
|
|
* @param \CommunityRoom $room
|
|
|
|
|
* @param string $size Image dimensions.
|
|
|
|
|
* @return string Relative path or null if icon is absent.
|
|
|
|
|
* @return \Generator<int,CurlHandle,CurlHandle|false,void>
|
|
|
|
|
*/
|
|
|
|
|
function room_icon(\CommunityRoom $room, string $size): ?string {
|
|
|
|
|
list($width, $height) = explode("x", $size);
|
|
|
|
|
$width = intval($width);
|
|
|
|
|
$height = intval($height);
|
|
|
|
|
assert(!empty($width) && !empty($height));
|
|
|
|
|
function fetch_room_icon_coroutine(\CommunityRoom $room): Generator {
|
|
|
|
|
if (room_icon_safety($room) < 0) {
|
|
|
|
|
return null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$room_id = $room->get_room_identifier();
|
|
|
|
|
$icon_cached = room_icon_path($room_id);
|
|
|
|
|
$icon_resized = room_icon_path_resized($room_id, $size);
|
|
|
|
|
$icon_expired = file_exists($icon_cached) && filemtime($icon_cached) < strtotime("-1 day");
|
|
|
|
|
|
|
|
|
|
// Re-fetch icons periodically.
|
|
|
|
@ -56,7 +49,8 @@
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
log_debug("Fetching icon for $room_id.");
|
|
|
|
|
$icon = file_get_contents($icon_url);
|
|
|
|
|
$icon_response = yield from FetchingCoroutine::from_url($icon_url)->run();
|
|
|
|
|
$icon = $icon_response ? curl_multi_getcontent($icon_response) : null;
|
|
|
|
|
if (empty($icon)) {
|
|
|
|
|
log_info("$room_id returned an empty icon.");
|
|
|
|
|
}
|
|
|
|
@ -65,6 +59,33 @@
|
|
|
|
|
file_put_contents($icon_cached, $icon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the icon of the given room and return its relative path.
|
|
|
|
|
* @param \CommunityRoom $room
|
|
|
|
|
* @param string $size Image dimensions.
|
|
|
|
|
* @return string Relative path or null if icon is absent.
|
|
|
|
|
*/
|
|
|
|
|
function room_icon(\CommunityRoom $room, string $size): ?string {
|
|
|
|
|
list($width, $height) = explode("x", $size);
|
|
|
|
|
$width = intval($width);
|
|
|
|
|
$height = intval($height);
|
|
|
|
|
assert(!empty($width) && !empty($height));
|
|
|
|
|
|
|
|
|
|
if (room_icon_safety($room) < 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$room_id = $room->get_room_identifier();
|
|
|
|
|
$icon_cached = room_icon_path($room_id);
|
|
|
|
|
$icon_resized = room_icon_path_resized($room_id, $size);
|
|
|
|
|
$icon_expired = file_exists($icon_cached) && filemtime($icon_cached) < strtotime("-1 day");
|
|
|
|
|
|
|
|
|
|
if (!file_exists($icon_cached)) {
|
|
|
|
|
log_debug("Missing icon asset for $room_id");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
if (!file_exists($icon_resized) || $icon_expired) {
|
|
|
|
|
$icon_cached_contents = file_get_contents($icon_cached);
|
|
|
|
|
if (empty($icon_cached_contents)) {
|
|
|
|
|