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 ++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 24 deletions(-) (limited to 'client.rb') 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 -- cgit v1.2.3