From 8453f524515941f3c0a65b5ca3b9354be76b4c33 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Mon, 26 Jun 2023 11:20:38 +0200 Subject: hidden reply form --- client.rb | 65 +++++++++++++++++++++++++++++++++++--------------------- public/style.css | 6 ++++++ views/index.erb | 18 ++++++++++++++++ views/item.erb | 10 ++++++--- 4 files changed, 72 insertions(+), 27 deletions(-) diff --git a/client.rb b/client.rb index 5b2aced..2e449bd 100644 --- a/client.rb +++ b/client.rb @@ -1,18 +1,47 @@ # client-server post "/outbox" do protected! - request.body.rewind # in case someone already read it - #body = request.body.read date = Time.now.strftime("%Y-%m-%dT%H:%M:%S") - # TODO hashtags, replys outbox_path = File.join("public/outbox", date + ".json") - object_path = File.join("public/objects", date + ".json") + notes_path = File.join("public/notes", date + ".json") - #recipients = ["https://www.w3.org/ns/activitystreams#Public", params[:to]] - recipients = [params[:to]] - #recipients += Dir[File.join("public/followers", "*.json")].collect { |f| JSON.parse(File.read(f))["actor"] } + recipients = ["https://www.w3.org/ns/activitystreams#Public", params[:to]] + recipients += Dir[File.join("public/followers", "*.json")].collect { |f| JSON.parse(File.read(f))["actor"] } recipients.delete ACTOR recipients.uniq! + + content = [] + attachment = [] + tag = [] + extensions = { + :image => ["jpeg","png"], + :audio => ["flac","wav","mp3","ogg"], + :video => ["mp4","webm"] + } + params[:content].lines.each do |line| + line.chomp! + if line.match(/^http/) + ext = File.extname(line).sub('.','') + media_type = extensions.select{|k,v| v.include? ext}.keys[0].to_s + '/' + ext + attachment << { + 'type' => 'Document', + 'mediaType' => media_type, + 'url' => line + } + else + tags = line.split(/\s+/).grep(/^#\w+$/) + tags.each do |name| + href = File.join(SOCIAL_URL,'tags',name.sub('#','')) + tag << { + 'type' => 'Hashtag', + 'href' => href, + 'name' => name + } + line.gsub!(name, "") + end + content << line + end + end create = { "@context" => "https://www.w3.org/ns/activitystreams", @@ -20,35 +49,23 @@ post "/outbox" do "type" => "Create", "actor" => ACTOR, "object" => { - "id" => File.join(SOCIAL_URL, object_path), + "id" => File.join(SOCIAL_URL, notes_path), "type" => "Note", "attributedTo" => ACTOR, "inReplyTo" => params[:inReplyTo], "published" => date, - "content" => params[:content], + "content" => "

\n"+content.join("\n
")+"\n

", + "attachment" => attachment, + "tag" => tag, "to" => recipients }, "published" => date, "to" => recipients } -=begin - if /^@/.match body - mentions, body = body.split("\n", 2) - mentions.split(/, */).each do |m| - recipients << actor(m.chomp) - end - end -=end - #create["object"]["content"] = body#.lines.select { |l| !l.empty? }.join("
") - #create["object"]["to"] += recipients - #create["to"] += recipients - #p params["to"] - #p create File.open(outbox_path, "w+") { |f| f.puts create.to_json } - File.open(object_path, "w+") { |f| f.puts create["object"].to_json } + File.open(notes_path, "w+") { |f| f.puts create["object"].to_json } - #p recipients create["to"].each { |r| send_signed create, r } redirect to(params['redirect']) end diff --git a/public/style.css b/public/style.css index d72fca9..affde4c 100644 --- a/public/style.css +++ b/public/style.css @@ -39,6 +39,12 @@ a { color: #888; } +textarea { + width: 50vw; + height: 50vh; + display: block; +} + @media (orientation: landscape) { button { font-size: 1em; diff --git a/views/index.erb b/views/index.erb index 269c495..0021ec9 100644 --- a/views/index.erb +++ b/views/index.erb @@ -18,4 +18,22 @@ <% end %> + diff --git a/views/item.erb b/views/item.erb index 287054e..ebc632e 100644 --- a/views/item.erb +++ b/views/item.erb @@ -35,12 +35,16 @@ <% end %> <% end %> <% end %> -
+

+ + #<%= @item[:nr] %>' /> - - + +
+ +

<% @item[:replies].each do |reply| %> -- cgit v1.2.3