Add emoji to statuses
This commit is contained in:
9
db/migrate/20240324053509_add_emoji_to_posts.rb
Normal file
9
db/migrate/20240324053509_add_emoji_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 :emoji, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
18
slices/main/actions/feeds/statuses_json.rb
Normal file
18
slices/main/actions/feeds/statuses_json.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
module Main
|
||||||
|
module Actions
|
||||||
|
module Feeds
|
||||||
|
class StatusesJSON < Action
|
||||||
|
include Deps["views.feeds.statuses_json", "repos.post_repo"]
|
||||||
|
|
||||||
|
def handle(req, res)
|
||||||
|
posts = post_repo.statuses_for_rss.map do |post|
|
||||||
|
Decorators::Posts::Decorator.new(post).to_h
|
||||||
|
end
|
||||||
|
|
||||||
|
res.content_type = "application/json; charset=utf-8"
|
||||||
|
res.body = JSON.generate(posts, quirks_mode: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -24,6 +24,8 @@ module Main
|
|||||||
get "/feeds/rss", to: "feeds.rss"
|
get "/feeds/rss", to: "feeds.rss"
|
||||||
get "/feeds/statuses_rss", to: "feeds.statuses_rss"
|
get "/feeds/statuses_rss", to: "feeds.statuses_rss"
|
||||||
|
|
||||||
|
get "/feeds/statuses_json", to: "feeds.statuses_json"
|
||||||
|
|
||||||
get "/more", to: "more.index"
|
get "/more", to: "more.index"
|
||||||
|
|
||||||
get "/hikes", to: "workouts.index"
|
get "/hikes", to: "workouts.index"
|
||||||
|
@@ -53,11 +53,23 @@ module Main
|
|||||||
doc.at("//img")
|
doc.at("//img")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inline_image_sources
|
||||||
|
inline_images
|
||||||
|
&.select {|attr, _value| attr == "src"}
|
||||||
|
&.map {|img| img[1] } || []
|
||||||
|
end
|
||||||
|
|
||||||
|
def photo_sources
|
||||||
|
photos.map{|photo| photo["value"]}
|
||||||
|
end
|
||||||
|
|
||||||
def prefix_emoji
|
def prefix_emoji
|
||||||
if name
|
if name
|
||||||
nil
|
nil
|
||||||
elsif photos? && content == ""
|
elsif photos? && content == ""
|
||||||
"📷"
|
"📷"
|
||||||
|
elsif __getobj__.emoji
|
||||||
|
__getobj__.emoji
|
||||||
else
|
else
|
||||||
@prefix_emoji ||= if (match = content.match(Unicode::Emoji::REGEX))
|
@prefix_emoji ||= if (match = content.match(Unicode::Emoji::REGEX))
|
||||||
match
|
match
|
||||||
@@ -133,6 +145,15 @@ module Main
|
|||||||
__getobj__.trips
|
__getobj__.trips
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_h
|
||||||
|
{
|
||||||
|
id: slug,
|
||||||
|
emoji: prefix_emoji,
|
||||||
|
content: raw_content,
|
||||||
|
images: (inline_image_sources + photo_sources).compact
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# e.g. geo:-37.75188,144.90417;u=35
|
# e.g. geo:-37.75188,144.90417;u=35
|
||||||
|
21
slices/main/views/feeds/statuses_json.rb
Normal file
21
slices/main/views/feeds/statuses_json.rb
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
require "builder"
|
||||||
|
|
||||||
|
module Main
|
||||||
|
module Views
|
||||||
|
module Feeds
|
||||||
|
class StatusesJSON < Main::View
|
||||||
|
include Deps["repos.post_repo"]
|
||||||
|
|
||||||
|
expose :posts do
|
||||||
|
post_repo.statuses_for_rss.map do |post|
|
||||||
|
Decorators::Posts::Decorator.new post
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
expose :json, decorate: false, layout: true do |posts|
|
||||||
|
posts.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -11,6 +11,7 @@ module Micropub
|
|||||||
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 :in_reply_to, Types::Coercible::String
|
||||||
|
attribute :emoji, 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
|
||||||
|
@@ -98,6 +98,7 @@ module Micropub
|
|||||||
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,
|
in_reply_to: params[:properties][:"in-reply-to"] || nil,
|
||||||
|
emoji: params[:properties][:emoji] || nil,
|
||||||
photos: photos,
|
photos: photos,
|
||||||
location: params[:properties][:location]
|
location: params[:properties][:location]
|
||||||
})
|
})
|
||||||
@@ -121,6 +122,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"],
|
in_reply_to: params[:"in-reply-to"],
|
||||||
|
emoji: params[:emoji],
|
||||||
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,
|
||||||
|
@@ -13,6 +13,7 @@ module Micropub
|
|||||||
required(:photos).array(:hash)
|
required(:photos).array(:hash)
|
||||||
required(:location).maybe(:string)
|
required(:location).maybe(:string)
|
||||||
required(:in_reply_to).maybe(:string)
|
required(:in_reply_to).maybe(:string)
|
||||||
|
required(:emoji).maybe(:string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -7,26 +7,28 @@ RSpec.describe "Webmention creation", :db, :requests do
|
|||||||
context "reply" do
|
context "reply" do
|
||||||
let(:reply_json) {
|
let(:reply_json) {
|
||||||
{
|
{
|
||||||
type: "entry",
|
post: {
|
||||||
author: {
|
type: "entry",
|
||||||
type: "card",
|
author: {
|
||||||
name: "nitza",
|
type: "card",
|
||||||
photo: "",
|
name: "nitza",
|
||||||
url: "https://micro.blog/nitza"
|
photo: "",
|
||||||
},
|
url: "https://micro.blog/nitza"
|
||||||
url: "https://micro.blog/nitza/20554783",
|
},
|
||||||
published: "2023-07-05T09:44:41+00:00",
|
url: "https://micro.blog/nitza/20554783",
|
||||||
"wm-received": "2023-07-05T09:44:48Z",
|
published: "2023-07-05T09:44:41+00:00",
|
||||||
"wm-id": 1692950,
|
"wm-received": "2023-07-05T09:44:48Z",
|
||||||
"wm-source": "https://micro.blog/nitza/20554783",
|
"wm-id": 1692950,
|
||||||
"wm-target": "https://dnitza.com/post/#{post_record.slug}",
|
"wm-source": "https://micro.blog/nitza/20554783",
|
||||||
content: {
|
"wm-target": "https://dnitza.com/post/#{post_record.slug}",
|
||||||
html: "<p><a href=\"https://micro.blog/example\">@example</a> hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅</p>",
|
content: {
|
||||||
text: "@example hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅"
|
html: "<p><a href=\"https://micro.blog/example\">@example</a> hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅</p>",
|
||||||
},
|
text: "@example hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅"
|
||||||
"in-reply-to": "https://dnitza.com/post/#{post_record.slug}",
|
},
|
||||||
"wm-property": "in-reply-to",
|
"in-reply-to": "https://dnitza.com/post/#{post_record.slug}",
|
||||||
"wm-private": false
|
"wm-property": "in-reply-to",
|
||||||
|
"wm-private": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,8 @@ RSpec.describe Adamantium::Syndication::Mastodon do
|
|||||||
syndicate_to: [],
|
syndicate_to: [],
|
||||||
photos: [],
|
photos: [],
|
||||||
location: nil,
|
location: nil,
|
||||||
in_reply_to: nil
|
in_reply_to: nil,
|
||||||
|
emoji: nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user