Browse Source

Service to reblog statuses

Eugen Rochko 4 years ago
parent
commit
42eeecba3f
2 changed files with 25 additions and 0 deletions
  1. 7
    0
      app/services/post_status_service.rb
  2. 18
    0
      app/services/reblog_service.rb

+ 7
- 0
app/services/post_status_service.rb View File

@@ -1,4 +1,9 @@
1 1
 class PostStatusService < BaseService
2
+  # Post a text status update, fetch and notify remote users mentioned
3
+  # @param [Account] account Account from which to post
4
+  # @param [String] text Message
5
+  # @param [Status] in_reply_to Optional status to reply to
6
+  # @return [Status]
2 7
   def call(account, text, in_reply_to = nil)
3 8
     status = account.statuses.create!(text: text, thread: in_reply_to)
4 9
 
@@ -14,6 +19,8 @@ class PostStatusService < BaseService
14 19
       next if mentioned_account.local?
15 20
       send_interaction_service.(status.stream_entry, mentioned_account)
16 21
     end
22
+
23
+    status
17 24
   end
18 25
 
19 26
   private

+ 18
- 0
app/services/reblog_service.rb View File

@@ -0,0 +1,18 @@
1
+class ReblogService < BaseService
2
+  # Reblog a status and notify its remote author
3
+  # @param [Account] account Account to reblog from
4
+  # @param [Status] reblogged_status Status to be reblogged
5
+  # @return [Status]
6
+  def call(account, reblogged_status)
7
+    reblog = account.statuses.create!(reblog: reblogged_status, text: '')
8
+    return reblog if reblogged_status.local?
9
+    send_interaction_service.(reblog.stream_entry, reblogged_status.account)
10
+    reblog
11
+  end
12
+
13
+  private
14
+
15
+  def send_interaction_service
16
+    @send_interaction_service ||= SendInteractionService.new
17
+  end
18
+end

Loading…
Cancel
Save