| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | module Plugin::MastodonSseStreaming::Handler |
| 4 | class Mention |
| 5 | # @param [Plugin::Mastodon::SSEAuthorizedType|Plugin::Mastodon::SSEPublicType] connection_type |
| 6 | # @yield [user, message] SSEで受信したmentionひとつにつき一度呼ばれる |
| 7 | # @yieldparam [Plugin::Mastodon::Status] message 受信したMention |
| 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 != 'notification' |
| 17 | case payload |
| 18 | in type: 'mention', status: Hash => status |
| 19 | @receiver.(Plugin::Mastodon::Status.build(@connection_type.server, status)) |
| 20 | else |
| 21 | # noop |
| 22 | end |
| 23 | end |
| 24 | end |
| 25 | end |