summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-07-24 17:34:43 +0200
committerpdp8 <pdp8@pdp8.info>2023-07-24 17:34:43 +0200
commit0f039c1b813653869033e961810942f479a28685 (patch)
tree3268286b6cc892b1af4bfdf34921f9040600973a
parenta509c55faca368709044133199f71fb862b1e605 (diff)
public outbox, inbox/outbox threads
-rw-r--r--.gitignore1
-rw-r--r--client.rb28
-rw-r--r--helpers.rb2
-rw-r--r--server.rb19
4 files changed, 30 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index d2522b8..6911852 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
inbox
public/*/
*csv
+*~
diff --git a/client.rb b/client.rb
index 8d34cf1..b0b6385 100644
--- a/client.rb
+++ b/client.rb
@@ -2,10 +2,10 @@
# client-server
-['/inbox', '/outbox'].each do |path|
+['/inbox/threads', '/outbox/threads'].each do |path|
get path do
protected!
- box = path.sub('/', '')
+ box = path.sub('/', '').sub('/threads', '')
collection = Dir[File.join(box, 'object', '*', '*.json')].collect { |f| JSON.parse(File.read(f)) }
threads = []
collection.collect! do |object|
@@ -42,20 +42,18 @@ end
post '/follow' do
protected!
- actor, = parse_follow params['follow']
- outbox 'Follow', actor, [actor]
+ params['id'] = actor params['mention'] if params['mention']
+ outbox 'Follow', params['id'], [params['id']]
end
post '/unfollow' do
protected!
- actor, mention = parse_follow params['follow']
- Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].each do |f|
- activity = JSON.parse(File.read(f))
- if activity['object'] == actor
- outbox 'Undo', activity, [actor]
- update_collection FOLLOWING, actor, true
- end
- end
+ params['id'] = actor params['mention'] if params['mention']
+ following = Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].collect { |f| JSON.parse(File.read(f)) }
+ activity = following.find { |a| a['object'] == params['id'] }
+ activity ||= save_activity({ 'type' => 'Follow', 'actor' => ACTOR, 'object' => params['id'] }, OUTBOX) # recreate activity for old/deleted follows
+ outbox 'Undo', activity, [params['id']]
+ update_collection FOLLOWING, params['id'], true
end
post '/share' do # TODO
@@ -64,7 +62,7 @@ post '/share' do # TODO
object = JSON.parse(File.read(src))
recipients = public
recipients << object['attributedTo']
- # outbox 'Announce', object, recipients
+ outbox 'Announce', object, recipients
dest = src.sub('/inbox/', '/outbox/')
FileUtils.mkdir_p File.dirname(dest)
FileUtils.mv src, dest
@@ -80,9 +78,9 @@ helpers do
end
def find_file(id)
- Dir[File.join('*', 'object', '*', '*.json')].select do |f|
+ Dir[File.join('*', 'object', '*', '*.json')].find do |f|
JSON.parse(File.read(f))['id'] == id
- end[0]
+ end
end
def public
diff --git a/helpers.rb b/helpers.rb
index 94ec2e1..6812a83 100644
--- a/helpers.rb
+++ b/helpers.rb
@@ -12,7 +12,7 @@ helpers do
activity_path = File.join(box[:dir], activity_rel_path)
if box == OUTBOX
activity['id'] = File.join(box[:url], activity_rel_path)
- activity['object']['published'] = date
+ activity['object']['published'] = date unless activity['object'].is_a? String
end
# save object
save_object activity['object'], box if activity['object'] && activity['object']['type'] && !activity['object']['id']
diff --git a/server.rb b/server.rb
index f337820..666b59e 100644
--- a/server.rb
+++ b/server.rb
@@ -24,19 +24,30 @@ get '/' do
redirect 'https://pdp8.info'
end
+get '/outbox' do
+ files = Dir[File.join('outbox', 'create', '*.json')] + Dir[File.join('outbox', 'announce', '*.json')]
+ activities = files.collect { |f| JSON.parse(File.read(f)) }
+ ids = activities.sort_by { |a| a['published'] }.collect { |a| a['id'] }
+ { '@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => 'https://social.pdp8.info/outbox',
+ 'type' => 'OrderedCollection',
+ 'totalItems' => ids.size,
+ 'orderedItems' => ids }.to_json
+end
+
get '/pdp8', provides: 'html' do
redirect 'https://pdp8.info'
end
+get '/pdp8' do
+ send_file(File.join(PUBLIC_DIR, 'pdp8.json'), type: CONTENT_TYPE)
+end
+
get '/.well-known/webfinger' do
halt 404 unless request['resource'] == "acct:#{MENTION}"
send_file(WEBFINGER, type: 'application/jrd+json')
end
-get '/pdp8' do
- send_file(File.join(PUBLIC_DIR, 'pdp8.json'), type: CONTENT_TYPE)
-end
-
['/following', '/followers'].each do |path|
get path do
send_file(File.join(PUBLIC_DIR, path) + '.json', type: CONTENT_TYPE)