summaryrefslogtreecommitdiff
path: root/server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'server.rb')
-rw-r--r--server.rb36
1 files changed, 29 insertions, 7 deletions
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|