summaryrefslogtreecommitdiff
path: root/client.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-07-17 19:09:02 +0200
committerpdp8 <pdp8@pdp8.info>2023-07-17 19:09:02 +0200
commit4ca1c5555f18703d1dac673b1a77d1c919fb4787 (patch)
tree2f57783bdc1786e09737196a2fae07a720452d4f /client.rb
parent2e614738f72c9af634c4a630693d06f144bc24df (diff)
write to json instead of direcories
Diffstat (limited to 'client.rb')
-rw-r--r--client.rb20
1 files changed, 17 insertions, 3 deletions
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