summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.rb102
-rw-r--r--public/style.css10
-rw-r--r--views/index.erb25
3 files changed, 90 insertions, 47 deletions
diff --git a/activitypub.rb b/activitypub.rb
index 6e82bc4..a340291 100644
--- a/activitypub.rb
+++ b/activitypub.rb
@@ -1,7 +1,8 @@
# TODO
+# delete all/thread
+# anchors (return after delete)
# boost
# archive
-# threads
# federation
# client post media
# test with pleroma etc
@@ -20,10 +21,6 @@ ACCOUNT = "#{USER}@#{SOCIAL_DOMAIN}"
SOCIAL_URL = "https://#{SOCIAL_DOMAIN}"
ACTOR = File.join(SOCIAL_URL, USER)
-#OpenSSL::SSL::SSLContext::DEFAULT_PARAMS = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.merge(
- #options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] + OpenSSL::SSL::OP_IGNORE_UNEXPECTED_EOF
-#).freeze
-
enable :sessions
set :session_secret, File.read(".secret").chomp
set :default_content_type, 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
@@ -172,24 +169,44 @@ end
get "/", :provides => 'html' do
protected!
- @inbox = Dir['./inbox/*.json'].sort.collect do |file|
+ items = Dir['./inbox/*.json'].sort.collect do |file|
item = JSON.parse(File.read(file))
- unless item['type'] == 'Person'
- mention = mention(item['attributedTo'])
- #p mention
- following_path = File.join('public', 'following', mention + '.json')
- File.exists?(following_path) ? follow = 'unfollow' : follow = 'follow'
- { :file => file,
- :actor_url => item['attributedTo'],
- :mention => mention,
- :follow => follow,
- :content => item['content'],
- :attachment => item['attachment']
- }
- end
+ mention = mention(item['attributedTo'])
+ following_path = File.join('public', 'following', mention + '.json')
+ File.exists?(following_path) ? follow = 'unfollow' : follow = 'follow'
+ { :id => item['id'],
+ :parent => item['inReplyTo'],
+ :file => file,
+ :actor_url => item['attributedTo'],
+ :mention => mention,
+ :follow => follow,
+ :content => item['content'],
+ :attachment => item['attachment'],
+ :replies => []
+ }
end.compact
- #p @inbox
- erb :index
+ @inbox = []
+ items.each do |i|
+ if i[:parent].nil? or items.select{|it| it[:id] == i[:parent] }.empty?
+ @inbox << i
+ else
+ #p i
+ items.select{|it| it[:id] == i[:parent] }.each{|it| it[:replies] << i}
+ end
+ end
+ html="<!DOCTYPE html>
+ <html lang='en'>
+ <head>
+ <link rel='stylesheet' type='text/css' href='/style.css'>
+ </head>
+ <body>"
+ @inbox.each do |item|
+ html += html(item)
+ end
+ html+=' </body>
+ </html>'
+ #erb :index
+ html
end
["/outbox","/following","/followers"].each do |path|
@@ -204,6 +221,43 @@ helpers do
end
end
+def html item, indent=2
+ html = "
+ <div style='margin-left:#{indent}em'>
+ <b><a href='#{ item[:actor_url] }', target='_blank'>#{ item[:mention] }</a></b>&nbsp;
+ <form action='#{ File.join item[:follow], item[:mention] }' method='post'>
+ <button>#{ item[:follow].capitalize }</button>
+ </form>
+ &nbsp;
+ <form action='#{ File.join 'delete', item[:file] }' method='post'>
+ <button>Delete</button>
+ </form>
+ #{ item[:content].gsub('<br />','') }"
+ if item[:attachment]
+ item[:attachment].each do |att|
+ html << "<br>"
+ case att['mediaType']
+ when /audio/
+ html << "<audio controls=''><source src='#{ att['url'] }' type='#{ att['mediaType'] }'></audio>"
+ when /image/
+ html << "<a href='#{ att['url'] }'><img src='#{ att['url'] }'></a>"
+ when /video/
+ html << "<video controls=''><source src='#{ att['url'] }' type='#{ att['mediaType'] }'></video>"
+ else
+ html << "#{ att }<br>
+ <a href='#{ att['url'] }'>#{ att['url'] }</a>"
+ end
+ end
+ end
+ html << "
+ </div>"
+ item[:replies].each do |r|
+ html << html(r,indent+4)
+ end
+
+ html
+end
+
def delete object
Dir["inbox/*.json"].each do |doc|
FileUtils.rm doc if JSON.parse(File.read(doc))["id"] == object["id"]
@@ -211,8 +265,10 @@ def delete object
end
def create object
- doc = File.join("inbox", "#{Time.now.strftime('%Y-%m-%dT%H:%M:%S.%N')}.json")
- File.open(doc, "w+") { |f| f.puts object.to_json }
+ unless object['type'] == 'Person'
+ doc = File.join("inbox", "#{Time.now.strftime('%Y-%m-%dT%H:%M:%S.%N')}.json")
+ File.open(doc, "w+") { |f| f.puts object.to_json }
+ end
end
def mention actor
diff --git a/public/style.css b/public/style.css
index 73528ed..98d83b5 100644
--- a/public/style.css
+++ b/public/style.css
@@ -1,8 +1,16 @@
body {
font-family: sans-serif;
font-size: 3vmin;
+ color: white;
+ background-color: black;
}
+div {
+ margin: 1em;
+ padding: 1em;
+ border: 1px solid #333;
+ border-radius: 1em;
+}
img,
video {
@@ -19,6 +27,8 @@ form {
button {
font-size: 1.5em;
+ background-color: #BBB;
+ border-radius: 0.5em;
}
a {
diff --git a/views/index.erb b/views/index.erb
index a698565..3a245a9 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -5,30 +5,7 @@
</head>
<body>
<% @inbox.each do |item| %>
- <b><a href='<%= item[:actor_url] %>', target='_blank'><%= item[:mention] %></a></b>&nbsp;
- <form action='<%= File.join item[:follow], item[:mention] %>' method='post'>
- <button><%= item[:follow].capitalize %></button>
- </form>
- <p><%= item[:content] %>
- <% if item[:attachment]
- item[:attachment].each do |att|
- case att['mediaType']
- when /audio/ %>
- <br><audio controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></audio>
- <% when /image/ %>
- <br><a href='<%= att['url'] %>'><img src='<%= att['url'] %>'></a>
- <% when /video/ %>
- <br><video controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></video>
- <% else %>
- <%= att %><br>
- <a href='<%= att['url'] %>'><%= att['url'] %></a>
- <% end %>
- <% end %>
- <% end %>
- <p>
- <form action='<%= File.join 'delete', item[:file] %>' method='post'>
- <button>Delete</button>
- </form>
+ <%= erb :item %>
<hr>
<% end %>
</body>