mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-21 19:23:41 +00:00
Bluesky: Handle API error when fetching feeds
This commit is contained in:
parent
b6f2e7dd50
commit
6f56932f12
1 changed files with 16 additions and 1 deletions
|
@ -68,6 +68,7 @@ const BLUEKSY_STATUS_TOKEN_FAIL = 13;
|
||||||
const BLUESKY_DIRECTORY = 'https://plc.directory'; // Path to the directory server service to fetch the PDS of a given DID
|
const BLUESKY_DIRECTORY = 'https://plc.directory'; // Path to the directory server service to fetch the PDS of a given DID
|
||||||
const BLUESKY_PDS = 'https://bsky.social'; // Path to the personal data server service (PDS) to fetch the DID for a given handle
|
const BLUESKY_PDS = 'https://bsky.social'; // Path to the personal data server service (PDS) to fetch the DID for a given handle
|
||||||
const BLUESKY_WEB = 'https://bsky.app'; // Path to the web interface with the user profile and posts
|
const BLUESKY_WEB = 'https://bsky.app'; // Path to the web interface with the user profile and posts
|
||||||
|
const BLUESKY_HOSTNAME = 'bsky.social'; // Host name to be added to the handle if incomplete
|
||||||
|
|
||||||
function bluesky_install()
|
function bluesky_install()
|
||||||
{
|
{
|
||||||
|
@ -1719,6 +1720,9 @@ function bluesky_get_feeds(int $uid): array
|
||||||
{
|
{
|
||||||
$type = '$type';
|
$type = '$type';
|
||||||
$preferences = bluesky_get_preferences($uid);
|
$preferences = bluesky_get_preferences($uid);
|
||||||
|
if (empty($preferences) || empty($preferences->preferences)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
foreach ($preferences->preferences as $preference) {
|
foreach ($preferences->preferences as $preference) {
|
||||||
if ($preference->$type == 'app.bsky.actor.defs#savedFeedsPref') {
|
if ($preference->$type == 'app.bsky.actor.defs#savedFeedsPref') {
|
||||||
return $preference->pinned ?? [];
|
return $preference->pinned ?? [];
|
||||||
|
@ -1727,7 +1731,7 @@ function bluesky_get_feeds(int $uid): array
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function bluesky_get_preferences(int $uid): stdClass
|
function bluesky_get_preferences(int $uid): ?stdClass
|
||||||
{
|
{
|
||||||
$cachekey = 'bluesky:preferences:' . $uid;
|
$cachekey = 'bluesky:preferences:' . $uid;
|
||||||
$data = DI::cache()->get($cachekey);
|
$data = DI::cache()->get($cachekey);
|
||||||
|
@ -1736,6 +1740,9 @@ function bluesky_get_preferences(int $uid): stdClass
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = bluesky_xrpc_get($uid, 'app.bsky.actor.getPreferences');
|
$data = bluesky_xrpc_get($uid, 'app.bsky.actor.getPreferences');
|
||||||
|
if (empty($data)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
DI::cache()->set($cachekey, $data, Duration::HOUR);
|
DI::cache()->set($cachekey, $data, Duration::HOUR);
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -1778,6 +1785,14 @@ function bluesky_get_did_by_dns(string $handle): string
|
||||||
|
|
||||||
function bluesky_get_did(string $handle): string
|
function bluesky_get_did(string $handle): string
|
||||||
{
|
{
|
||||||
|
if ($handle == '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($handle, '.') === false) {
|
||||||
|
$handle .= '.' . BLUESKY_HOSTNAME;
|
||||||
|
}
|
||||||
|
|
||||||
// Deactivated at the moment, since it isn't reliable by now
|
// Deactivated at the moment, since it isn't reliable by now
|
||||||
//$did = bluesky_get_did_by_dns($handle);
|
//$did = bluesky_get_did_by_dns($handle);
|
||||||
//if ($did != '') {
|
//if ($did != '') {
|
||||||
|
|
Loading…
Reference in a new issue