summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.rb34
-rw-r--r--views/collection.erb12
-rw-r--r--views/object.erb49
3 files changed, 41 insertions, 54 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
diff --git a/views/collection.erb b/views/collection.erb
index 9640b7c..c169e0b 100644
--- a/views/collection.erb
+++ b/views/collection.erb
@@ -4,9 +4,9 @@
<link rel='stylesheet' type='text/css' href='/style.css'>
</head>
<body>
- <h1><%= @dir %>
- <% dirs = ['inbox','outbox','shared']
- dirs.delete(@dir)
+ <h1><%= @box %>
+ <% dirs = ['inbox','outbox']
+ dirs.delete(@box)
dirs.each do |d| %>
<form action='/<%= d %>' method='get'>
<button><%= d %></button>
@@ -18,10 +18,10 @@
@object = object %>
<%= erb :object %>
<% end %>
- <% unless @dir == 'shared' %>
+ <% unless @box == 'shared' %>
<form action='/delete' method='post'>
- <input type='hidden' name='dir' value='<%= @dir %>' />
- <input type='hidden' name='anchor' value='/<%= @dir %>' />
+ <input type='hidden' name='dir' value='<%= @box %>' />
+ <input type='hidden' name='anchor' value='/<%= @box %>' />
<button>Delete all</button>
</form>
<% end %>
diff --git a/views/object.erb b/views/object.erb
index 6ac9f43..b4b7d89 100644
--- a/views/object.erb
+++ b/views/object.erb
@@ -1,32 +1,38 @@
<% @idx +=1
mention = mention @object['attributedTo']
JSON.parse(File.read(FOLLOWING))['orderedItems'].include?(@object['attributedTo']) ? follow='unfollow' : follow='follow'
+ @indent = 0 unless @object['inReplyTo']
%>
-<div style='margin-left:<%= @object['indent']%>em' id='<%= @idx %>'>
+<div style='margin-left:<%= @indent%>em' id='<%= @idx %>'>
<b><a href='<%= @object['attributedTo'] %>', target='_blank'><%= mention %></a></b>&nbsp;
<form action='/<%= follow %>' method='post'>
<input type='hidden' name='follow' value='<%= @object['attributedTo'] %>' />
- <input type='hidden' name='anchor' value='/<%= @dir %>#<%= @idx %>' />
+ <input type='hidden' name='anchor' value='/<%= @box %>#<%= @idx %>' />
<button><%= follow.capitalize %></button>
</form>
- &nbsp;
- <em><%= @object['published'] %></em>
- &nbsp;
- <form action='/delete' method='post'>
- <input type='hidden' name='id' value='<%= @object['id'] %>' />
- <input type='hidden' name='dir' value='<%= @dir %>' />
- <input type='hidden' name='anchor' value='/<%= @dir %>#<%= @idx %>' />
- <button>Delete</button>
- </form>
- &nbsp;
- <% unless @dir == 'shared' %>
- <form action='/share' method='post'>
- <input type='hidden' name='id' value='<%= @object['id'] %>' />
- <input type='hidden' name='dir' value='<%= @dir %>' />
- <input type='hidden' name='anchor' value='/<%= @dir %>#<%= @idx %>' />
- <button>Share</button>
+ <% unless @object['inReplyTo'] %>
+ &nbsp;
+ <em><%= @object['published'] %></em>
+ &nbsp;
+ <form action='/delete' method='post'>
+ <input type='hidden' name='id' value='<%= @object['id'] %>' />
+ <input type='hidden' name='dir' value='<%= @box %>' />
+ <input type='hidden' name='anchor' value='/<%= @box %>#<%= @idx %>' />
+ <button>Delete</button>
+ </form>
+ <% end %>
+ <% unless @box == 'shared' %>
+ &nbsp;
+ <form action='/share' method='post'>
+ <input type='hidden' name='id' value='<%= @object['id'] %>' />
+ <input type='hidden' name='dir' value='<%= @box %>' />
+ <input type='hidden' name='anchor' value='/<%= @box %>#<%= @idx %>' />
+ <button>Share</button>
+ </form>
+ <% end %>
+ <% unless @object['content'].match(/^<p>/) %>
+ <p>
<% end %>
- </form>
<%= @object['content'] %>
<% if @object['attachment']
@object['attachment'].each do |att|
@@ -44,12 +50,12 @@
<% end %>
<% end %>
<p>
- <% unless @dir == 'shared' %>
+ <% unless @box == 'shared' %>
<button class='reply' data-index='<%= @idx %>'>Reply</button>
<form action='/' method='post' id='form<%= @idx %>' style='display:none;' >
<input type='hidden' name='to' value='<%= @object['attributedTo'] %>' />
<input type='hidden' name='inReplyTo' value='<%= @object['id'] %>' />
- <input type='hidden' name='anchor' value='/<%= @dir %>#<%= @idx %>' />
+ <input type='hidden' name='anchor' value='/<%= @box %>#<%= @idx %>' />
<textarea name='content'></textarea>
<br>
<button class='cancel' data-index='<%= @idx %>'>Cancel</button>
@@ -58,6 +64,7 @@
<% end %>
</div>
<% @object['replies'].each do |reply|
+ @indent += 2
@object = reply %>
<%= erb :object %>
<% end %>