summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.rb37
-rw-r--r--server.rb48
-rw-r--r--views/collection.erb10
3 files changed, 41 insertions, 54 deletions
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 /^#/
diff --git a/server.rb b/server.rb
index 6379332..386b519 100644
--- a/server.rb
+++ b/server.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
-before '/inbox' do
+# server-server
+post '/inbox' do
request.body.rewind # in case someone already read it
@body = request.body.read
unless @body.empty?
@@ -9,20 +10,9 @@ before '/inbox' do
@object = fetch(@object) if @object.is_a?(String) && @object.match(/^http/)
halt 400 unless @object
end
-end
-
-# client-server
-post '/outbox' do
- protected!
- # send_signed @activity
-end
-
-# server-server
-post '/inbox' do
verify!
- # file = File.join INBOX, "#{SecureRandom.uuid}.json"
- # File.open(file, 'w+') { |f| f.puts @activity.to_json }
type = @activity['type'].downcase.to_sym
+ p type
respond_to?(type) ? send(type) : p("Unknown activity: #{type}")
end
@@ -32,7 +22,7 @@ get '/.well-known/webfinger' do
send_file('./public/webfinger',
type: 'application/jrd+json')
else
- halt(404)
+ halt 404
end
end
@@ -40,10 +30,10 @@ get '/outbox' do
ordered_collection(OUTBOX).to_json
end
-get '/inbox' do
- # protected!
- ordered_collection(File.join(INBOX, 'note')).to_json
-end
+# get '/inbox' do
+# protected!
+# ordered_collection(File.join(INBOX, 'note')).to_json
+# end
['/following', '/followers'].each do |path|
get path do
@@ -118,6 +108,17 @@ helpers do
create
end
+ def follow
+ File.open(File.join(FOLLOWERS, "#{mention(@activity['actor'])}.json"), 'w+') { |f| f.puts @body }
+ accept = { '@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => File.join("#{SOCIAL_URL}#accepts", SecureRandom.uuid),
+ 'type' => 'Accept',
+ 'actor' => ACTOR,
+ 'object' => @activity,
+ 'to' => [@activity['actor']] }
+ send_signed accept
+ end
+
def accept
return unless @object['type'] == 'Follow'
@@ -132,17 +133,6 @@ helpers do
end
end
- def follow
- File.open(File.join(FOLLOWERS, "#{mention(@activity['actor'])}.json"), 'w+') { |f| f.puts @body }
- accept = { '@context' => 'https://www.w3.org/ns/activitystreams',
- 'id' => File.join("#{SOCIAL_URL}#accepts", SecureRandom.uuid),
- 'type' => 'Accept',
- 'actor' => ACTOR,
- 'object' => @activity,
- 'to' => [@activity['actor']] }
- send_signed accept
- end
-
# when "Like"
# when "Move"
# when "Add"
diff --git a/views/collection.erb b/views/collection.erb
index 4455b31..8dd3878 100644
--- a/views/collection.erb
+++ b/views/collection.erb
@@ -5,9 +5,13 @@
</head>
<body>
<h1><%= @dir %>
- <form action='<%= @alt_dir %>' method='get'>
- <button><%= @alt_name %></button>
- </form>
+ <% dirs = ['inbox','outbox','archive']
+ dirs.delete(@dir)
+ dirs.each do |d| %>
+ <form action='/<%= d %>' method='get'>
+ <button><%= d %></button>
+ </form>
+ <% end %>
</h1>
<% @threads.each do |object|
@object = object %>