summaryrefslogtreecommitdiff
path: root/client.rb
diff options
context:
space:
mode:
Diffstat (limited to 'client.rb')
-rw-r--r--client.rb47
1 files changed, 40 insertions, 7 deletions
diff --git a/client.rb b/client.rb
index 3ee3a7e..386bce5 100644
--- a/client.rb
+++ b/client.rb
@@ -29,13 +29,23 @@ post '/' do # TODO
else
tags = line.split(/\s+/).grep(/^#\w+$/)
tags.each do |name|
- href = File.join(SOCIAL_URL, 'tags', name.sub('#', ''))
+ # href = File.join(TAGS_URL, name.sub('#', ''))
+ tag_url = File.join(TAGS_URL, name.sub('#', ''))
tag << {
'type' => 'Hashtag',
- 'href' => href,
+ 'href' => tag_url,
'name' => name
}
- line.gsub!(name, "<a href='#{href}' class='mention hashtag' rel='tag'>#{name}</a>")
+ end
+
+ mentions = line.split(/\s+/).grep(/^@\w+@\S+$/)
+ mentions.each do |mention|
+ actor = actor(mention)
+ tag << {
+ 'type' => 'Mention',
+ 'href' => actor,
+ 'name' => mention
+ }
end
content << line
end
@@ -51,7 +61,25 @@ post '/' do # TODO
'to' => recipients
}
- outbox 'Create', object, recipients, true
+ activity = outbox 'Create', object, recipients, true
+ activity['object']['tag'].each do |tag|
+ next unless tag['type'] == 'Hashtag'
+
+ tag_path = File.join(TAGS_DIR, tag['name'].sub('#', '')) + '.json'
+ unless File.exist? tag_path
+ File.open(tag_path, 'w+') do |f|
+ tag_collection = {
+ '@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => tag['href'],
+ 'type' => 'OrderedCollection',
+ 'totalItems' => 0,
+ 'orderedItems' => []
+ }
+ f.puts tag_collection.to_json
+ end
+ end
+ update_collection tag_path, activity['object']['id']
+ end
redirect(params['anchor'] || '/inbox')
end
@@ -88,8 +116,13 @@ end
post '/share' do # TODO
protected!
- selection(params).each { |f| FileUtils.mv f, f.sub(%r{/inbox/}, '/shared/') }
- outbox 'Announce', params['id'], public
+ inbox = JSON.parse File.read(INBOX)
+ object = inbox['orderedItems'].find { |i| i['id'] == params['id'] }
+ update_collection SHARED, object
+ update_collection INBOX, object, true
+ recipients = public
+ recipients << object['attributedTo']
+ outbox 'Announce', params['id'], recipients
redirect(params['anchor'] || '/inbox')
end
@@ -148,7 +181,7 @@ helpers do
mention = follow
when /^http/
actor = follow
- mention = mention actor
+ mention = mention(actor)
when /^@*\w+@\w+/
mention = follow
actor = actor(follow)