De-syndicate posts
This commit is contained in:
@@ -78,6 +78,27 @@ module Adamantium
|
||||
JSON.parse(response.body, symbolize_names: true).fetch(:id, nil)
|
||||
end
|
||||
|
||||
def remove_post(post_id:)
|
||||
unless settings.mastodon_token && settings.mastodon_server
|
||||
return Failure(:no_mastodon_credentials)
|
||||
end
|
||||
|
||||
mastodon_token = settings.mastodon_token
|
||||
mastodon_server = settings.mastodon_server.split("@").first
|
||||
response = HTTParty.delete("#{mastodon_server}api/v1/statuses/#{post_id}", {
|
||||
headers: {
|
||||
"Idempotency-Key": key,
|
||||
Authorization: "Bearer #{mastodon_token}"
|
||||
}
|
||||
})
|
||||
|
||||
if response.code >= 200 && response.code < 300
|
||||
Success(post_id)
|
||||
else
|
||||
Failure(response.message)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sanitze_post(content)
|
||||
|
@@ -20,6 +20,16 @@ module Adamantium
|
||||
Failure(:failed_to_syndicate)
|
||||
end
|
||||
end
|
||||
|
||||
def de_syndicate(post_id:)
|
||||
response = mastodon_client.remove_post(post_id: post_id)
|
||||
|
||||
if response.success?
|
||||
Success(response.value!)
|
||||
else
|
||||
Failure(:failed_to_de_syndicate)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
15
slices/admin/actions/posts/de_syndicate.rb
Normal file
15
slices/admin/actions/posts/de_syndicate.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Actions
|
||||
module Posts
|
||||
class DeSyndicate < Admin::Action
|
||||
include Deps["commands.posts.de_syndicate"]
|
||||
|
||||
def handle(req, res)
|
||||
de_syndicate.call(post_id: req.params[:id], target: req.params[:target])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
slices/admin/commands/posts/de_syndicate.rb
Normal file
29
slices/admin/commands/posts/de_syndicate.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
require "readability"
|
||||
require "down"
|
||||
|
||||
module Admin
|
||||
module Commands
|
||||
module Posts
|
||||
class DeSyndicate
|
||||
include Dry::Monads[:result]
|
||||
include Deps["repos.post_repo", "syndication.mastodon"]
|
||||
|
||||
def call(post_id:, target:)
|
||||
post = post_repo.find(id: post_id)
|
||||
|
||||
request = if target.to_sym == :mastodon
|
||||
masto_id = post.syndication_sources[target].split("/").last
|
||||
mastodon.de_syndicate(post_id: masto_id)
|
||||
end
|
||||
|
||||
if request.success?
|
||||
post.syndication_sources.delete(target)
|
||||
post_repo.update(post_id, post)
|
||||
end
|
||||
|
||||
Success()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -49,6 +49,7 @@ module Admin
|
||||
post "/posts/:id/publish", to: Auth.call(action: "posts.publish")
|
||||
get "/posts/:id", to: Auth.call(action: "posts.show")
|
||||
post "/posts/:id/syndicate/add_source", to: Auth.call(action: "posts.add_syndication_source")
|
||||
post "/posts/:id/de_syndicate/:target", to: Auth.call(action: "posts.de_syndicate")
|
||||
post "/posts/:id/syndicate/:target", to: Auth.call(action: "posts.syndicate")
|
||||
post "/post/:id/update", to: Auth.call(action: "posts.update")
|
||||
|
||||
|
@@ -6,6 +6,8 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:
|
||||
li
|
||||
a href=url
|
||||
= name
|
||||
= " — "
|
||||
button hx-swap="afterend" hx-post="/admin/posts/#{post.id}/de_syndicate/#{name}" de-syndicate
|
||||
form hx-post="/admin/posts/#{post.id}/syndicate/add_source"
|
||||
span class="mr-2"
|
||||
label for="syndication_source_name"
|
||||
|
Reference in New Issue
Block a user