about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-02-24 18:25:04 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-02-24 18:25:04 +0100
commit79609d62705fa7060c1d1ab78234b4aabdbd7e0f (patch)
tree12cef6a016a9052fdfb0d39ac10df8eab55d46a3 /app/services
parent8da8387afee66e17b3ec864ba84a7a065187818b (diff)
Add service for posting statuses (normal and replies), mention regex to
fetch webfinger information of mentioned accounts
Diffstat (limited to 'app/services')
-rw-r--r--app/services/post_status_service.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
new file mode 100644
index 000000000..e8fc6cdef
--- /dev/null
+++ b/app/services/post_status_service.rb
@@ -0,0 +1,19 @@
+class PostStatusService < BaseService
+  def call(account, text, in_reply_to = nil)
+    status = account.statuses.create!(text: text, thread: in_reply_to)
+
+    status.text.scan(Account::MENTION_RE).each do |match|
+      next if match.first.split('@').size == 1
+      username, domain = match.first.split('@')
+      local_account = Account.find_by(username: username, domain: domain)
+      next unless local_account.nil?
+      follow_remote_account_service.("acct:#{match.first}")
+    end
+  end
+
+  private
+
+  def follow_remote_account_service
+    @follow_remote_account_service ||= FollowRemoteAccountService.new
+  end
+end