From 4ca1c5555f18703d1dac673b1a77d1c919fb4787 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Mon, 17 Jul 2023 19:09:02 +0200 Subject: write to json instead of direcories --- client.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'client.rb') diff --git a/client.rb b/client.rb index c2c64ea..24d8795 100644 --- a/client.rb +++ b/client.rb @@ -64,7 +64,12 @@ end post '/delete' do protected! - selection(params).each { |f| FileUtils.rm f } + collection = Kernel.const_get(params['dir'].upcase) + if params['id'] + update_collection collection, params, true + else + update_collection collection, JSON.parse(File.read(collection))['orderedItems'], true + end redirect(params['anchor'] || '/inbox') end @@ -78,6 +83,8 @@ end post '/unfollow' do protected! actor, mention = parse_follow params['follow'] + outbox 'Undo', JSON.parse(File.read(following_path)), [actor] + p actor following_path = File.join(FOLLOWING_DIR, "#{mention}.json") if File.exist?(following_path) outbox 'Undo', JSON.parse(File.read(following_path)), [actor] @@ -100,17 +107,24 @@ end get path, provides: 'html' do protected! @dir = path.sub('/', '') - collection = ordered_collection(File.join(SOCIAL_DIR, path, 'note'))['orderedItems'] + # p(Kernel.const_get(@dir.upcase)) + # p(File.read(Kernel.const_get(@dir.upcase))) + collection = JSON.parse(File.read(Kernel.const_get(@dir.upcase)))['orderedItems'].uniq + # collection = ordered_collection(File.join(SOCIAL_DIR, path, 'note'))['orderedItems'] @threads = [] - collection.each_with_index do |object, _idx| + 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| + next unless o['indent'] + object['indent'] = o['indent'] + 2 o['replies'] << object + # else + # p o end end end -- cgit v1.2.3