Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communicate the current settings inside Mastodon using an Announcement #44

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 59 additions & 9 deletions includes/class-mastodon-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ public function add_rest_routes() {
'permission_callback' => array( $this, 'public_api_permission' ),
)
);
register_rest_route(
self::PREFIX,
'api/v1/announcements',
array(
'methods' => 'GET',
'callback' => array( $this, 'api_announcements' ),
'permission_callback' => array( $this, 'logged_in_permission' ),
)
);
register_rest_route(
self::PREFIX,
'api/v1/instance/peers',
Expand All @@ -212,6 +221,7 @@ public function add_rest_routes() {
'permission_callback' => array( $this, 'public_api_permission' ),
)
);

register_rest_route(
self::PREFIX,
'api/v2/instance',
Expand All @@ -230,15 +240,6 @@ public function add_rest_routes() {
'permission_callback' => array( $this, 'public_api_permission' ),
)
);
register_rest_route(
self::PREFIX,
'api/v1/announcements',
array(
'methods' => 'GET',
'callback' => '__return_empty_array',
'permission_callback' => array( $this, 'logged_in_permission' ),
)
);
register_rest_route(
self::PREFIX,
'api/v1/follow_requests',
Expand Down Expand Up @@ -2757,6 +2758,55 @@ public function api_nodeinfo() {
return $ret;
}

public function api_announcements() {
$ret = array();

$content = array();
$content[] = sprintf(
// Translators: %1$s is a URL, %2$s is the domain of your blog.
__( 'Using this Mastodon app is made possible by the <a href=%1$s>Enable Mastodon Apps WordPress plugin</a> on %2$s.', 'enable-mastodon-apps' ),
'"https://wordpress.org/plugins/enable-mastodon-apps"',
'<a href="' . home_url() . '">' . get_bloginfo( 'name' ) . '</a>'
);

$content[] = sprintf(
// Translators: %s is the post formats.
_n( 'Posts with the post format <strong>%s</strong> will appear in this app.', 'Posts with the post formats <strong>%s</strong> will appear in this app.', count( $this->app->get_post_formats() ), 'enable-mastodon-apps' ),
implode( ', ', $this->app->get_post_formats() )
);

$content[] = sprintf(
// Translators: %s is the post format.
__( 'If you create a new note in this app, it will be created with the <strong>%s</strong> post format.', 'enable-mastodon-apps' ),
reset( $this->app->get_post_formats() )
);

if ( 'standard' === reset( $this->app->get_post_formats() ) ) {
$content[] = __( 'If you want to create a post in WordPress with a title, add a new line after the title. The first line will then appear as the title of the post.', 'enable-mastodon-apps' );
} else {
$content[] = __( 'Because a new post is not created in the standard post format, it will be published without title. To change this, select the <strong>standard</strong> post format in the Enable Mastodon Apps settings.', 'enable-mastodon-apps' );
}

$ret[] = array(
'id' => 1,
'content' => '<h1><strong>' . __( 'Mastodon Apps', 'enable-mastodon-apps' ) . '</strong></h1><p>' . implode( '</p><p>' . PHP_EOL, $content ) . '</p>',
'published_at' => $this->app->get_creation_date(),
'updated_at' => time(),
'starts_at' => null,
'ends_at' => null,
'all_day' => false,
'read' => true,
'mentions' => array(),
'statuses' => array(),
'tags' => array(),
'emojis' => array(),
'reactions' => array(),

);

return $ret;
}

public function api_instance() {
$ret = array(
'title' => get_bloginfo( 'name' ),
Expand Down