From 4586c63bd86fe3dad403086b15d5b74b6d67fc92 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Thu, 1 Feb 2024 12:23:31 +0100 Subject: general outbox routes --- create.rb | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'create.rb') diff --git a/create.rb b/create.rb index 40bfbb8..371f8f8 100644 --- a/create.rb +++ b/create.rb @@ -1,5 +1,4 @@ TO_REGEXP = /^to:\s+/i -CC_REGEXP = /^cc:\s+/i REPLY_REGEXP = /^inreplyto:\s+/i ATTACH_REGEXP = /^attach:\s+/i URL_REGEXP = %r{\Ahttps?://\S+\Z} @@ -23,11 +22,25 @@ post '/create' do line.sub(TO_REGEXP, '').split(/\s+/).each do |word| case word when 'public' - to += ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] + to << 'https://www.w3.org/ns/activitystreams#Public' + to << FOLLOWERS_URL when MENTION_REGEXP - to << actor(word) + href = actor(word) + m = { + 'type' => 'Mention', + 'href' => href, + 'name' => word + } + to << href unless to.include? href + tag << m unless tag.include? m when URL_REGEXP - to << word + m = { + 'type' => 'Mention', + 'href' => word, + 'name' => mention(word) + } + to << word unless to.include? word + tag << m unless tag.include? m end end when REPLY_REGEXP @@ -40,8 +53,8 @@ post '/create' do 'url' => url, 'name' => description } - when "\n" - "

\n" + when '' + content << '

' else # create links content << line.split(/\s+/).collect do |word| case word @@ -55,36 +68,28 @@ post '/create' do "#{word}" when MENTION_REGEXP actor = actor(word) - tag << { + m = { 'type' => 'Mention', 'href' => actor, 'name' => word } - to << actor + tag << m unless tag.include? m + to << actor unless to.include? actor "#{word}" + when URL_REGEXP + "#{word}" else word end end.join(' ') - # content << line end end - # https://docs.joinmastodon.org/spec/activitypub/#Mention - if to.size == 1 # mastodon DM - m = { - 'type' => 'Mention', - 'href' => to[0], - 'name' => mention(to[0]) - } - tag << m unless tag.include? m - end - object = { 'to' => to, 'type' => 'Note', 'attributedTo' => ACTOR, - 'content' => "#{content.join(' ')}" + 'content' => "#{content.join('')}" } object['inReplyTo'] = inReplyTo unless inReplyTo.empty? object['attachment'] = attachment unless attachment.empty? @@ -92,7 +97,7 @@ post '/create' do # p to jj object - # create_activity 'Create', object, to + create_activity 'Create', object, to 200 end -- cgit v1.2.3