summaryrefslogtreecommitdiff
path: root/client.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-07-21 16:28:24 +0200
committerpdp8 <pdp8@pdp8.info>2023-07-21 16:28:24 +0200
commit3c38f81b8a145778d4329c6be4c91baa00ca0d48 (patch)
treec0a68c6b57b6bf4154dcb3c9d3a67e93cc01a658 /client.rb
parent5062145de3e3fe600415c8b8718c6a144f8ed939 (diff)
thread rendering
Diffstat (limited to 'client.rb')
-rw-r--r--client.rb34
1 files changed, 7 insertions, 27 deletions
diff --git a/client.rb b/client.rb
index 75464c1..f90ca5f 100644
--- a/client.rb
+++ b/client.rb
@@ -135,32 +135,22 @@ get '/' do
redirect '/inbox'
end
-# ['/inbox', '/shared', '/outbox'].each do |path|
['/inbox', '/outbox'].each do |path|
get path, provides: 'html' do
protected!
- @dir = path.sub('/', '')
- # collection = DirI#
- # collection = Dir[File.join(@dir, 'object','*', '*.json')].collect { |f| JSON.parse(File.read(f)) }
-
- @collection = Dir[File.join(@dir, 'create', '*.json')].collect { |f| JSON.parse(File.read(f))['object'] }
- @collection += Dir[File.join(@dir, 'announce', '*.json')].collect { |f| JSON.parse(File.read(f))['object'] }
+ @box = path.sub('/', '')
+ collection = Dir[File.join(@box, 'object', '*', '*.json')].collect { |f| JSON.parse(File.read(f)) }
@threads = []
- @collection.collect! do |object|
+ collection.collect! do |object|
object = fetch(object) if object.is_a?(String) && object.match(/^http/)
object
end
- @collection.each do |object|
- add_parents object
- end
- @collection.each do |object|
- object['indent'] = 0
+ collection.each do |object|
object['replies'] = []
- @threads << object if object['inReplyTo'].nil? || @collection.select { |o| o['id'] == object['inReplyTo'] }.empty?
+ @threads << object if object['inReplyTo'].nil? || collection.select { |o| o['id'] == object['inReplyTo'] }.empty?
end
- @collection.each do |object|
- @collection.select { |o| o['id'] == object['inReplyTo'] }.each do |o|
- object['indent'] = o['indent'] + 2
+ collection.each do |object|
+ collection.select { |o| o['id'] == object['inReplyTo'] }.each do |o|
o['replies'] << object
end
end
@@ -170,16 +160,6 @@ end
end
helpers do
- def add_parents(object)
- return unless object['inReplyTo']
-
- object = fetch object['inReplyTo']
- return unless object
-
- @collection << object unless @collection.collect { |o| o['id'] }.include? object['id']
- add_parents object
- end
-
def protected!
halt 403 unless session['client']
end