Class: MTProto::Type::RPC::Messages::Updates

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/type/rpc/messages/updates.rb

Constant Summary collapse

CONSTRUCTOR_UPDATES =
0x74ae4240
CONSTRUCTOR_UPDATE_SHORT =
0x78d4dec1
CONSTRUCTOR_UPDATE_SHORT_MESSAGE =
0x313bc7f8
CONSTRUCTOR_UPDATE_SHORT_CHAT_MESSAGE =
0x4d6deea5
CONSTRUCTOR_UPDATE_SHORT_SENT_MESSAGE =
0x9015e101

Class Method Summary collapse

Class Method Details

.parse(response) ⇒ Object



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
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
79
80
81
82
# File 'lib/mtproto/type/rpc/messages/updates.rb', line 17

def self.parse(response)
  offset = 0

  constructor = response[offset, 4].unpack1('L<')
  offset += 4

  if constructor == Type::GzipPacked::CONSTRUCTOR
    response = Type::GzipPacked.unpack(response)
    constructor = response[0, 4].unpack1('L<')
    offset = 4
  end

  if constructor == Type::RpcError::CONSTRUCTOR
    error = Type::RpcError.deserialize(response)
    raise MTProto::RpcError.new(error.error_code, error.error_message)
  end

  case constructor
  when CONSTRUCTOR_UPDATE_SHORT_SENT_MESSAGE
    # updateShortSentMessage#11f1331c flags:# out:flags.1?true id:int pts:int pts_count:int date:int media:flags.9?MessageMedia entities:flags.7?Vector<MessageEntity> ttl_period:flags.25?int = Updates;
    flags = response[offset, 4].unpack1('L<')
    offset += 4

    message_id = response[offset, 4].unpack1('L<')
    offset += 4

    pts = response[offset, 4].unpack1('L<')
    offset += 4

    pts_count = response[offset, 4].unpack1('L<')
    offset += 4

    date = response[offset, 4].unpack1('L<')
    offset += 4

    {
      sent: true,
      message_id: message_id,
      date: date,
      pts: pts,
      pts_count: pts_count
    }

  when CONSTRUCTOR_UPDATE_SHORT_MESSAGE, CONSTRUCTOR_UPDATE_SHORT_CHAT_MESSAGE
    # updateShortMessage#2296d2c8 or updateShortChatMessage#402d5dbb
    # Both have similar structure with flags, id, etc.
    flags = response[offset, 4].unpack1('L<')
    offset += 4

    message_id = response[offset, 4].unpack1('L<')

    {
      sent: true,
      message_id: message_id
    }

  when CONSTRUCTOR_UPDATES, CONSTRUCTOR_UPDATE_SHORT
    # For full updates or updateShort, just confirm success
    {
      sent: true
    }

  else
    raise "Unknown Updates constructor: 0x#{constructor.to_s(16)}"
  end
end