mtproto 0.0.19 → 0.0.20

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.
@@ -41,21 +41,48 @@ module MTProto
41
41
  end
42
42
  end
43
43
 
44
- # messageReplyHeader: ctor, flags, reply_to_msg_id:flags.4?int (first payload
45
- # field). A plain message in a forum topic carries this header (forum_topic
46
- # flags.3) but is a reply only when it targets a message in the topic
47
- # (reply_to_top_id flags.1). => [reply_to_msg_id, is_reply]
44
+ # messageReplyHeader#1b97dd66: flags, then (in wire order) reply_to_msg_id
45
+ # flags.4?int, reply_to_peer_id flags.0?Peer, reply_from flags.5?MessageFwdHeader,
46
+ # reply_media flags.8?MessageMedia, reply_to_top_id flags.1?int, quote_text
47
+ # flags.6?string, quote_entities flags.7?Vector<MessageEntity>, quote_offset
48
+ # flags.10?int. A manual quote sets flags.9 and carries quote_text/offset — the
49
+ # fragment the user selected out of the replied-to message. The quote fields sit
50
+ # past the variable-length reply_from/reply_media, so we walk the whole header to
51
+ # reach them (reply_from/reply_media are sized via the schema). A plain message
52
+ # in a forum topic carries this header (forum_topic flags.3) but is a reply only
53
+ # when it targets a message in the topic (reply_to_top_id flags.1). Returns a
54
+ # descriptor hash, or nil for a non-messageReplyHeader (e.g. a story reply).
48
55
  def parse_reply_to(data, offset)
49
- return [nil, false] unless data[offset, 4].unpack1('L<') == MESSAGE_REPLY_HEADER
56
+ return unless data[offset, 4].unpack1('L<') == MESSAGE_REPLY_HEADER
50
57
 
51
58
  io = offset + 4
52
59
  flags = data[io, 4].unpack1('L<')
53
60
  io += 4
54
61
  forum_topic = flags.anybits?(1 << 3)
55
- msg_id = flags.anybits?(1 << 4) ? data[io, 4].unpack1('l<') : nil
56
- [msg_id, forum_topic ? flags.anybits?(1 << 1) : true]
62
+
63
+ msg_id = nil
64
+ if flags.anybits?(1 << 4) # reply_to_msg_id
65
+ msg_id = data[io, 4].unpack1('l<')
66
+ io += 4
67
+ end
68
+
69
+ peer_type = peer_id = nil
70
+ peer_type, peer_id, io = parse_peer(data, io) if flags.anybits?(1 << 0) # reply_to_peer_id
71
+
72
+ io = schema.skip(data, io) if flags.anybits?(1 << 5) # reply_from
73
+ io = schema.skip(data, io) if flags.anybits?(1 << 8) # reply_media
74
+ io += 4 if flags.anybits?(1 << 1) # reply_to_top_id
75
+
76
+ quote_text = nil
77
+ quote_text, io = read_tl_string(data, io) if flags.anybits?(1 << 6)
78
+ io = schema.skip_vector(data, io) if flags.anybits?(1 << 7) # quote_entities
79
+ quote_offset = flags.anybits?(1 << 10) ? data[io, 4].unpack1('l<') : nil
80
+
81
+ { msg_id: msg_id, is_reply: forum_topic ? flags.anybits?(1 << 1) : true,
82
+ is_quote: flags.anybits?(1 << 9), quote_text: quote_text, quote_offset: quote_offset,
83
+ peer_type: peer_type, peer_id: peer_id }
57
84
  rescue StandardError
58
- [nil, false]
85
+ nil
59
86
  end
60
87
 
61
88
  # Classify message media into :photo / :video / :audio / :document, or nil.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MTProto
4
- VERSION = '0.0.19'
4
+ VERSION = '0.0.20'
5
5
  end
data/lib/mtproto.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'mtproto/version'
4
4
  require_relative 'mtproto/errors'
5
5
  require_relative 'mtproto/binary'
6
+ require_relative 'mtproto/dc'
6
7
  require_relative 'mtproto/delegate_methods'
7
8
  require_relative 'mtproto/transport/errors'
8
9
  require_relative 'mtproto/transport/packet'
@@ -13,6 +14,8 @@ require_relative 'mtproto/unencrypted_message'
13
14
  require_relative 'mtproto/tl/constructors'
14
15
  require_relative 'mtproto/tl/constructor_names'
15
16
  require_relative 'mtproto/tl/reader'
17
+ require_relative 'mtproto/tl/message_entity'
18
+ require_relative 'mtproto/markdown'
16
19
  require_relative 'mtproto/tl/object'
17
20
  require_relative 'mtproto/tl/objects/update'
18
21
  require_relative 'mtproto/tl/objects/update_short'
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.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Levenkov
@@ -65,6 +65,8 @@ files:
65
65
  - lib/mtproto/client/api/check_password.rb
66
66
  - lib/mtproto/client/api/export_authorization.rb
67
67
  - lib/mtproto/client/api/export_login_token.rb
68
+ - lib/mtproto/client/api/get_bot_callback_answer.rb
69
+ - lib/mtproto/client/api/get_channel_difference.rb
68
70
  - lib/mtproto/client/api/get_contacts.rb
69
71
  - lib/mtproto/client/api/get_dialogs.rb
70
72
  - lib/mtproto/client/api/get_history.rb
@@ -72,6 +74,7 @@ files:
72
74
  - lib/mtproto/client/api/get_updates_state.rb
73
75
  - lib/mtproto/client/api/get_users.rb
74
76
  - lib/mtproto/client/api/import_authorization.rb
77
+ - lib/mtproto/client/api/import_bot_authorization.rb
75
78
  - lib/mtproto/client/api/import_login_token.rb
76
79
  - lib/mtproto/client/api/send_code.rb
77
80
  - lib/mtproto/client/api/send_message.rb
@@ -87,18 +90,23 @@ files:
87
90
  - lib/mtproto/crypto/rsa_key.rb
88
91
  - lib/mtproto/crypto/rsa_pad.rb
89
92
  - lib/mtproto/crypto/srp.rb
93
+ - lib/mtproto/dc.rb
90
94
  - lib/mtproto/delegate_methods.rb
91
95
  - lib/mtproto/encrypted_message.rb
92
96
  - lib/mtproto/errors.rb
93
97
  - lib/mtproto/file_downloader.rb
98
+ - lib/mtproto/markdown.rb
94
99
  - lib/mtproto/message_id.rb
95
100
  - lib/mtproto/session.rb
96
101
  - lib/mtproto/tl/constructor_names.rb
97
102
  - lib/mtproto/tl/constructors.rb
103
+ - lib/mtproto/tl/message_entity.rb
98
104
  - lib/mtproto/tl/object.rb
99
105
  - lib/mtproto/tl/objects/account_password.rb
100
106
  - lib/mtproto/tl/objects/authorization.rb
107
+ - lib/mtproto/tl/objects/bot_callback_answer.rb
101
108
  - lib/mtproto/tl/objects/bot_command_scope.rb
109
+ - lib/mtproto/tl/objects/channel_difference.rb
102
110
  - lib/mtproto/tl/objects/channels_create_channel.rb
103
111
  - lib/mtproto/tl/objects/channels_delete_messages.rb
104
112
  - lib/mtproto/tl/objects/channels_delete_participant_history.rb
@@ -128,6 +136,7 @@ files:
128
136
  - lib/mtproto/tl/objects/get_access_settings.rb
129
137
  - lib/mtproto/tl/objects/get_bot_callback_answer.rb
130
138
  - lib/mtproto/tl/objects/get_bot_commands.rb
139
+ - lib/mtproto/tl/objects/get_bot_info.rb
131
140
  - lib/mtproto/tl/objects/get_channel_difference.rb
132
141
  - lib/mtproto/tl/objects/get_config.rb
133
142
  - lib/mtproto/tl/objects/get_contacts.rb
@@ -154,6 +163,8 @@ files:
154
163
  - lib/mtproto/tl/objects/login_token.rb
155
164
  - lib/mtproto/tl/objects/message.rb
156
165
  - lib/mtproto/tl/objects/messages.rb
166
+ - lib/mtproto/tl/objects/messages_add_chat_user.rb
167
+ - lib/mtproto/tl/objects/messages_create_chat.rb
157
168
  - lib/mtproto/tl/objects/messages_get_messages.rb
158
169
  - lib/mtproto/tl/objects/msg_container.rb
159
170
  - lib/mtproto/tl/objects/new_session_created.rb