mtproto 0.0.17 → 0.0.19

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: 91acdfee4741dfeba7510863fa536d1502c83caebf8bc358cec8153d555aaa80
4
- data.tar.gz: 28e855af4ad87db1558ea91ba740f671254e014ac76618f4692c0d3b9e916e68
3
+ metadata.gz: b96860172330495c1d12e06b8de8861ac33c97a6882a955fc77fe3e85e4268e4
4
+ data.tar.gz: 95c1faa866ea16ad23ba0cc06849adb6684f2267a53f7f018dc2ade8ad8decb4
5
5
  SHA512:
6
- metadata.gz: 42f5c61075a9e8111deb852a90ae1b61505f3e36de083b29b9f1e947fa2bb3708e54c4d2c7208a06de08d1611599e44ed89b1614a4165ffc9fac936f8c4b43a2
7
- data.tar.gz: cb28efdff6ff2af2c93e70ef3cfd48807af8edc734ef69c11c83dd1be06bd127d907cb227ed5266e9d0b1a78ed3acef6c56c9f1d5aae7b209bca8e8a80a3ffd9
6
+ metadata.gz: 6566d9f51ccf60e24a99ec3410309088813a26dd42fa353699390c2714427e688e43882130e950cfe24268f586ed920ac4b6e7473cb183e660f8be3d4a249191
7
+ data.tar.gz: 36016eb3d8176d4dc806fa8057835d0b9947ef5ad77acc9e32add81a39a6bb2a2a8a367b5a5329ece094299cfdf2188350658c1b69a42c23d0d34cf576ac6281
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MTProto
4
+ module TL
5
+ # channels.editAdmin — grant, change, or (with no rights) revoke a participant's
6
+ # admin rights in a channel or supergroup. Returns Updates.
7
+ class ChannelsEditAdmin
8
+ include Binary
9
+
10
+ CONSTRUCTOR = 0x9a98ad68
11
+ CHAT_ADMIN_RIGHTS = 0x5fb224d5
12
+ INPUT_USER = 0xf21158c6
13
+
14
+ # Flag bit per chatAdminRights right (the schema leaves bits 6 and 8 unused).
15
+ ADMIN_RIGHT_BITS = {
16
+ change_info: 0, post_messages: 1, edit_messages: 2, delete_messages: 3,
17
+ ban_users: 4, invite_users: 5, pin_messages: 7, add_admins: 9, anonymous: 10,
18
+ manage_call: 11, other: 12, manage_topics: 13, post_stories: 14,
19
+ edit_stories: 15, delete_stories: 16, manage_direct_messages: 17, manage_ranks: 18
20
+ }.freeze
21
+
22
+ # channel and user are { id:, access_hash: }. Pass any ADMIN_RIGHT_BITS key as
23
+ # true to grant that right (e.g. post_messages: true); none/all-false revokes
24
+ # the participant's admin status. rank is the optional custom admin title.
25
+ def initialize(channel:, user:, rank: '', **rights)
26
+ unknown = rights.keys - ADMIN_RIGHT_BITS.keys
27
+ raise ArgumentError, "unknown admin right(s): #{unknown.join(', ')}" unless unknown.empty?
28
+
29
+ @channel = channel
30
+ @user = user
31
+ @rank = rank
32
+ @rights = rights
33
+ end
34
+
35
+ def serialize
36
+ result = u32_b(CONSTRUCTOR)
37
+ result += u32_b(rank_flag)
38
+ result += serialize_input_channel
39
+ result += serialize_input_user
40
+ result += serialize_admin_rights
41
+ result += serialize_tl_string(@rank) unless @rank.to_s.empty?
42
+ result
43
+ end
44
+
45
+ private
46
+
47
+ # The method's own flags word: only bit 0, set when the optional rank is present.
48
+ def rank_flag
49
+ @rank.to_s.empty? ? 0 : (1 << 0)
50
+ end
51
+
52
+ def serialize_input_channel
53
+ u32_b(Constructors::INPUT_CHANNEL) + u64_b(@channel[:id]) + u64_b(@channel[:access_hash])
54
+ end
55
+
56
+ def serialize_input_user
57
+ u32_b(INPUT_USER) + u64_b(@user[:id]) + u64_b(@user[:access_hash] || 0)
58
+ end
59
+
60
+ def serialize_admin_rights
61
+ flags = ADMIN_RIGHT_BITS.sum { |right, bit| @rights[right] ? (1 << bit) : 0 }
62
+ u32_b(CHAT_ADMIN_RIGHTS) + u32_b(flags)
63
+ end
64
+
65
+ def serialize_tl_string(str)
66
+ bytes = str.to_s.b.bytes
67
+ length = bytes.length
68
+ if length <= 253
69
+ [length] + bytes + padding(length + 1)
70
+ else
71
+ [254] + u32_b(length)[0, 3] + bytes + padding(length + 4)
72
+ end
73
+ end
74
+
75
+ def padding(current_length)
76
+ [0] * ((4 - (current_length % 4)) % 4)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -6,7 +6,7 @@ module MTProto
6
6
  module TL
7
7
  class Dialogs
8
8
  Dialog = Struct.new(:peer_type, :peer_id, :top_message, :unread_count, :pts, keyword_init: true)
9
- Chat = Struct.new(:id, :title, :type, :access_hash, keyword_init: true)
9
+ Chat = Struct.new(:id, :title, :type, :access_hash, :username, keyword_init: true)
10
10
 
11
11
  SCHEMA_PATH = File.expand_path('../../../../data/tl-schema.json', __dir__)
12
12
 
@@ -310,7 +310,8 @@ module MTProto
310
310
  offset += 8
311
311
  end
312
312
  title, offset = read_tl_string(data, offset)
313
- offset = skip_tl_string(data, offset) if flags.anybits?(1 << 6) # username
313
+ username = nil
314
+ username, offset = read_tl_string(data, offset) if flags.anybits?(1 << 6) # username
314
315
  offset = schema.skip(data, offset) # photo (ChatPhoto)
315
316
  offset += 4 # date
316
317
  if flags.anybits?(1 << 9) # restriction_reason Vector<RestrictionReason>
@@ -334,7 +335,7 @@ module MTProto
334
335
  offset += 8 if flags2.anybits?(1 << 18) # linked_monoforum_id (long)
335
336
 
336
337
  type = flags.anybits?(1 << 8) ? :supergroup : :channel
337
- [Chat.new(id: id, title: title, type: type, access_hash: access_hash), offset]
338
+ [Chat.new(id: id, title: title, type: type, access_hash: access_hash, username: username), offset]
338
339
  end
339
340
 
340
341
  # chatForbidden#6592a1a7 id:long title:string
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MTProto
4
- VERSION = '0.0.17'
4
+ VERSION = '0.0.19'
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.17
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Levenkov
@@ -102,6 +102,7 @@ files:
102
102
  - lib/mtproto/tl/objects/channels_create_channel.rb
103
103
  - lib/mtproto/tl/objects/channels_delete_messages.rb
104
104
  - lib/mtproto/tl/objects/channels_delete_participant_history.rb
105
+ - lib/mtproto/tl/objects/channels_edit_admin.rb
105
106
  - lib/mtproto/tl/objects/channels_edit_banned.rb
106
107
  - lib/mtproto/tl/objects/channels_get_messages.rb
107
108
  - lib/mtproto/tl/objects/channels_get_participant.rb