From e13839321f5b1dd1106a00cd3f93259bdf1ca8c6 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Thu, 8 Jun 2023 23:31:07 +0200 Subject: threads, dark style --- activitypub.rb | 102 ++++++++++++++++++++++++++++++++++++++++++------------- public/style.css | 10 ++++++ views/index.erb | 25 +------------- 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=" + + + + + " + @inbox.each do |item| + html += html(item) + end + 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 = " +
+ #{ item[:mention] }  +
+ +
+   +
+ +
+ #{ item[:content].gsub('
','') }" + if item[:attachment] + item[:attachment].each do |att| + html << "
" + case att['mediaType'] + when /audio/ + html << "" + when /image/ + html << "" + when /video/ + html << "" + else + html << "#{ att }
+ #{ att['url'] }" + end + end + end + html << " +
" + 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 @@ <% @inbox.each do |item| %> - <%= item[:mention] %>  -
- -
-

<%= item[:content] %> - <% if item[:attachment] - item[:attachment].each do |att| - case att['mediaType'] - when /audio/ %> -
- <% when /image/ %> -
'>'> - <% when /video/ %> -
- <% else %> - <%= att %>
- '><%= att['url'] %> - <% end %> - <% end %> - <% end %> -

-

' method='post'> - -
+ <%= erb :item %>
<% end %> -- cgit v1.2.3