diff options
author | pdp8 <pdp8@pdp8.info> | 2023-06-26 11:20:38 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-06-26 11:20:38 +0200 |
commit | 8453f524515941f3c0a65b5ca3b9354be76b4c33 (patch) | |
tree | c33131d99193f5a5875ae1869e8cafa11e2a803e | |
parent | cec92f7d472c53bdd5d2aa480179ee30c27e8b38 (diff) |
hidden reply form
-rw-r--r-- | client.rb | 65 | ||||
-rw-r--r-- | public/style.css | 6 | ||||
-rw-r--r-- | views/index.erb | 18 | ||||
-rw-r--r-- | views/item.erb | 10 |
4 files changed, 72 insertions, 27 deletions
@@ -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, "<a href='#{href}' class='mention hashtag' rel='tag'>#{name}</a>") + 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" => "<p>\n"+content.join("\n<br>")+"\n</p>", + "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("<br>") - #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 @@ </form> <% end %> </body> + <script> + const reply_buttons = document.querySelectorAll(".reply"); + for (const button of reply_buttons) { + button.addEventListener('click', function() { + const form = document.getElementById('form' + button.getAttribute('data-index')); + button.style.display = 'none'; + form.style.display = 'block'; + }); + }; + const cancel_buttons = document.querySelectorAll(".cancel"); + for (const button of cancel_buttons) { + button.addEventListener('click', function() { + const form = document.getElementById('form' + button.getAttribute('data-index')); + button.style.display = 'block'; + form.style.display = 'none'; + }); + }; + </script> </html> 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 %> - <form action='/outbox' method='post'> + <p> + <button class="reply" data-index='<%= @item[:nr] %>'>Reply</button> + <form action='/outbox' method='post' id='form<%= @item[:nr] %>' style='display:none;' > <input type='hidden' name='to' value='<%= @item[:actor_url] %>' /> <input type='hidden' name='inReplyTo' value='<%= @item[:id] %>' /> <input type='hidden' name='redirect' value='/<%= @dir.sub('inbox','') %>#<%= @item[:nr] %>' /> - <textarea name="content"></textarea> - <input type="submit" value="Reply"> + <textarea name='content'></textarea> + <br> + <button class="cancel" data-index='<%= @item[:nr] %>'>Cancel</button> + <input type='submit' value='Send'> </form> </div> <% @item[:replies].each do |reply| %> |