summaryrefslogtreecommitdiff
path: root/client.rb
diff options
context:
space:
mode:
Diffstat (limited to 'client.rb')
-rw-r--r--client.rb65
1 files changed, 41 insertions, 24 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, "<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