Class: MTProto::TL::ChannelDifference

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

Overview

updates.ChannelDifference — the reply to updates.getChannelDifference: a channel/supergroup's backlog since a given pts. Channels aren't pushed to a fresh session, so the client pulls this. Three variants:

channelDifference        — new_messages + other_updates + chats + users, with the new pts
channelDifferenceEmpty   — nothing new since pts (just pts/final/timeout)
channelDifferenceTooLong — gap too large: a Dialog snapshot + a messages slice
                         + chats + users; the caller resyncs pts from the dialog

Mirrors UpdatesDifference: reads only the surfaced fields and advances the rest via Schema#skip (zero-drop, robust to an unmodelled tail).

Constant Summary collapse

SCHEMA_PATH =
File.expand_path('../../../../data/tl-schema.json', __dir__)
UPDATE_NEW_MESSAGE =

Channel messages ride in new_messages, but message-bearing updates can also appear in other_updates — mine those too, like UpdatesDifference.

0x1f2b0afd
UPDATE_NEW_CHANNEL_MESSAGE =
0x62ba04d9

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, final: false, pts: nil, timeout: nil, new_messages: [], chats: [], users: []) ⇒ ChannelDifference

Returns a new instance of ChannelDifference.



28
29
30
31
32
33
34
35
36
# File 'lib/mtproto/tl/objects/channel_difference.rb', line 28

def initialize(type:, final: false, pts: nil, timeout: nil, new_messages: [], chats: [], users: [])
  @type = type
  @final = final
  @pts = pts
  @timeout = timeout
  @new_messages = new_messages
  @chats = chats
  @users = users
end

Instance Attribute Details

#chatsObject (readonly)

Returns the value of attribute chats.



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

def chats
  @chats
end

#finalObject (readonly)

Returns the value of attribute final.



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

def final
  @final
end

#new_messagesObject (readonly)

Returns the value of attribute new_messages.



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

def new_messages
  @new_messages
end

#ptsObject (readonly)

Returns the value of attribute pts.



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

def pts
  @pts
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#usersObject (readonly)

Returns the value of attribute users.



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

def users
  @users
end

Class Method Details

.deserialize(data) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mtproto/tl/objects/channel_difference.rb', line 42

def self.deserialize(data)
  constructor = data[0, 4].unpack1('L<')

  case constructor
  when Constructors::UPDATES_CHANNEL_DIFFERENCE_EMPTY
    parse_empty(data)
  when Constructors::UPDATES_CHANNEL_DIFFERENCE
    parse_difference(data)
  when Constructors::UPDATES_CHANNEL_DIFFERENCE_TOO_LONG
    parse_too_long(data)
  else
    warn "Unknown ChannelDifference constructor: 0x#{constructor.to_s(16)}, treating as empty"
    new(type: :empty, final: true)
  end
end

.schemaObject



38
39
40
# File 'lib/mtproto/tl/objects/channel_difference.rb', line 38

def self.schema
  @schema ||= Schema.new(SCHEMA_PATH)
end