Class: MTProto::TL::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/tl/objects/messages.rb

Overview

A messages.messages / messagesSlice / channelMessages container (e.g. the messages.getHistory / messages.getMessages reply). Its messages are TL::Message instances.

Constant Summary collapse

MESSAGES_MESSAGES =
0x1d73e7ea
MESSAGES_SLICE =
0x5f206716
MESSAGES_CHANNEL =
0xc776ba4e
VALID_CONSTRUCTORS =
[MESSAGES_MESSAGES, MESSAGES_SLICE, MESSAGES_CHANNEL].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages:, count: nil, users: [], chats: []) ⇒ Messages

Returns a new instance of Messages.



21
22
23
24
25
26
# File 'lib/mtproto/tl/objects/messages.rb', line 21

def initialize(messages:, count: nil, users: [], chats: [])
  @messages = messages
  @count = count
  @users = users
  @chats = chats
end

Instance Attribute Details

#chatsObject (readonly)

Returns the value of attribute chats.



19
20
21
# File 'lib/mtproto/tl/objects/messages.rb', line 19

def chats
  @chats
end

#countObject (readonly)

Returns the value of attribute count.



19
20
21
# File 'lib/mtproto/tl/objects/messages.rb', line 19

def count
  @count
end

#messagesObject (readonly)

Returns the value of attribute messages.



19
20
21
# File 'lib/mtproto/tl/objects/messages.rb', line 19

def messages
  @messages
end

#usersObject (readonly)

Returns the value of attribute users.



19
20
21
# File 'lib/mtproto/tl/objects/messages.rb', line 19

def users
  @users
end

Class Method Details

.deserialize(data) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mtproto/tl/objects/messages.rb', line 38

def self.deserialize(data)
  constructor = data[0, 4].unpack1('L<')
  raise UnexpectedConstructorError, constructor unless VALID_CONSTRUCTORS.include?(constructor)

  offset = 4
  count = nil

  case constructor
  when MESSAGES_MESSAGES
    # messages:Vector<Message> chats:Vector<Chat> users:Vector<User>
  when MESSAGES_SLICE
    # flags:# count:int next_rate:flags.0?int offset_id_offset:flags.2?int
    # search_flood:flags.3?SearchPostsFlood messages:Vector<Message> ...
    flags = data[offset, 4].unpack1('L<')
    offset += 4
    count = data[offset, 4].unpack1('L<')
    offset += 4
    offset += 4 if flags.anybits?(1 << 0) # next_rate
    offset += 4 if flags.anybits?(1 << 2) # offset_id_offset
    offset = schema.skip(data, offset) if flags.anybits?(1 << 3) # search_flood
  when MESSAGES_CHANNEL
    # flags:# pts:int count:int offset_id_offset:flags.2?int
    # messages:Vector<Message> topics:Vector<ForumTopic> ...
    flags = data[offset, 4].unpack1('L<')
    offset += 4
    offset += 4 # pts
    count = data[offset, 4].unpack1('L<')
    offset += 4
    offset += 4 if flags.anybits?(1 << 2) # offset_id_offset
  end

  messages, offset = parse_messages_vector(data, offset)

  # topics:Vector<ForumTopic> precedes chats/users in all three constructors
  offset = schema.skip_vector(data, offset) { |d, o| schema.skip(d, o) }

  chats, offset = Dialogs.chats_at(data, offset)
  users, = Dialogs.users_at(data, offset)

  new(messages: messages, count: count, users: users, chats: chats)
end

.schemaObject



32
33
34
35
36
# File 'lib/mtproto/tl/objects/messages.rb', line 32

def self.schema
  @schema ||= Schema.new(
    File.expand_path('../../../../data/tl-schema.json', __dir__)
  )
end

Instance Method Details

#slice?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mtproto/tl/objects/messages.rb', line 28

def slice?
  !@count.nil?
end