Save syndication sources to posts
This commit is contained in:
18
app/commands/posts/add_syndication_source.rb
Normal file
18
app/commands/posts/add_syndication_source.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Adamantium
|
||||
module Commands
|
||||
module Posts
|
||||
class AddSyndicationSource
|
||||
include Deps["repos.post_repo"]
|
||||
|
||||
def call(post_id, source, url)
|
||||
post = post_repo.find!(post_id).to_h
|
||||
syndication_sources = post[:syndication_sources] || {}
|
||||
syndication_sources[source] = url
|
||||
post[:syndication_sources] = syndication_sources
|
||||
|
||||
post_repo.update(post_id, post)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,12 +1,20 @@
|
||||
require "dry/monads"
|
||||
require "dry/monads/do"
|
||||
|
||||
module Adamantium
|
||||
module Commands
|
||||
module Posts
|
||||
class Syndicate
|
||||
include Dry::Monads[:result]
|
||||
include Dry::Monads::Do.for(:call)
|
||||
|
||||
include Deps["settings", "syndication.mastodon"]
|
||||
|
||||
def call(post)
|
||||
if post[:syndicate_to].any? { |url| settings.mastodon_server.match(/#{url}/) }
|
||||
mastodon.call(post: post)
|
||||
url = yield mastodon.call(post: post)
|
||||
|
||||
Success([:mastodon, url])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user