From 485d71e69cb5b56d3ccf8b5eb82ef6af9d172485 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Thu, 24 Aug 2023 15:52:39 +0200 Subject: like, move, delete, update activities --- server.rb | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'server.rb') diff --git a/server.rb b/server.rb index fa4ca2e..9fd9e11 100644 --- a/server.rb +++ b/server.rb @@ -9,11 +9,17 @@ post '/inbox' do p @body halt 400 end - halt 501 if @activity['actor'] and @activity['type'] == 'Delete' # deleted actors return 403 => verification error + # deleted actors return 403 => verification error + halt 200 if @activity['type'] == 'Delete' and @activity['actor'] == @activity['object'] # verify! # pixelfed sends unsigned activities??? type = @activity['type'].downcase.to_sym - save_activity(@activity, INBOX) unless %i[create announce].include? type - send(type) if %i[create announce follow accept undo].include? type + save_activity(@activity, INBOX) # unless %i[create announce].include? type + if %i[create announce follow accept undo delete like update move].include? type + send(type) + else + p "Unknown activity #{type}:" + jj @activity + end 200 end @@ -59,9 +65,14 @@ end helpers do def create @object ||= @activity['object'] - @object = save_object @object, INBOX + @object = if @object['type'] == 'Like' # lemmy likes + save_object @object['object'], INBOX + else + save_object @object, INBOX + end return unless @object and @object['inReplyTo'] + # recursive thread download @object = @object['inReplyTo'] create end @@ -70,6 +81,10 @@ helpers do create end + def like + create + end + def follow update_collection FOLLOWERS, @activity['actor'] outbox 'Accept', @activity, [@activity['actor']] @@ -97,6 +112,15 @@ helpers do create end + def delete + file = find_file(@activity['object']['id']) + FileUtils.rm(file) if file + end + + def move + outbox 'Follow', @activity['target'], [@activity['target']] if @activity['actor'] == @activity['object'] + end + # https://github.com/mastodon/mastodon/blob/main/app/controllers/concerns/signature_verification.rb def verify! # digest @@ -144,9 +168,7 @@ helpers do end end - def outbox(type, object, to) - # send - ## https://github.com/mastodon/mastodon/blob/main/app/lib/request.rb + def outbox(type, object, to) # https://github.com/mastodon/mastodon/blob/main/app/lib/request.rb to = [to] if to.is_a?(String) inboxes = [] to.uniq.each do |url| -- cgit v1.2.3