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 Jobs
|
||||
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"]
|
||||
settings = Admin::Container["settings"]
|
||||
|
||||
@@ -17,6 +17,15 @@ module Adamantium
|
||||
target: target
|
||||
})
|
||||
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
|
||||
|
@@ -9,6 +9,7 @@ module Adamantium
|
||||
youtube.com
|
||||
bsky.app
|
||||
bsky.social
|
||||
localhost
|
||||
github.com].freeze
|
||||
|
||||
def call(content)
|
||||
|
@@ -192,6 +192,17 @@ module Main
|
||||
.one!
|
||||
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)
|
||||
posts
|
||||
.by_pk(id)
|
||||
|
@@ -17,6 +17,13 @@ article class="h-entry"
|
||||
h1 class="p-name mb-2"
|
||||
a class="u-url" href=post.permalink
|
||||
= 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"
|
||||
- if post.location || post.photos? || post.videos?
|
||||
span See more:
|
||||
|
@@ -4,7 +4,7 @@ module Main
|
||||
module Views
|
||||
module Posts
|
||||
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:|
|
||||
Decorators::Posts::Decorator.new(post_repo.fetch!(slug))
|
||||
@@ -35,6 +35,13 @@ module Main
|
||||
expose :trip do |post|
|
||||
post.trips.first
|
||||
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
|
||||
|
@@ -24,7 +24,7 @@ module Micropub
|
||||
|
||||
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)
|
||||
end
|
||||
|
@@ -7,10 +7,10 @@ module Micropub
|
||||
class SendWebmentions
|
||||
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"]
|
||||
|
||||
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
|
||||
|
@@ -10,6 +10,7 @@ module Micropub
|
||||
attribute :published_at, Types::Nominal::DateTime.optional
|
||||
attribute :post_type, 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 :location, Types::Coercible::String.optional
|
||||
end
|
||||
|
@@ -97,6 +97,7 @@ module Micropub
|
||||
content: content,
|
||||
slug: params[:slug] || params[:"mp-slug"],
|
||||
syndicate_to: Array(params[:properties][:"mp-syndicate-to"]) || [],
|
||||
in_reply_to: params[:properties][:"in-reply-to"] || nil,
|
||||
photos: photos,
|
||||
location: params[:properties][:location]
|
||||
})
|
||||
@@ -119,6 +120,7 @@ module Micropub
|
||||
|
||||
new_params.merge({
|
||||
syndicate_to: Array(params[:"mp-syndicate-to"]) || [],
|
||||
in_reply_to: params[:"in-reply-to"],
|
||||
name: params[:name],
|
||||
slug: params[:slug] || params[:"mp-slug"],
|
||||
published_at: (params[:"post-status"] == "draft") ? nil : publish_time,
|
||||
|
@@ -12,6 +12,7 @@ module Micropub
|
||||
required(:syndicate_to).array(:string)
|
||||
required(:photos).array(:hash)
|
||||
required(:location).maybe(:string)
|
||||
required(:in_reply_to).maybe(:string)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -20,7 +20,8 @@ RSpec.describe Adamantium::Syndication::Mastodon do
|
||||
post_type: "post",
|
||||
syndicate_to: [],
|
||||
photos: [],
|
||||
location: nil
|
||||
location: nil,
|
||||
in_reply_to: nil
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user