Add replies to posts
This commit is contained in:
9
db/migrate/20240321211120_add_in_reply_to_to_posts.rb
Normal file
9
db/migrate/20240321211120_add_in_reply_to_to_posts.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
ROM::SQL.migration do
|
||||||
|
change do
|
||||||
|
alter_table :posts do
|
||||||
|
add_column :in_reply_to, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -4,7 +4,7 @@ require "que"
|
|||||||
module Adamantium
|
module Adamantium
|
||||||
module Jobs
|
module Jobs
|
||||||
class SendWebMentions < Que::Job
|
class SendWebMentions < Que::Job
|
||||||
def run(post_content:, post_url:)
|
def run(post_content:, post_url:, in_reply_to:)
|
||||||
link_finder = Admin::Container["post_utilities.link_finder"]
|
link_finder = Admin::Container["post_utilities.link_finder"]
|
||||||
settings = Admin::Container["settings"]
|
settings = Admin::Container["settings"]
|
||||||
|
|
||||||
@@ -17,6 +17,15 @@ module Adamantium
|
|||||||
target: target
|
target: target
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
links = link_finder.call(in_reply_to)
|
||||||
|
links.each do |target|
|
||||||
|
HTTParty.post(settings.webmention_url, {
|
||||||
|
token: settings.webmention_token,
|
||||||
|
source: source,
|
||||||
|
target: target
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -9,6 +9,7 @@ module Adamantium
|
|||||||
youtube.com
|
youtube.com
|
||||||
bsky.app
|
bsky.app
|
||||||
bsky.social
|
bsky.social
|
||||||
|
localhost
|
||||||
github.com].freeze
|
github.com].freeze
|
||||||
|
|
||||||
def call(content)
|
def call(content)
|
||||||
|
@@ -192,6 +192,17 @@ module Main
|
|||||||
.one!
|
.one!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch(slug)
|
||||||
|
posts
|
||||||
|
.published
|
||||||
|
.combine(:tags, :trips, :webmentions)
|
||||||
|
.node(:webmentions) { |webmention|
|
||||||
|
webmention.published.where(type: "reply")
|
||||||
|
}
|
||||||
|
.where(slug: slug)
|
||||||
|
.one
|
||||||
|
end
|
||||||
|
|
||||||
def find!(id)
|
def find!(id)
|
||||||
posts
|
posts
|
||||||
.by_pk(id)
|
.by_pk(id)
|
||||||
|
@@ -17,6 +17,13 @@ article class="h-entry"
|
|||||||
h1 class="p-name mb-2"
|
h1 class="p-name mb-2"
|
||||||
a class="u-url" href=post.permalink
|
a class="u-url" href=post.permalink
|
||||||
= post.display_title
|
= post.display_title
|
||||||
|
- if post.in_reply_to
|
||||||
|
div class=""
|
||||||
|
em = "In reply to: "
|
||||||
|
- if reply_in_context
|
||||||
|
a class="no-underline bg-pink-50 hover:bg-pink-100 dark:bg-pink-600 hover:dark:bg-pink-900 p-1 rounded" href=post.in_reply_to #{reply_in_context.display_title}
|
||||||
|
- else
|
||||||
|
a class="no-underline bg-pink-50 hover:bg-pink-100 dark:bg-pink-600 hover:dark:bg-pink-900 p-1 rounded" href=post.in_reply_to #{post.in_reply_to}
|
||||||
nav class="space-x-1 text-sm md:text-sm md:block dark:text-gray-600"
|
nav class="space-x-1 text-sm md:text-sm md:block dark:text-gray-600"
|
||||||
- if post.location || post.photos? || post.videos?
|
- if post.location || post.photos? || post.videos?
|
||||||
span See more:
|
span See more:
|
||||||
|
@@ -4,7 +4,7 @@ module Main
|
|||||||
module Views
|
module Views
|
||||||
module Posts
|
module Posts
|
||||||
class Show < Main::View
|
class Show < Main::View
|
||||||
include Deps["repos.post_repo", "repos.movie_repo"]
|
include Deps["repos.post_repo", "repos.movie_repo", "settings"]
|
||||||
|
|
||||||
expose :post do |slug:|
|
expose :post do |slug:|
|
||||||
Decorators::Posts::Decorator.new(post_repo.fetch!(slug))
|
Decorators::Posts::Decorator.new(post_repo.fetch!(slug))
|
||||||
@@ -35,6 +35,13 @@ module Main
|
|||||||
expose :trip do |post|
|
expose :trip do |post|
|
||||||
post.trips.first
|
post.trips.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
expose :reply_in_context do |post|
|
||||||
|
if post.in_reply_to&.match settings.micropub_site_url
|
||||||
|
slug = post.in_reply_to.split("/").last
|
||||||
|
Decorators::Posts::Decorator.new(post_repo.fetch(slug))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -24,7 +24,7 @@ module Micropub
|
|||||||
|
|
||||||
decorated_post = Decorators::Posts::Decorator.new(created_post)
|
decorated_post = Decorators::Posts::Decorator.new(created_post)
|
||||||
|
|
||||||
send_webmentions.call(post_content: created_post.content, post_url: decorated_post.permalink)
|
send_webmentions.call(post_content: created_post.content, post_url: decorated_post.permalink, in_reply_to: created_post.in_reply_to)
|
||||||
|
|
||||||
Success(created_post)
|
Success(created_post)
|
||||||
end
|
end
|
||||||
|
@@ -7,10 +7,10 @@ module Micropub
|
|||||||
class SendWebmentions
|
class SendWebmentions
|
||||||
include Deps["settings", "post_utilities.link_finder"]
|
include Deps["settings", "post_utilities.link_finder"]
|
||||||
|
|
||||||
def call(post_content:, post_url:)
|
def call(post_content:, post_url:, in_reply_to:)
|
||||||
Que.connection = Adamantium::Container["persistence.db"]
|
Que.connection = Adamantium::Container["persistence.db"]
|
||||||
|
|
||||||
Adamantium::Jobs::SendWebMentions.enqueue(post_content: post_content, post_url: post_url)
|
Adamantium::Jobs::SendWebMentions.enqueue(post_content: post_content, post_url: post_url, in_reply_to: in_reply_to)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -10,6 +10,7 @@ module Micropub
|
|||||||
attribute :published_at, Types::Nominal::DateTime.optional
|
attribute :published_at, Types::Nominal::DateTime.optional
|
||||||
attribute :post_type, Types::Coercible::String
|
attribute :post_type, Types::Coercible::String
|
||||||
attribute :syndicate_to, Types::Array.of(Types::Coercible::String)
|
attribute :syndicate_to, Types::Array.of(Types::Coercible::String)
|
||||||
|
attribute :in_reply_to, Types::Coercible::String
|
||||||
attribute :photos, Types::Array.of(Types::Hash)
|
attribute :photos, Types::Array.of(Types::Hash)
|
||||||
attribute :location, Types::Coercible::String.optional
|
attribute :location, Types::Coercible::String.optional
|
||||||
end
|
end
|
||||||
|
@@ -97,6 +97,7 @@ module Micropub
|
|||||||
content: content,
|
content: content,
|
||||||
slug: params[:slug] || params[:"mp-slug"],
|
slug: params[:slug] || params[:"mp-slug"],
|
||||||
syndicate_to: Array(params[:properties][:"mp-syndicate-to"]) || [],
|
syndicate_to: Array(params[:properties][:"mp-syndicate-to"]) || [],
|
||||||
|
in_reply_to: params[:properties][:"in-reply-to"] || nil,
|
||||||
photos: photos,
|
photos: photos,
|
||||||
location: params[:properties][:location]
|
location: params[:properties][:location]
|
||||||
})
|
})
|
||||||
@@ -119,6 +120,7 @@ module Micropub
|
|||||||
|
|
||||||
new_params.merge({
|
new_params.merge({
|
||||||
syndicate_to: Array(params[:"mp-syndicate-to"]) || [],
|
syndicate_to: Array(params[:"mp-syndicate-to"]) || [],
|
||||||
|
in_reply_to: params[:"in-reply-to"],
|
||||||
name: params[:name],
|
name: params[:name],
|
||||||
slug: params[:slug] || params[:"mp-slug"],
|
slug: params[:slug] || params[:"mp-slug"],
|
||||||
published_at: (params[:"post-status"] == "draft") ? nil : publish_time,
|
published_at: (params[:"post-status"] == "draft") ? nil : publish_time,
|
||||||
|
@@ -12,6 +12,7 @@ module Micropub
|
|||||||
required(:syndicate_to).array(:string)
|
required(:syndicate_to).array(:string)
|
||||||
required(:photos).array(:hash)
|
required(:photos).array(:hash)
|
||||||
required(:location).maybe(:string)
|
required(:location).maybe(:string)
|
||||||
|
required(:in_reply_to).maybe(:string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -20,7 +20,8 @@ RSpec.describe Adamantium::Syndication::Mastodon do
|
|||||||
post_type: "post",
|
post_type: "post",
|
||||||
syndicate_to: [],
|
syndicate_to: [],
|
||||||
photos: [],
|
photos: [],
|
||||||
location: nil
|
location: nil,
|
||||||
|
in_reply_to: nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user