From c967802c4351f34d5c62e52b72c7d5c2d72ffba3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 24 Feb 2016 18:44:03 +0100 Subject: [PATCH] Notify remote users about mentions --- app/api/mastodon/entities.rb | 31 +++++++++++++++++++++++++++-- app/api/mastodon/rest.rb | 6 +++--- app/services/post_status_service.rb | 9 +++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/api/mastodon/entities.rb b/app/api/mastodon/entities.rb index 2e56a67df..975e72538 100644 --- a/app/api/mastodon/entities.rb +++ b/app/api/mastodon/entities.rb @@ -1,17 +1,44 @@ module Mastodon module Entities class Account < Grape::Entity + include ApplicationHelper + + expose :id expose :username - expose :domain + + expose :domain do |account| + account.local? ? LOCAL_DOMAIN : account.domain + end + expose :display_name expose :note + + expose :url do |account| + account.local? ? profile_url(name: account.username) : account.url + end end class Status < Grape::Entity + include ApplicationHelper + format_with(:iso_timestamp) { |dt| dt.iso8601 } - expose :uri + expose :id + + expose :uri do |status| + status.local? ? unique_tag(status.stream_entry.created_at, status.stream_entry.activity_id, status.stream_entry.activity_type) : status.uri + end + + expose :url do |status| + status.local? ? status_url(name: status.account.username, id: status.id) : status.url + end + expose :text + expose :in_reply_to_id + + expose :reblog_of_id + expose :reblog, using: Mastodon::Entities::Status + expose :account, using: Mastodon::Entities::Account with_options(format_with: :iso_timestamp) do diff --git a/app/api/mastodon/rest.rb b/app/api/mastodon/rest.rb index eaf337938..25a53202b 100644 --- a/app/api/mastodon/rest.rb +++ b/app/api/mastodon/rest.rb @@ -3,11 +3,11 @@ module Mastodon version 'v1', using: :path format :json - resource :statuses do + resource :timelines do desc 'Return a public timeline' - get :all do - present Status.all, with: Mastodon::Entities::Status + get :public do + # todo end desc 'Return the home timeline of a logged in user' diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index e8fc6cdef..39bbe9f9e 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -9,6 +9,11 @@ class PostStatusService < BaseService next unless local_account.nil? follow_remote_account_service.("acct:#{match.first}") end + + status.mentions.each do |mentioned_account| + next if mentioned_account.local? + send_interaction_service.(status.stream_entry, mentioned_account) + end end private @@ -16,4 +21,8 @@ class PostStatusService < BaseService def follow_remote_account_service @follow_remote_account_service ||= FollowRemoteAccountService.new end + + def send_interaction_service + @send_interaction_service ||= SendInteractionService.new + end end