Class: Pubnub::FetchMessages

Inherits:
SingleEvent show all
Includes:
Concurrent::Async, Validator::FetchMessages
Defined in:
lib/pubnub/events/fetch_messages.rb

Overview

Holds functionality to fetch:

  • batch messages (for multiple channels)
  • messages with message actions.

Instance Attribute Summary

Attributes inherited from Event

#callback, #channel, #channel_group, #fresh_clone, #given_options, #group, #idle_timeout, #open_timeout, #origin, #presence_callback, #read_timeout, #ssl, #state, #wildcard_channel, #with_presence

Instance Method Summary collapse

Methods included from Validator::FetchMessages

#validate!

Methods included from Validator::CommonValidator

#validate_origin, #validate_publish_key, #validate_subscribe_key, #validate_user_id

Methods inherited from Event

#finalized?, #fire, #send_request, #sync?, #uri

Methods included from Event::EFormatter

#format_channels, #format_envelopes, #format_group

Constructor Details

#initialize(options, app) ⇒ FetchMessages

Returns a new instance of FetchMessages.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pubnub/events/fetch_messages.rb', line 11

def initialize(options, app)
  @telemetry_name = :l_hist
  @include_custom_message_type = options.fetch(:include_custom_message_type, false)
  @include_message_actions = options.fetch(:include_message_actions, false)
  @include_message_type = options.fetch(:include_message_type, true)
  @encode_channels = options.fetch(:encode_channels, true)
  @include_uuid = options.fetch(:include_uuid, true)
  @include_meta = options.fetch(:include_meta, false)
  @start = options[:start] if options.key?(:start)
  @end = options[:end] if options.key?(:end)

  channel = options[:channel] if options.key?(:channel) && !options[:channel].empty?
  @channels = options[:channels] if options.key?(:channels) && !options[:channels].empty?
  if @include_message_actions
    @channel = channel
  elsif @channels.nil? && !channel.nil?
    @channels = [channel]
    @channel = nil
    options.delete :channel
  end

  maximum = @include_message_actions || @channels&.size == 1 ? 100 : 25
  @max = [options[:max], maximum].min unless options[:max].nil?

  @event = current_operation

  # Override crypto module if custom cipher key has been used.
  random_iv = options.key?(:random_iv) ? options[:random_iv] : true
  options[:crypto_module] = Crypto::CryptoModule.new_legacy(options[:cipher_key], random_iv) if options[:cipher_key]

  super
end