De-syndicate posts

This commit is contained in:
2024-01-30 20:29:51 +11:00
parent 4833ae01c1
commit 6569060ba0
6 changed files with 78 additions and 0 deletions

View 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

View 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

View File

@@ -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")

View File

@@ -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"