Merge pull request 'Bluesky/Tumblr: Improved statistics' (#1530) from heluecht/friendica-addons:stats2 into 2024.06-rc

Reviewed-on: #1530
This commit is contained in:
Tobias Diekershoff 2024-08-14 08:09:37 +02:00
commit 4ad7d61893
2 changed files with 26 additions and 19 deletions

View file

@ -294,9 +294,9 @@ function bluesky_block(array &$hook_data)
$activity = bluesky_xrpc_post($hook_data['uid'], 'com.atproto.repo.createRecord', $post);
if (!empty($activity->uri)) {
$cdata = Contact::getPublicAndUserContactID($hook_data['contact']['id'], $hook_data['uid']);
if (!empty($cdata['user'])) {
Contact::remove($cdata['user']);
$ucid = Contact::getUserContactId($hook_data['contact']['id'], $hook_data['uid']);
if ($ucid) {
Contact::remove($ucid);
}
Logger::debug('Successfully blocked contact', ['url' => $hook_data['contact']['url'], 'uri' => $activity->uri]);
}
@ -975,6 +975,7 @@ function bluesky_upload_blob(int $uid, array $photo): ?stdClass
return null;
}
Item::incrementOutbound(Protocol::BLUESKY);
Logger::debug('Uploaded blob', ['return' => $data, 'uid' => $uid, 'retrial' => $retrial, 'height' => $new_height, 'width' => $new_width, 'size' => $new_size, 'orig-height' => $height, 'orig-width' => $width, 'orig-size' => $size]);
return $data->blob;
}
@ -1048,8 +1049,8 @@ function bluesky_process_reason(stdClass $reason, string $uri, int $uid)
$item['owner-link'] = $item['author-link'];
$item['owner-avatar'] = $item['author-avatar'];
if (Item::insert($item)) {
$cdata = Contact::getPublicAndUserContactID($contact['id'], $uid);
Item::update(['post-reason' => Item::PR_ANNOUNCEMENT, 'causer-id' => $cdata['public']], ['uri' => $uri, 'uid' => $uid]);
$pcid = Contact::getPublicContactId($contact['id'], $uid);
Item::update(['post-reason' => Item::PR_ANNOUNCEMENT, 'causer-id' => $pcid], ['uri' => $uri, 'uid' => $uid]);
}
}
@ -1537,8 +1538,7 @@ function bluesky_fetch_missing_post(string $uri, int $uid, int $fetch_uid, int $
Logger::debug('Reply count', ['level' => $level, 'uid' => $uid, 'uri' => $uri]);
if ($causer != 0) {
$cdata = Contact::getPublicAndUserContactID($causer, $uid);
$causer = $cdata['public'] ?? 0;
$causer = Contact::getPublicContactId($causer, $uid);
}
return bluesky_process_thread($data->thread, $uid, $fetch_uid, $post_reason, $causer, $level, $last_poll);
@ -1936,7 +1936,11 @@ function bluesky_create_token(int $uid, string $password): string
function bluesky_xrpc_post(int $uid, string $url, $parameters): ?stdClass
{
return bluesky_post($uid, '/xrpc/' . $url, json_encode($parameters), ['Content-type' => 'application/json', 'Authorization' => ['Bearer ' . bluesky_get_token($uid)]]);
$data = bluesky_post($uid, '/xrpc/' . $url, json_encode($parameters), ['Content-type' => 'application/json', 'Authorization' => ['Bearer ' . bluesky_get_token($uid)]]);
if (!empty($data)) {
Item::incrementOutbound(Protocol::BLUESKY);
}
return $data;
}
function bluesky_post(int $uid, string $url, string $params, array $headers): ?stdClass
@ -1946,7 +1950,6 @@ function bluesky_post(int $uid, string $url, string $params, array $headers): ?s
return null;
}
Item::incrementOutbound(Protocol::BLUESKY);
try {
$curlResult = DI::httpClient()->post($pds . $url, $params, $headers);
} catch (\Exception $e) {
@ -1983,7 +1986,6 @@ function bluesky_xrpc_get(int $uid, string $url, array $parameters = []): ?stdCl
function bluesky_get(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ?stdClass
{
Item::incrementInbound(Protocol::BLUESKY);
try {
$curlResult = DI::httpClient()->get($url, $accept_content, $opts);
} catch (\Exception $e) {
@ -1996,5 +1998,6 @@ function bluesky_get(string $url, string $accept_content = HttpClientAccept::DEF
return null;
}
Item::incrementInbound(Protocol::BLUESKY);
return json_decode($curlResult->getBodyString());
}

View file

@ -133,6 +133,7 @@ function tumblr_item_by_link(array &$hookData)
Logger::debug('Got post', ['blog' => $matches[1], 'id' => $matches[2], 'result' => $result->response->posts]);
if (!empty($result->response->posts)) {
$hookData['item_id'] = tumblr_process_post($result->response->posts[0], $hookData['uid'], Item::PR_FETCHED);
Item::incrementInbound(Protocol::TUMBLR);
}
}
@ -203,9 +204,9 @@ function tumblr_block(array &$hook_data)
$hook_data['result'] = ($result->meta->status <= 399);
if ($hook_data['result']) {
$cdata = Contact::getPublicAndUserContactID($hook_data['contact']['id'], $hook_data['uid']);
if (!empty($cdata['user'])) {
Contact::remove($cdata['user']);
$ucid = Contact::getUserContactId($hook_data['contact']['id'], $hook_data['uid']);
if ($ucid) {
Contact::remove($ucid);
}
}
}
@ -238,9 +239,7 @@ function tumblr_get_contact_uuid(array $contact): string
* existence of this method is checked to figure out if the addon offers a
* module.
*/
function tumblr_module()
{
}
function tumblr_module() {}
function tumblr_content()
{
@ -756,6 +755,7 @@ function tumblr_fetch_tags(int $uid, int $last_poll)
$post = Post::selectFirst(['uri-id'], ['id' => $id]);
$stored = Post\Category::storeFileByURIId($post['uri-id'], $uid, Post\Category::SUBCRIPTION, $tag);
Logger::debug('Stored tag subscription for user', ['uri-id' => $post['uri-id'], 'uid' => $uid, 'tag' => $tag, 'stored' => $stored]);
Item::incrementInbound(Protocol::TUMBLR);
}
}
}
@ -795,6 +795,7 @@ function tumblr_fetch_dashboard(int $uid, int $last_poll)
Logger::debug('Importing post', ['uid' => $uid, 'created' => date(DateTimeFormat::MYSQL, $post->timestamp), 'id' => $post->id_string]);
tumblr_process_post($post, $uid, Item::PR_NONE, $last_poll);
Item::incrementInbound(Protocol::TUMBLR);
DI::pConfig()->set($uid, 'tumblr', 'last_id', $last);
}
@ -1167,6 +1168,7 @@ function tumblr_get_contact_fields(stdClass $blog, int $uid, bool $update): arra
Logger::notice('Error fetching blog info', ['meta' => $info->meta, 'response' => $info->response, 'errors' => $info->errors]);
return $fields;
}
Item::incrementInbound(Protocol::TUMBLR);
$avatar = $info->response->blog->avatar;
if (!empty($avatar)) {
@ -1231,6 +1233,8 @@ function tumblr_get_blogs(int $uid): array
return [];
}
Item::incrementInbound(Protocol::TUMBLR);
$blogs = [];
foreach ($userinfo->response->user->blogs as $blog) {
$blogs[$blog->uuid] = $blog->name;
@ -1287,10 +1291,11 @@ function tumblr_get_contact_by_url(string $url, int $uid): ?array
if ($info->meta->status > 399) {
Logger::notice('Error fetching blog info', ['meta' => $info->meta, 'response' => $info->response, 'errors' => $info->errors, 'blog' => $blog, 'uid' => $uid]);
return null;
} else {
Logger::debug('Got data', ['blog' => $blog, 'meta' => $info->meta]);
}
Logger::debug('Got data', ['blog' => $blog, 'meta' => $info->meta]);
Item::incrementInbound(Protocol::TUMBLR);
$baseurl = 'https://tumblr.com';
$url = $baseurl . '/' . $info->response->blog->name;
@ -1326,7 +1331,6 @@ function tumblr_get_contact_by_url(string $url, int $uid): ?array
*/
function tumblr_get(int $uid, string $url, array $parameters = []): stdClass
{
Item::incrementInbound(Protocol::TUMBLR);
$url = 'https://api.tumblr.com/v2/' . $url;
if ($uid == 0) {