diff options
Diffstat (limited to 'client.rb')
-rw-r--r-- | client.rb | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -2,10 +2,10 @@ # client-server -['/inbox', '/outbox'].each do |path| +['/inbox/threads', '/outbox/threads'].each do |path| get path do protected! - box = path.sub('/', '') + box = path.sub('/', '').sub('/threads', '') collection = Dir[File.join(box, 'object', '*', '*.json')].collect { |f| JSON.parse(File.read(f)) } threads = [] collection.collect! do |object| @@ -42,20 +42,18 @@ end post '/follow' do protected! - actor, = parse_follow params['follow'] - outbox 'Follow', actor, [actor] + params['id'] = actor params['mention'] if params['mention'] + outbox 'Follow', params['id'], [params['id']] end post '/unfollow' do protected! - actor, mention = parse_follow params['follow'] - Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].each do |f| - activity = JSON.parse(File.read(f)) - if activity['object'] == actor - outbox 'Undo', activity, [actor] - update_collection FOLLOWING, actor, true - end - end + params['id'] = actor params['mention'] if params['mention'] + following = Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].collect { |f| JSON.parse(File.read(f)) } + activity = following.find { |a| a['object'] == params['id'] } + activity ||= save_activity({ 'type' => 'Follow', 'actor' => ACTOR, 'object' => params['id'] }, OUTBOX) # recreate activity for old/deleted follows + outbox 'Undo', activity, [params['id']] + update_collection FOLLOWING, params['id'], true end post '/share' do # TODO @@ -64,7 +62,7 @@ post '/share' do # TODO object = JSON.parse(File.read(src)) recipients = public recipients << object['attributedTo'] - # outbox 'Announce', object, recipients + outbox 'Announce', object, recipients dest = src.sub('/inbox/', '/outbox/') FileUtils.mkdir_p File.dirname(dest) FileUtils.mv src, dest @@ -80,9 +78,9 @@ helpers do end def find_file(id) - Dir[File.join('*', 'object', '*', '*.json')].select do |f| + Dir[File.join('*', 'object', '*', '*.json')].find do |f| JSON.parse(File.read(f))['id'] == id - end[0] + end end def public |