diff options
author | pdp8 <pdp8@pdp8.info> | 2023-06-08 23:31:07 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-06-08 23:31:07 +0200 |
commit | e13839321f5b1dd1106a00cd3f93259bdf1ca8c6 (patch) | |
tree | da32268b706283db33823b6d1c2580a32294d6f6 /activitypub.rb | |
parent | 0751c83a552e3b5d7b4270823c1d231b2976df8f (diff) |
threads, dark style
Diffstat (limited to 'activitypub.rb')
-rw-r--r-- | activitypub.rb | 102 |
1 files changed, 79 insertions, 23 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> + <form action='#{ File.join item[:follow], item[:mention] }' method='post'> + <button>#{ item[:follow].capitalize }</button> + </form> + + <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 |