]> git.mxchange.org Git - friendica-addons.git/commitdiff
Bluesky: Support Restrictions / Updated Friendica handle description
authorMichael <heluecht@pirati.ca>
Thu, 21 Mar 2024 07:40:46 +0000 (07:40 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 22 Mar 2024 05:32:17 +0000 (05:32 +0000)
bluesky/bluesky.php
bluesky/lang/C/messages.po

index fe66d9a4578d9d77904aae3ab694227f57058c2f..2cd2d263c6b691811d19f4178395b23512c1bc95 100644 (file)
@@ -323,7 +323,7 @@ function bluesky_addon_admin(string &$o)
 
        $o = Renderer::replaceMacros($t, [
                '$submit' => DI::l10n()->t('Save Settings'),
-               '$friendica_handles'    => ['friendica_handles', DI::l10n()->t('Allow your users to use your hostname for their Bluesky handles'), DI::config()->get('bluesky', 'friendica_handles'), DI::l10n()->t('Before enabling this option, you have to download and configure the bluesky-handles repository on your system. See https://git.friendi.ca/heluecht/bluesky-handles')],
+               '$friendica_handles'    => ['friendica_handles', DI::l10n()->t('Allow your users to use your hostname for their Bluesky handles'), DI::config()->get('bluesky', 'friendica_handles'), DI::l10n()->t('Before enabling this option, you have to setup a wildcard domain configuration and you have to enable wildcard requests in your webserver configuration. On Apache this is done by adding "ServerAlias *.%s" to your HTTP configuration. You don\'t need to change the HTTPS configuration.', DI::baseUrl()->getHost())],
        ]);
 }
 
@@ -525,8 +525,8 @@ function bluesky_cron()
                // Refresh the token now, so that it doesn't need to be refreshed in parallel by the following workers
                bluesky_get_token($pconfig['uid']);
 
-               Worker::add(['priority' => Worker::PRIORITY_MEDIUM, 'force_priority' => true], 'addon/bluesky/bluesky_timeline.php', $pconfig['uid'], $last);
                Worker::add(['priority' => Worker::PRIORITY_MEDIUM, 'force_priority' => true], 'addon/bluesky/bluesky_notifications.php', $pconfig['uid'], $last);
+               Worker::add(['priority' => Worker::PRIORITY_MEDIUM, 'force_priority' => true], 'addon/bluesky/bluesky_timeline.php', $pconfig['uid'], $last);
 
                if (DI::pConfig()->get($pconfig['uid'], 'bluesky', 'import_feeds')) {
                        $feeds = bluesky_get_feeds($pconfig['uid']);
@@ -1176,6 +1176,8 @@ function bluesky_process_post(stdClass $post, int $uid, int $fetch_uid, int $pos
                $item = bluesky_add_media($post->embed, $item, $uid, $level, $last_poll);
        }
 
+       $item['restrictions'] = bluesky_get_restrictions_for_user($post, $item, $post_reason);
+
        if (empty($item['post-reason'])) {
                $item['post-reason'] = $post_reason;
        }
@@ -1223,6 +1225,49 @@ function bluesky_get_header(stdClass $post, string $uri, int $uid, int $fetch_ui
        return $item;
 }
 
+function bluesky_get_restrictions_for_user(stdClass $post, array $item, int $post_reason): ?int
+{
+       if (!empty($post->viewer->replyDisabled)) {
+               return Item::CANT_REPLY;
+       }
+
+       if(empty($post->threadgate)) {
+               return null;
+       }
+
+       if (!isset($post->threadgate->record->allow)) {
+               return null;
+       }
+
+       if ($item['uid'] == 0) {
+               return Item::CANT_REPLY;
+       }
+
+       $restrict = true;
+       $type = '$type';
+       foreach ($post->threadgate->record->allow as $allow) {
+               switch ($allow->$type) {
+                       case 'app.bsky.feed.threadgate#followingRule':
+                               // Only followers can reply.
+                               if (Contact::isFollower($item['author-id'], $item['uid'])) {
+                                       $restrict = false;
+                               }
+                               break;
+                       case 'app.bsky.feed.threadgate#mentionRule':
+                               // Only mentioned accounts can reply.
+                               if ($post_reason == Item::PR_TO) {
+                                       $restrict = false;
+                               }
+                               break;
+                       case 'app.bsky.feed.threadgate#listRule';
+                               // Only accounts in the provided list can reply. We don't support this at the moment.
+                               break;
+               }
+       }
+
+       return $restrict ? Item::CANT_REPLY : null;
+}
+
 function bluesky_get_content(array $item, stdClass $record, string $uri, int $uid, int $fetch_uid, int $level, int $last_poll): array
 {
        if (empty($item)) {
index 0d69cc102a0fa181d2354f79cecd8fe3a718a04e..9521ab89c8365fb204a3d0eda98e0ac950036140 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: \n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2024-02-28 03:05+0000\n"
+"POT-Creation-Date: 2024-03-22 05:31+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -26,10 +26,12 @@ msgid "Allow your users to use your hostname for their Bluesky handles"
 msgstr ""
 
 #: bluesky.php:326
+#, php-format
 msgid ""
-"Before enabling this option, you have to download and configure the bluesky-"
-"handles repository on your system. See https://git.friendi.ca/heluecht/"
-"bluesky-handles"
+"Before enabling this option, you have to setup a wildcard domain "
+"configuration and you have to enable wildcard requests in your webserver "
+"configuration. On Apache this is done by adding \"ServerAlias *.%s\" to your "
+"HTTP configuration. You don't need to change the HTTPS configuration."
 msgstr ""
 
 #: bluesky.php:354