mtproto 0.0.25 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80959bb3b78feec884c2b2f7700acd8dea584f1f14625c1d686e8205e69ad264
4
- data.tar.gz: 438f752fc31967355e0332cccc5f351fb9d23feed97f7f3eabba6cf2264ebdc0
3
+ metadata.gz: 71e2dc92efcb9cd07a9c3e7775c4d6bbbdad63323ac0f35f84b53ba0b8969052
4
+ data.tar.gz: ac178d6cca88867167bd65e618fbc306d7ee0d7fb037a5f0916bfa1e04e87034
5
5
  SHA512:
6
- metadata.gz: 2d73ecabf9a26825c15f231013de62256fd5b0b068b3e0b1b9c0e70755e84e8191d89eb8b9d4b2ae75bbd36974771a250367097217bff8a68cb743729ef41f3e
7
- data.tar.gz: 492d3760bc9c5787a52666cef213aaf73987bd075fd008bf331b1c9e08deb9e28cbc52d58467bd1676a68a8cf900d6dec8af131eea38a00fe8238d6ebf8748cf
6
+ metadata.gz: c68fb62846077b9be4e0c401741ffb5f027b2e63fbf4e4eeef1ea69544210ac3eb7de3ad15ab13890895fcaa20631488e72843192ad0f34aaef66c44118f9318
7
+ data.tar.gz: f61aa4190e8de25d164197c8191b8929476336d1249f5f500abb8b8f05c7e2b9a10b09edf12bcb9fc12076be965d535ef14df13e6d5456c857adb261b61166d0
@@ -101,6 +101,8 @@ module MTProto
101
101
  # Upload + media
102
102
  UPLOAD_SAVE_FILE_PART = 0xb304a621
103
103
  INPUT_FILE = 0xf52ff27f
104
+ UPLOAD_SAVE_BIG_FILE_PART = 0xde7b673d
105
+ INPUT_FILE_BIG = 0xfa4f0bb5
104
106
  INPUT_MEDIA_UPLOADED_PHOTO = 0x7d8375da
105
107
  INPUT_MEDIA_UPLOADED_DOCUMENT = 0x037c9330
106
108
  DOCUMENT_ATTRIBUTE_FILENAME = 0x15590068
@@ -22,7 +22,8 @@ module MTProto
22
22
 
23
23
  FIELDS = %i[id date message peer_type peer_id from_type from_id out media
24
24
  document photo is_reply reply_to_msg_id reply_to_peer_type reply_to_peer_id
25
- is_quote quote_text quote_offset entities fwd_from_type fwd_from_id].freeze
25
+ is_quote quote_text quote_offset entities fwd_from_type fwd_from_id
26
+ fwd_channel_post].freeze
26
27
 
27
28
  attr_reader(*FIELDS)
28
29
 
@@ -56,9 +57,9 @@ module MTProto
56
57
  _, offset = x.read_tl_string(data, offset) if flags2.anybits?(1 << 12) # from_rank (layer 227)
57
58
  peer_type, peer_id, offset = x.parse_peer(data, offset)
58
59
  offset = x.schema.skip(data, offset) if flags.anybits?(1 << 28) # saved_peer_id
59
- fwd_from_type = fwd_from_id = nil
60
+ fwd_from_type = fwd_from_id = fwd_channel_post = nil
60
61
  if flags.anybits?(1 << 2) # fwd_from
61
- fwd_from_type, fwd_from_id = parse_fwd_origin(data, offset)
62
+ fwd_from_type, fwd_from_id, fwd_channel_post = parse_fwd_origin(data, offset)
62
63
  offset = x.schema.skip(data, offset)
63
64
  end
64
65
  offset += 8 if flags.anybits?(1 << 11) # via_bot_id
@@ -87,7 +88,8 @@ module MTProto
87
88
  reply_to_peer_type: reply && reply[:peer_type], reply_to_peer_id: reply && reply[:peer_id],
88
89
  is_quote: reply ? reply[:is_quote] : false, quote_text: reply && reply[:quote_text],
89
90
  quote_offset: reply && reply[:quote_offset], entities: entities,
90
- fwd_from_type: fwd_from_type, fwd_from_id: fwd_from_id)
91
+ fwd_from_type: fwd_from_type, fwd_from_id: fwd_from_id,
92
+ fwd_channel_post: fwd_channel_post)
91
93
  end
92
94
 
93
95
  private
@@ -112,21 +114,26 @@ module MTProto
112
114
  end
113
115
 
114
116
  # messageFwdHeader#4e4df4bb flags:# imported:flags.7?true from_id:flags.0?Peer
115
- # ... — from_id is the forward origin (a peerChannel for a forwarded channel
116
- # post). imported (flags.7) is a flag-only bool, so from_id sits right after
117
- # the flags. => [type, id] or [nil, nil].
117
+ # from_name:flags.5?string date:int channel_post:flags.2?int ... — from_id is the
118
+ # forward origin (a peerChannel for a forwarded channel post); channel_post is that
119
+ # post's id inside the origin channel. imported (flags.7) is a flag-only bool, so
120
+ # from_id sits right after the flags; date is unconditional. => [type, id,
121
+ # channel_post], each element nil when its field is absent.
118
122
  def parse_fwd_origin(data, offset)
119
- return [nil, nil] unless data[offset, 4].unpack1('L<') == MESSAGE_FWD_HEADER
123
+ return [nil, nil, nil] unless data[offset, 4].unpack1('L<') == MESSAGE_FWD_HEADER
120
124
 
121
125
  io = offset + 4
122
126
  flags = data[io, 4].unpack1('L<')
123
127
  io += 4
124
- return [nil, nil] unless flags.anybits?(1 << 0) # from_id present
128
+ return [nil, nil, nil] unless flags.anybits?(1 << 0) # from_id present
125
129
 
126
- type, id, = x.parse_peer(data, io)
127
- [type, id]
130
+ type, id, io = x.parse_peer(data, io)
131
+ _, io = x.read_tl_string(data, io) if flags.anybits?(1 << 5) # from_name
132
+ io += 4 # date:int (unconditional)
133
+ channel_post = data[io, 4].unpack1('l<') if flags.anybits?(1 << 2) # channel_post
134
+ [type, id, channel_post]
128
135
  rescue StandardError
129
- [nil, nil]
136
+ [nil, nil, nil]
130
137
  end
131
138
  end
132
139
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MTProto
4
+ module TL
5
+ class SaveBigFilePart
6
+ include Binary
7
+
8
+ def initialize(file_id:, file_part:, file_total_parts:, bytes:)
9
+ @file_id = file_id
10
+ @file_part = file_part
11
+ @file_total_parts = file_total_parts
12
+ @bytes = bytes
13
+ end
14
+
15
+ def serialize
16
+ u32_b(Constructors::UPLOAD_SAVE_BIG_FILE_PART) +
17
+ u64_b(@file_id) +
18
+ u32_b(@file_part) +
19
+ u32_b(@file_total_parts) +
20
+ serialize_tl_bytes(@bytes)
21
+ end
22
+
23
+ private
24
+
25
+ def serialize_tl_bytes(bytes)
26
+ bytes = bytes.bytes if bytes.is_a?(String)
27
+ length = bytes.length
28
+
29
+ if length <= 253
30
+ [length] + bytes + padding(length + 1)
31
+ else
32
+ [254] + u32_b(length)[0, 3] + bytes + padding(length + 4)
33
+ end
34
+ end
35
+
36
+ def padding(current_length)
37
+ pad_length = (4 - (current_length % 4)) % 4
38
+ [0] * pad_length
39
+ end
40
+ end
41
+ end
42
+ end
@@ -133,6 +133,8 @@ module MTProto
133
133
  end
134
134
 
135
135
  def serialize_input_file(file)
136
+ return serialize_input_file_big(file) if file[:big]
137
+
136
138
  u32_b(Constructors::INPUT_FILE) +
137
139
  u64_b(file[:id]) +
138
140
  u32_b(file[:parts]) +
@@ -140,6 +142,13 @@ module MTProto
140
142
  serialize_tl_string(file[:md5_checksum].to_s)
141
143
  end
142
144
 
145
+ def serialize_input_file_big(file)
146
+ u32_b(Constructors::INPUT_FILE_BIG) +
147
+ u64_b(file[:id]) +
148
+ u32_b(file[:parts]) +
149
+ serialize_tl_string(file[:name].to_s)
150
+ end
151
+
143
152
  def serialize_tl_string(str)
144
153
  serialize_byte_array(str.encode('UTF-8').bytes)
145
154
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MTProto
4
- VERSION = '0.0.25'
4
+ VERSION = '0.0.26'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtproto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Levenkov
@@ -185,6 +185,7 @@ files:
185
185
  - lib/mtproto/tl/objects/reset_bot_commands.rb
186
186
  - lib/mtproto/tl/objects/resolve_username.rb
187
187
  - lib/mtproto/tl/objects/rpc_error.rb
188
+ - lib/mtproto/tl/objects/save_big_file_part.rb
188
189
  - lib/mtproto/tl/objects/save_file_part.rb
189
190
  - lib/mtproto/tl/objects/search.rb
190
191
  - lib/mtproto/tl/objects/send_bot_requested_peer.rb