| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | module Plugin::MastodonSseStreaming::Handler |
| 4 | class Update |
| 5 | # @param [Plugin::Mastodon::SSEAuthorizedType|Plugin::Mastodon::SSEPublicType] connection_type |
| 6 | # @yield [message] SSEで受信したTootひとつにつき一度呼ばれる |
| 7 | # @yieldparam [Plugin::Mastodon::Status] message 受信したToot |
| 8 | def initialize(connection_type, &receiver) |
| 9 | @connection_type = connection_type |
| 10 | @receiver = receiver |
| 11 | end |
| 12 | |
| 13 | # @params [String] event |
| 14 | # @params [Hash] payload |
| 15 | def call(event, payload) |
| 16 | return if event != 'update' |
| 17 | message = Plugin::Mastodon::Status.build(@connection_type.server, payload) |
| 18 | if message |
| 19 | @receiver.(message) |
| 20 | Plugin.call(:update, nil, [message]) # 互換性のため |
| 21 | end |
| 22 | end |
| 23 | end |
| 24 | end |