summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.rb34
-rw-r--r--create.rb2
-rw-r--r--server.rb36
3 files changed, 50 insertions, 22 deletions
diff --git a/client.rb b/client.rb
index 13ba3a6..0ebd3aa 100644
--- a/client.rb
+++ b/client.rb
@@ -10,24 +10,24 @@ post '/delete' do
protected!
params['id'].each do |id|
file = find_file id
- if file.match(%r{outbox/}) # find/delete activity
+ # if file.match(%r{outbox/}) # find/delete activity
- Dir[File.join 'outbox', 'announce', '*'].each do |announce_file|
- announce = JSON.load_file(announce_file)
- next unless announce['object']['id'] == id
+ Dir[File.join 'outbox', 'announce', '*'].each do |announce_file|
+ announce = JSON.load_file(announce_file)
+ next unless announce['object']['id'] == id
- outbox 'Undo', announce, announce['to']
- FileUtils.rm(announce_file)
- end
- Dir[File.join 'outbox', 'create', '*'].each do |create_file|
- create = JSON.load_file(create_file)
- next unless create['object']['id'] == id
+ outbox 'Undo', announce, announce['to']
+ FileUtils.rm(announce_file)
+ end
+ Dir[File.join 'outbox', 'create', '*'].each do |create_file|
+ create = JSON.load_file(create_file)
+ next unless create['object']['id'] == id
- object = JSON.load_file(file)
- outbox 'Delete', object, object['to']
- FileUtils.rm(create_file)
- end
+ object = JSON.load_file(file)
+ outbox 'Delete', object, object['to']
+ FileUtils.rm(create_file)
end
+ # end
FileUtils.rm(file) if File.exist? file
end
200
@@ -45,6 +45,12 @@ post '/unfollow' do
params['id'] = actor params['mention'] if params['mention']
following = Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].collect { |f| JSON.load_file(f) }
activity = following.find { |a| a['object'] == params['id'] }
+ activity ||= {
+ "@context": 'https://www.w3.org/ns/activitystreams',
+ "type": 'Follow',
+ "actor": 'https://social.pdp8.info/pdp8',
+ "object": params['id']
+ }
outbox 'Undo', activity, [params['id']]
update_collection FOLLOWING, params['id'], true
200
diff --git a/create.rb b/create.rb
index 6a6dd4e..50933f1 100644
--- a/create.rb
+++ b/create.rb
@@ -70,7 +70,7 @@ post '/create' do # TODO
# single quotes in html invalidate digest, reason unknown
line.gsub!(mention, "<a href=\"#{actor}\">#{mention}</a>")
end
- content << line
+ content << '<br>' + line
end
end
content.shift while content[0] == '<p>'
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|