Debian Codegraph @

plugin/mastodon_sse_streaming/handler/favorite.rb

raw symbols SCIP
1 # frozen_string_literal: true
2
3 module Plugin::MastodonSseStreaming::Handler
4 class Favorite
5 # @param [Plugin::Mastodon::SSEAuthorizedType|Plugin::Mastodon::SSEPublicType] connection_type
6 # @yield [user, message] SSEで受信したfavoriteひとつにつき一度呼ばれる
7 # @yieldparam [Plugin::Mastodon::Account] user ふぁぼったユーザ
8 # @yieldparam [Plugin::Mastodon::Status] message ふぁぼられたToot
9 def initialize(connection_type, &receiver)
10 @connection_type = connection_type
11 @receiver = receiver
12 end
13
14 # @params [String] event
15 # @params [Hash] payload
16 def call(event, payload)
17 return if event != 'notification'
18 case payload
19 in type: 'favourite', account: Hash => account, status: Hash => status
20 user = Plugin::Mastodon::Account.new(account)
21 message = Plugin::Mastodon::Status.build(@connection_type.server, status)
22 message.favorite_accts << user.acct
23 message.set_modified(Time.now.localtime) if favorite_age?(user)
24 @receiver.(user, message)
25 else
26 # noop
27 end
28 end
29
30 private
31
32 def favorite_age?(user)
33 if user.me?
34 UserConfig[:favorited_by_myself_age]
35 else
36 UserConfig[:favorited_by_anyone_age]
37 end
38 end
39 end
40 end