From 086709cae3da7a01a011fe906004c8685fdd2ed0 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sat, 1 Jul 2023 01:54:02 +0200 Subject: direct collection access from client --- client.rb | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'client.rb') diff --git a/client.rb b/client.rb index b62f139..3016d02 100644 --- a/client.rb +++ b/client.rb @@ -134,8 +134,21 @@ end ['/inbox', '/archive', '/outbox'].each do |path| get path, provides: 'html' do protected! - @items = fetch(File.join(SOCIAL_URL, path))['orderedItems'] - threads + @dir = path.sub('/', '') + collection = ordered_collection(File.join(SOCIAL_DIR, path, 'note'))['orderedItems'] + @threads = [] + collection.each do |object| + object['indent'] = 0 + object['replies'] = [] + if object['inReplyTo'].nil? || collection.select { |o| o['id'] == object['inReplyTo'] }.empty? + @threads << object + else + collection.select { |o| o['id'] == object['inReplyTo'] }.each do |o| + object['indent'] = o['indent'] + 4 + o['replies'] << object + end + end + end erb :collection end end @@ -145,26 +158,6 @@ helpers do halt 403 unless session['client'] end - def outbox(activity) - curl("-X POST -d #{activity.to_json}", File.join(SOCIAL_URL, 'outbox')) - end - - def threads - @threads = [] - @items.each do |i| - i['indent'] = 0 - i['replies'] = [] - if i['inReplyTo'].nil? || @items.select { |it| it['id'] == i['inReplyTo'] }.empty? - @threads << i - else - @items.select { |it| it['id'] == i['inReplyTo'] }.each do |it| - i['indent'] = it['indent'] + 4 - it['replies'] << i - end - end - end - end - def parse_follow(follow) case follow when /^#/ -- cgit v1.2.3