summaryrefslogtreecommitdiff
path: root/server.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-08-24 15:52:39 +0200
committerpdp8 <pdp8@pdp8.info>2023-08-24 15:52:39 +0200
commit485d71e69cb5b56d3ccf8b5eb82ef6af9d172485 (patch)
tree8d353aed6b5dacf34c8be426881ee03d6b3602ab /server.rb
parent8cb9bc7e4d516a27b4fe27ba0d0a9c40497e003d (diff)
like, move, delete, update activities
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|