chat_xdk 0.7.10-aarch64-linux

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.
@@ -0,0 +1,1860 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module ChatXdk
6
+ # A screen-capture setting signed by {Chat#prepare_screen_capture}.
7
+ #
8
+ # Blocking names are the events X clients sign. Detection names are the
9
+ # events this SDK's verifier reconstructs.
10
+ module ScreenCaptureChange
11
+ BLOCKING_ENABLED = "BlockingEnabled"
12
+ BLOCKING_DISABLED = "BlockingDisabled"
13
+ DETECTION_ENABLED = "DetectionEnabled"
14
+ DETECTION_DISABLED = "DetectionDisabled"
15
+ end
16
+
17
+ # Why a key change's signature did not verify.
18
+ module UnverifiedKeyChangeReason
19
+ MISSING_SIGNING_KEY = "MissingSigningKey"
20
+ REJECTED_SIGNING_KEY = "RejectedSigningKey"
21
+ INVALID_SIGNATURE = "InvalidSignature"
22
+ UNVERIFIABLE = "Unverifiable"
23
+ end
24
+
25
+ # Why this identity could not decrypt the conversation key a key change carries.
26
+ module UndecryptableKeyChangeReason
27
+ LOCKED = "Locked"
28
+ NOT_A_RECIPIENT = "NotARecipient"
29
+ OTHER_KEY_VERSION = "OtherKeyVersion"
30
+ DECRYPTION_FAILED = "DecryptionFailed"
31
+ end
32
+
33
+ # The user's identity and signing public keys (base64).
34
+ class PublicKeys
35
+ attr_reader :identity, :signing
36
+
37
+ def initialize(identity:, signing:)
38
+ @identity = identity
39
+ @signing = signing
40
+ end
41
+
42
+ def self.from_h(hash)
43
+ new(identity: hash["identity"].to_s, signing: hash["signing"].to_s)
44
+ end
45
+
46
+ def to_h
47
+ { "identity" => @identity, "signing" => @signing }
48
+ end
49
+
50
+ def to_json(*args)
51
+ to_h.to_json(*args)
52
+ end
53
+ end
54
+
55
+ # Registration fields expected by POST /2/users/{id}/public_keys.
56
+ class PublicKeyRegistration
57
+ attr_reader :identity_public_key_signature, :public_key, :public_key_fingerprint,
58
+ :registration_method, :signing_public_key, :signing_public_key_signature
59
+
60
+ def initialize(
61
+ identity_public_key_signature:,
62
+ public_key:,
63
+ registration_method:,
64
+ signing_public_key:,
65
+ public_key_fingerprint: nil,
66
+ signing_public_key_signature: nil
67
+ )
68
+ @identity_public_key_signature = identity_public_key_signature
69
+ @public_key = public_key
70
+ @public_key_fingerprint = public_key_fingerprint
71
+ @registration_method = registration_method
72
+ @signing_public_key = signing_public_key
73
+ @signing_public_key_signature = signing_public_key_signature
74
+ end
75
+
76
+ def self.from_h(hash)
77
+ new(
78
+ identity_public_key_signature: hash["identity_public_key_signature"].to_s,
79
+ public_key: hash["public_key"].to_s,
80
+ public_key_fingerprint: hash["public_key_fingerprint"],
81
+ registration_method: hash["registration_method"].to_s,
82
+ signing_public_key: hash["signing_public_key"].to_s,
83
+ signing_public_key_signature: hash["signing_public_key_signature"]
84
+ )
85
+ end
86
+
87
+ def to_h
88
+ h = {
89
+ "identity_public_key_signature" => @identity_public_key_signature,
90
+ "public_key" => @public_key,
91
+ "registration_method" => @registration_method,
92
+ "signing_public_key" => @signing_public_key
93
+ }
94
+ h["public_key_fingerprint"] = @public_key_fingerprint unless @public_key_fingerprint.nil?
95
+ h["signing_public_key_signature"] = @signing_public_key_signature unless @signing_public_key_signature.nil?
96
+ h
97
+ end
98
+
99
+ def to_json(*args)
100
+ to_h.to_json(*args)
101
+ end
102
+ end
103
+
104
+ # Returned by {Chat#generate_keypairs}.
105
+ class PublicKeyRegistrationPayload
106
+ attr_reader :public_key
107
+
108
+ def initialize(public_key:)
109
+ @public_key = public_key
110
+ end
111
+
112
+ def self.from_h(hash)
113
+ new(public_key: PublicKeyRegistration.from_h(hash["public_key"] || {}))
114
+ end
115
+
116
+ def to_h
117
+ { "public_key" => @public_key.to_h }
118
+ end
119
+
120
+ def to_json(*args)
121
+ to_h.to_json(*args)
122
+ end
123
+ end
124
+
125
+ # Signature metadata for a sent message.
126
+ class SignatureInfo
127
+ attr_reader :public_key_version, :signature_version
128
+
129
+ def initialize(public_key_version:, signature_version:)
130
+ @public_key_version = public_key_version
131
+ @signature_version = signature_version
132
+ end
133
+
134
+ def self.from_h(hash)
135
+ new(
136
+ public_key_version: hash["public_key_version"].to_s,
137
+ signature_version: hash["signature_version"].to_s
138
+ )
139
+ end
140
+
141
+ def to_h
142
+ {
143
+ "public_key_version" => @public_key_version,
144
+ "signature_version" => @signature_version
145
+ }
146
+ end
147
+
148
+ def to_json(*args)
149
+ to_h.to_json(*args)
150
+ end
151
+ end
152
+
153
+ # Encrypted message payload ready to POST to the X API.
154
+ # Returned by all encrypt_* methods.
155
+ class SendPayload
156
+ attr_reader :message_id, :event_b64, :encoded_message_create_event, :signature,
157
+ :encoded_message_event_signature, :signature_info, :conversation_key_version,
158
+ :should_notify, :xdk_version
159
+
160
+ def initialize(
161
+ message_id:,
162
+ event_b64:,
163
+ encoded_message_create_event:,
164
+ signature:,
165
+ encoded_message_event_signature:,
166
+ signature_info:,
167
+ conversation_key_version:,
168
+ should_notify:,
169
+ xdk_version:
170
+ )
171
+ @message_id = message_id
172
+ @event_b64 = event_b64
173
+ @encoded_message_create_event = encoded_message_create_event
174
+ @signature = signature
175
+ @encoded_message_event_signature = encoded_message_event_signature
176
+ @signature_info = signature_info
177
+ @conversation_key_version = conversation_key_version
178
+ @should_notify = should_notify
179
+ @xdk_version = xdk_version
180
+ end
181
+
182
+ def self.from_h(hash)
183
+ new(
184
+ message_id: hash["message_id"].to_s,
185
+ event_b64: hash["event_b64"].to_s,
186
+ encoded_message_create_event: hash["encoded_message_create_event"].to_s,
187
+ signature: hash["signature"].to_s,
188
+ encoded_message_event_signature: hash["encoded_message_event_signature"].to_s,
189
+ signature_info: SignatureInfo.from_h(hash["signature_info"] || {}),
190
+ conversation_key_version: hash["conversation_key_version"].to_s,
191
+ should_notify: hash["should_notify"] == true,
192
+ xdk_version: hash["xdk_version"].to_s
193
+ )
194
+ end
195
+
196
+ def to_h
197
+ {
198
+ "message_id" => @message_id,
199
+ "event_b64" => @event_b64,
200
+ "encoded_message_create_event" => @encoded_message_create_event,
201
+ "signature" => @signature,
202
+ "encoded_message_event_signature" => @encoded_message_event_signature,
203
+ "signature_info" => @signature_info.to_h,
204
+ "conversation_key_version" => @conversation_key_version,
205
+ "should_notify" => @should_notify,
206
+ "xdk_version" => @xdk_version
207
+ }
208
+ end
209
+
210
+ def to_json(*args)
211
+ to_h.to_json(*args)
212
+ end
213
+ end
214
+
215
+ # The signature of an {ActionSignature}.
216
+ class MessageEventSignature
217
+ attr_reader :signature, :signature_version, :public_key_version, :signing_public_key
218
+
219
+ def initialize(signature:, signature_version:, public_key_version:, signing_public_key:)
220
+ @signature = signature
221
+ @signature_version = signature_version
222
+ @public_key_version = public_key_version
223
+ @signing_public_key = signing_public_key
224
+ end
225
+
226
+ def self.from_h(hash)
227
+ new(
228
+ signature: hash["signature"].to_s,
229
+ signature_version: hash["signature_version"].to_s,
230
+ public_key_version: hash["public_key_version"].to_s,
231
+ signing_public_key: hash["signing_public_key"].to_s
232
+ )
233
+ end
234
+
235
+ def to_h
236
+ {
237
+ "signature" => @signature,
238
+ "signature_version" => @signature_version,
239
+ "public_key_version" => @public_key_version,
240
+ "signing_public_key" => @signing_public_key
241
+ }
242
+ end
243
+
244
+ def to_json(*args)
245
+ to_h.to_json(*args)
246
+ end
247
+ end
248
+
249
+ # Signed action authenticating a conversation key change, group change,
250
+ # message delete, or read receipt.
251
+ class ActionSignature
252
+ attr_reader :message_id, :encoded_message_event_detail, :message_event_signature
253
+
254
+ def initialize(message_id:, encoded_message_event_detail:, message_event_signature:)
255
+ @message_id = message_id
256
+ @encoded_message_event_detail = encoded_message_event_detail
257
+ @message_event_signature = message_event_signature
258
+ end
259
+
260
+ def self.from_h(hash)
261
+ new(
262
+ message_id: hash["message_id"].to_s,
263
+ encoded_message_event_detail: hash["encoded_message_event_detail"].to_s,
264
+ message_event_signature: MessageEventSignature.from_h(hash["message_event_signature"] || {})
265
+ )
266
+ end
267
+
268
+ def to_h
269
+ {
270
+ "message_id" => @message_id,
271
+ "encoded_message_event_detail" => @encoded_message_event_detail,
272
+ "message_event_signature" => @message_event_signature.to_h
273
+ }
274
+ end
275
+
276
+ def to_json(*args)
277
+ to_h.to_json(*args)
278
+ end
279
+ end
280
+
281
+ # Signed actions for a request that does not rotate a conversation key.
282
+ class PreparedAction
283
+ attr_reader :action_signatures
284
+
285
+ def initialize(action_signatures:)
286
+ @action_signatures = action_signatures
287
+ end
288
+
289
+ def self.from_h(hash)
290
+ sigs = (hash["action_signatures"] || []).map { |s| ActionSignature.from_h(s) }
291
+ new(action_signatures: sigs)
292
+ end
293
+
294
+ def to_h
295
+ { "action_signatures" => @action_signatures.map(&:to_h) }
296
+ end
297
+
298
+ def to_json(*args)
299
+ to_h.to_json(*args)
300
+ end
301
+ end
302
+
303
+ # A signed group title or description change.
304
+ class PreparedGroupMetadataChange
305
+ attr_reader :encrypted_value, :conversation_key_version, :action_signatures
306
+
307
+ def initialize(encrypted_value:, conversation_key_version:, action_signatures:)
308
+ @encrypted_value = encrypted_value
309
+ @conversation_key_version = conversation_key_version
310
+ @action_signatures = action_signatures
311
+ end
312
+
313
+ def self.from_h(hash)
314
+ sigs = (hash["action_signatures"] || []).map { |s| ActionSignature.from_h(s) }
315
+ new(
316
+ encrypted_value: hash["encrypted_value"].to_s,
317
+ conversation_key_version: hash["conversation_key_version"].to_s,
318
+ action_signatures: sigs
319
+ )
320
+ end
321
+
322
+ def to_h
323
+ {
324
+ "encrypted_value" => @encrypted_value,
325
+ "conversation_key_version" => @conversation_key_version,
326
+ "action_signatures" => @action_signatures.map(&:to_h)
327
+ }
328
+ end
329
+
330
+ def to_json(*args)
331
+ to_h.to_json(*args)
332
+ end
333
+ end
334
+
335
+ # One participant's copy of a conversation key, encrypted to their identity key.
336
+ class ConversationParticipantKey
337
+ attr_reader :user_id, :encrypted_conversation_key, :public_key_version
338
+
339
+ def initialize(user_id:, encrypted_conversation_key:, public_key_version:)
340
+ @user_id = user_id
341
+ @encrypted_conversation_key = encrypted_conversation_key
342
+ @public_key_version = public_key_version
343
+ end
344
+
345
+ def self.from_h(hash)
346
+ new(
347
+ user_id: hash["user_id"].to_s,
348
+ encrypted_conversation_key: hash["encrypted_conversation_key"].to_s,
349
+ public_key_version: hash["public_key_version"].to_s
350
+ )
351
+ end
352
+
353
+ def to_h
354
+ {
355
+ "user_id" => @user_id,
356
+ "encrypted_conversation_key" => @encrypted_conversation_key,
357
+ "public_key_version" => @public_key_version
358
+ }
359
+ end
360
+
361
+ def to_json(*args)
362
+ to_h.to_json(*args)
363
+ end
364
+ end
365
+
366
+ # Returned by prepare_conversation_key_change, prepare_group_create,
367
+ # prepare_group_members_change, and prepare_group_members_remove.
368
+ #
369
+ # {#conversation_key} holds raw secret key bytes: it is omitted from {#to_h}
370
+ # and {#to_json}, and redacted in {#inspect}.
371
+ class PreparedConversationChange
372
+ attr_reader :conversation_id, :conversation_key, :conversation_key_version,
373
+ :conversation_participant_keys, :action_signatures,
374
+ :encrypted_title, :encrypted_description
375
+
376
+ def initialize(
377
+ conversation_id:,
378
+ conversation_key:,
379
+ conversation_key_version:,
380
+ conversation_participant_keys:,
381
+ action_signatures:,
382
+ encrypted_title: nil,
383
+ encrypted_description: nil
384
+ )
385
+ @conversation_id = conversation_id
386
+ @conversation_key = conversation_key
387
+ @conversation_key_version = conversation_key_version
388
+ @conversation_participant_keys = conversation_participant_keys
389
+ @action_signatures = action_signatures
390
+ @encrypted_title = encrypted_title
391
+ @encrypted_description = encrypted_description
392
+ end
393
+
394
+ def self.from_h(hash)
395
+ raw_key = hash["conversation_key"] ? Native.b64_decode(hash["conversation_key"]) : nil
396
+ pks = (hash["conversation_participant_keys"] || []).map { |k| ConversationParticipantKey.from_h(k) }
397
+ sigs = (hash["action_signatures"] || []).map { |s| ActionSignature.from_h(s) }
398
+ new(
399
+ conversation_id: hash["conversation_id"].to_s,
400
+ conversation_key: raw_key,
401
+ conversation_key_version: hash["conversation_key_version"].to_s,
402
+ conversation_participant_keys: pks,
403
+ action_signatures: sigs,
404
+ encrypted_title: hash["encrypted_title"],
405
+ encrypted_description: hash["encrypted_description"]
406
+ )
407
+ end
408
+
409
+ def to_h
410
+ h = {
411
+ "conversation_id" => @conversation_id,
412
+ "conversation_key_version" => @conversation_key_version,
413
+ "conversation_participant_keys" => @conversation_participant_keys.map(&:to_h),
414
+ "action_signatures" => @action_signatures.map(&:to_h)
415
+ }
416
+ h["encrypted_title"] = @encrypted_title unless @encrypted_title.nil?
417
+ h["encrypted_description"] = @encrypted_description unless @encrypted_description.nil?
418
+ h
419
+ end
420
+
421
+ def to_json(*args)
422
+ to_h.to_json(*args)
423
+ end
424
+
425
+ def inspect
426
+ "#<#{self.class.name} conversation_id=#{@conversation_id.inspect} " \
427
+ "conversation_key=[REDACTED] " \
428
+ "conversation_key_version=#{@conversation_key_version.inspect} " \
429
+ "participants=#{@conversation_participant_keys.length} " \
430
+ "action_signatures=#{@action_signatures.length}>"
431
+ end
432
+ end
433
+
434
+ # A participant's signing key entry for verification.
435
+ class SigningKeyEntry
436
+ attr_accessor :user_id, :public_key_version, :public_key,
437
+ :identity_public_key, :identity_public_key_signature
438
+
439
+ def initialize(
440
+ user_id:,
441
+ public_key_version:,
442
+ public_key:,
443
+ identity_public_key:,
444
+ identity_public_key_signature:
445
+ )
446
+ @user_id = user_id
447
+ @public_key_version = public_key_version
448
+ @public_key = public_key
449
+ @identity_public_key = identity_public_key
450
+ @identity_public_key_signature = identity_public_key_signature
451
+ end
452
+
453
+ def to_h
454
+ {
455
+ "user_id" => @user_id,
456
+ "public_key_version" => @public_key_version,
457
+ "public_key" => @public_key,
458
+ "identity_public_key" => @identity_public_key,
459
+ "identity_public_key_signature" => @identity_public_key_signature
460
+ }
461
+ end
462
+ end
463
+
464
+ # A participant's identity key for the prepare methods.
465
+ class PublicKeyInput
466
+ attr_accessor :user_id, :identity_public_key, :public_key_version
467
+
468
+ def initialize(user_id:, identity_public_key:, public_key_version:)
469
+ @user_id = user_id
470
+ @identity_public_key = identity_public_key
471
+ @public_key_version = public_key_version
472
+ end
473
+
474
+ def to_h
475
+ {
476
+ "user_id" => @user_id,
477
+ "identity_public_key" => @identity_public_key,
478
+ "public_key_version" => @public_key_version
479
+ }
480
+ end
481
+ end
482
+
483
+ # One of a user's public keys as returned in the data array of
484
+ # GET /2/users/{id}/public_keys.
485
+ class PublicKeyRecord
486
+ attr_accessor :public_key_version, :public_key, :signing_public_key,
487
+ :identity_public_key_signature
488
+
489
+ def initialize(
490
+ public_key_version: "",
491
+ public_key: "",
492
+ signing_public_key: "",
493
+ identity_public_key_signature: ""
494
+ )
495
+ @public_key_version = public_key_version.nil? ? "" : public_key_version.to_s
496
+ @public_key = public_key.to_s
497
+ @signing_public_key = signing_public_key.to_s
498
+ @identity_public_key_signature = identity_public_key_signature.to_s
499
+ end
500
+
501
+ def self.from_h(hash)
502
+ return hash if hash.is_a?(self)
503
+ raise ArgumentError, "expected Hash or PublicKeyRecord" unless hash.is_a?(Hash)
504
+
505
+ lookup = lambda do |snake, camel|
506
+ if hash.key?(snake)
507
+ hash[snake]
508
+ elsif hash.key?(snake.to_sym)
509
+ hash[snake.to_sym]
510
+ elsif hash.key?(camel)
511
+ hash[camel]
512
+ elsif hash.key?(camel.to_sym)
513
+ hash[camel.to_sym]
514
+ end
515
+ end
516
+
517
+ ver = lookup.call("public_key_version", "publicKeyVersion")
518
+ new(
519
+ public_key_version: ver.nil? ? "" : ver.to_s,
520
+ public_key: lookup.call("public_key", "publicKey").to_s,
521
+ signing_public_key: lookup.call("signing_public_key", "signingPublicKey").to_s,
522
+ identity_public_key_signature: lookup.call("identity_public_key_signature", "identityPublicKeySignature").to_s
523
+ )
524
+ end
525
+
526
+ def to_h
527
+ {
528
+ "public_key_version" => @public_key_version,
529
+ "public_key" => @public_key,
530
+ "signing_public_key" => @signing_public_key,
531
+ "identity_public_key_signature" => @identity_public_key_signature
532
+ }
533
+ end
534
+ end
535
+
536
+ # Conversation keys extracted from KeyChange events.
537
+ class ConversationKeyResult
538
+ attr_reader :keys, :keys_by_conversation, :latest_version, :latest_versions
539
+
540
+ def initialize(keys:, keys_by_conversation:, latest_version:, latest_versions:)
541
+ @keys = keys
542
+ @keys_by_conversation = keys_by_conversation
543
+ @latest_version = latest_version
544
+ @latest_versions = latest_versions
545
+ end
546
+
547
+ def self.from_h(hash)
548
+ hash ||= {}
549
+ keys = parse_key_map(hash["keys"])
550
+ keys_by_conv = {}
551
+ (hash["keys_by_conversation"] || {}).each do |conv_id, ver_map|
552
+ keys_by_conv[conv_id] = parse_key_map(ver_map)
553
+ end
554
+ latest_versions = {}
555
+ (hash["latest_versions"] || {}).each do |conv_id, ver|
556
+ latest_versions[conv_id] = ver.to_s
557
+ end
558
+ new(
559
+ keys: keys,
560
+ keys_by_conversation: keys_by_conv,
561
+ latest_version: hash["latest_version"],
562
+ latest_versions: latest_versions
563
+ )
564
+ end
565
+
566
+ def self.parse_key_map(raw)
567
+ out = {}
568
+ return out unless raw.is_a?(Hash)
569
+
570
+ raw.each do |ver, b64|
571
+ out[ver.to_s] = Native.b64_decode(b64)
572
+ end
573
+ out
574
+ end
575
+ private_class_method :parse_key_map
576
+
577
+ def inspect
578
+ "#<#{self.class.name} keys=[REDACTED:#{@keys.length}] " \
579
+ "conversations=#{@keys_by_conversation.length} " \
580
+ "latest_version=#{@latest_version.inspect} " \
581
+ "latest_versions=#{@latest_versions.inspect}>"
582
+ end
583
+ end
584
+
585
+ # Width and height returned by {ChatXdk.detect_image_dimensions}.
586
+ class ImageDimensions
587
+ attr_reader :width, :height
588
+
589
+ def initialize(width:, height:)
590
+ @width = width
591
+ @height = height
592
+ end
593
+
594
+ def self.from_h(hash)
595
+ new(width: hash["width"].to_i, height: hash["height"].to_i)
596
+ end
597
+
598
+ def ==(other)
599
+ other.is_a?(ImageDimensions) && @width == other.width && @height == other.height
600
+ end
601
+ end
602
+
603
+ # One event decrypted by {Chat#decrypt_events}.
604
+ class DecryptedEvent
605
+ attr_reader :event, :original_b64
606
+
607
+ def initialize(event:, original_b64: nil)
608
+ @event = event
609
+ @original_b64 = original_b64
610
+ end
611
+
612
+ def self.from_h(hash)
613
+ new(event: hash["event"], original_b64: hash["original_b64"])
614
+ end
615
+ end
616
+
617
+ # A key change whose key was decrypted but whose signature did not verify.
618
+ class UnverifiedKeyChange
619
+ attr_reader :reason, :key_dropped, :conversation_id, :conversation_key_version,
620
+ :sender_id, :public_key_version
621
+
622
+ def initialize(
623
+ reason:,
624
+ key_dropped:,
625
+ conversation_id:,
626
+ conversation_key_version:,
627
+ sender_id:,
628
+ public_key_version:
629
+ )
630
+ @reason = reason
631
+ @key_dropped = key_dropped
632
+ @conversation_id = conversation_id
633
+ @conversation_key_version = conversation_key_version
634
+ @sender_id = sender_id
635
+ @public_key_version = public_key_version
636
+ end
637
+
638
+ def self.from_h(hash)
639
+ new(
640
+ reason: hash["reason"].to_s,
641
+ key_dropped: hash["key_dropped"] == true,
642
+ conversation_id: hash["conversation_id"],
643
+ conversation_key_version: hash["conversation_key_version"].to_s,
644
+ sender_id: hash["sender_id"],
645
+ public_key_version: hash["public_key_version"]
646
+ )
647
+ end
648
+ end
649
+
650
+ # A key change whose conversation key this identity could not decrypt.
651
+ class UndecryptableKeyChange
652
+ attr_reader :reason, :conversation_id, :conversation_key_version, :sender_id
653
+
654
+ def initialize(reason:, conversation_id:, conversation_key_version:, sender_id:)
655
+ @reason = reason
656
+ @conversation_id = conversation_id
657
+ @conversation_key_version = conversation_key_version
658
+ @sender_id = sender_id
659
+ end
660
+
661
+ def self.from_h(hash)
662
+ new(
663
+ reason: hash["reason"].to_s,
664
+ conversation_id: hash["conversation_id"],
665
+ conversation_key_version: hash["conversation_key_version"].to_s,
666
+ sender_id: hash["sender_id"]
667
+ )
668
+ end
669
+ end
670
+
671
+ # A signing key rejected because its identity binding did not verify.
672
+ class RejectedSigningKey
673
+ attr_reader :user_id, :public_key_version
674
+
675
+ def initialize(user_id:, public_key_version:)
676
+ @user_id = user_id
677
+ @public_key_version = public_key_version
678
+ end
679
+
680
+ def self.from_h(hash)
681
+ new(user_id: hash["user_id"].to_s, public_key_version: hash["public_key_version"].to_s)
682
+ end
683
+ end
684
+
685
+ # A signing key missing from the keys a decrypt_events call verified with.
686
+ class MissingSigningKey
687
+ attr_reader :user_id, :public_key_version
688
+
689
+ def initialize(user_id:, public_key_version:)
690
+ @user_id = user_id
691
+ @public_key_version = public_key_version
692
+ end
693
+
694
+ def self.from_h(hash)
695
+ new(user_id: hash["user_id"].to_s, public_key_version: hash["public_key_version"].to_s)
696
+ end
697
+
698
+ def to_h
699
+ { "user_id" => @user_id, "public_key_version" => @public_key_version }
700
+ end
701
+ end
702
+
703
+ # Result of {Chat#decrypt_events}.
704
+ class DecryptEventsResult
705
+ attr_reader :events, :conversation_keys, :errors, :unverified_key_changes,
706
+ :undecryptable_key_changes, :rejected_signing_keys, :missing_signing_keys
707
+
708
+ def initialize(
709
+ events:,
710
+ conversation_keys:,
711
+ errors:,
712
+ unverified_key_changes:,
713
+ undecryptable_key_changes:,
714
+ rejected_signing_keys:,
715
+ missing_signing_keys:
716
+ )
717
+ @events = events
718
+ @conversation_keys = conversation_keys
719
+ @errors = errors
720
+ @unverified_key_changes = unverified_key_changes
721
+ @undecryptable_key_changes = undecryptable_key_changes
722
+ @rejected_signing_keys = rejected_signing_keys
723
+ @missing_signing_keys = missing_signing_keys
724
+ end
725
+
726
+ def self.from_h(hash)
727
+ events = (hash["events"] || []).map { |el| DecryptedEvent.from_h(el) }
728
+ conv_keys = ConversationKeyResult.from_h(hash["conversation_keys"])
729
+ errors = {}
730
+ (hash["errors"] || {}).each { |k, v| errors[k.to_s] = v.to_s }
731
+ unverified = parse_indexed(hash["unverified_key_changes"], UnverifiedKeyChange)
732
+ undecryptable = parse_indexed(hash["undecryptable_key_changes"], UndecryptableKeyChange)
733
+ rejected = parse_indexed(hash["rejected_signing_keys"], RejectedSigningKey)
734
+ missing = parse_indexed(hash["missing_signing_keys"], MissingSigningKey)
735
+
736
+ new(
737
+ events: events,
738
+ conversation_keys: conv_keys,
739
+ errors: errors,
740
+ unverified_key_changes: unverified,
741
+ undecryptable_key_changes: undecryptable,
742
+ rejected_signing_keys: rejected,
743
+ missing_signing_keys: missing
744
+ )
745
+ end
746
+
747
+ def self.parse_indexed(raw, klass)
748
+ out = {}
749
+ return out unless raw.is_a?(Hash)
750
+
751
+ raw.each { |k, v| out[k.to_s] = klass.from_h(v) }
752
+ out
753
+ end
754
+ private_class_method :parse_indexed
755
+ end
756
+
757
+ # A group title or description as carried by a received group change event.
758
+ class GroupText
759
+ attr_reader :kind, :text, :raw
760
+
761
+ def initialize(kind:, text: nil, raw: nil)
762
+ @kind = kind
763
+ @text = text
764
+ @raw = raw
765
+ end
766
+
767
+ def self.from_h(hash)
768
+ return nil if hash.nil?
769
+ return hash if hash.is_a?(self)
770
+
771
+ new(
772
+ kind: hash["kind"] || hash[:kind],
773
+ text: hash.key?("text") ? hash["text"] : hash[:text],
774
+ raw: hash.key?("raw") ? hash["raw"] : hash[:raw]
775
+ )
776
+ end
777
+
778
+ def to_h
779
+ h = { "kind" => @kind }
780
+ h["text"] = @text unless @text.nil?
781
+ h["raw"] = @raw unless @raw.nil?
782
+ h
783
+ end
784
+ end
785
+
786
+ # Rich-text entity descriptor with UTF-8 byte offsets.
787
+ class EntityDescriptor
788
+ attr_accessor :start, :end, :entity_type
789
+
790
+ def initialize(start, end_offset, entity_type)
791
+ @start = start
792
+ @end = end_offset
793
+ @entity_type = entity_type
794
+ end
795
+
796
+ def to_tuple
797
+ [@start, @end, @entity_type]
798
+ end
799
+ end
800
+
801
+ # An encrypted preview image (banner or favicon) referenced by a URL card.
802
+ class UrlAttachmentImageDescriptor
803
+ attr_accessor :media_hash_key, :filesize_bytes, :filename, :width, :height
804
+
805
+ def initialize(media_hash_key:, filesize_bytes:, filename:, width: nil, height: nil)
806
+ @media_hash_key = media_hash_key
807
+ @filesize_bytes = filesize_bytes
808
+ @filename = filename
809
+ @width = width
810
+ @height = height
811
+ end
812
+
813
+ def to_h
814
+ h = {
815
+ "media_hash_key" => @media_hash_key,
816
+ "filesize_bytes" => @filesize_bytes,
817
+ "filename" => @filename
818
+ }
819
+ h["width"] = @width unless @width.nil?
820
+ h["height"] = @height unless @height.nil?
821
+ h
822
+ end
823
+ end
824
+
825
+ # Attachment descriptor created by {.media}, {.url_card}, or {.post}.
826
+ class AttachmentDescriptor
827
+ attr_reader :attachment_type, :media_hash_key, :width, :height,
828
+ :filesize_bytes, :filename, :media_type, :duration_millis,
829
+ :plaintext_sha256, :url, :display_title, :banner_image,
830
+ :favicon_image, :rest_id, :post_url
831
+
832
+ def initialize(
833
+ attachment_type:,
834
+ media_hash_key: nil,
835
+ width: nil,
836
+ height: nil,
837
+ filesize_bytes: nil,
838
+ filename: nil,
839
+ media_type: nil,
840
+ duration_millis: nil,
841
+ plaintext_sha256: nil,
842
+ url: nil,
843
+ display_title: nil,
844
+ banner_image: nil,
845
+ favicon_image: nil,
846
+ rest_id: nil,
847
+ post_url: nil
848
+ )
849
+ @attachment_type = attachment_type
850
+ @media_hash_key = media_hash_key
851
+ @width = width
852
+ @height = height
853
+ @filesize_bytes = filesize_bytes
854
+ @filename = filename
855
+ @media_type = media_type
856
+ @duration_millis = duration_millis
857
+ @plaintext_sha256 = plaintext_sha256
858
+ @url = url
859
+ @display_title = display_title
860
+ @banner_image = banner_image
861
+ @favicon_image = favicon_image
862
+ @rest_id = rest_id
863
+ @post_url = post_url
864
+ end
865
+
866
+ def self.media(
867
+ media_hash_key:,
868
+ width:,
869
+ height:,
870
+ filesize_bytes:,
871
+ filename:,
872
+ media_type: nil,
873
+ duration_millis: nil,
874
+ plaintext_sha256: nil
875
+ )
876
+ new(
877
+ attachment_type: "media",
878
+ media_hash_key: media_hash_key,
879
+ width: width,
880
+ height: height,
881
+ filesize_bytes: filesize_bytes,
882
+ filename: filename,
883
+ media_type: media_type,
884
+ duration_millis: duration_millis,
885
+ plaintext_sha256: plaintext_sha256
886
+ )
887
+ end
888
+
889
+ def self.url_card(url:, display_title: nil, banner_image: nil, favicon_image: nil)
890
+ new(
891
+ attachment_type: "url",
892
+ url: url,
893
+ display_title: display_title,
894
+ banner_image: banner_image,
895
+ favicon_image: favicon_image
896
+ )
897
+ end
898
+
899
+ def self.post(rest_id: nil, post_url: nil)
900
+ new(
901
+ attachment_type: "post",
902
+ rest_id: rest_id,
903
+ post_url: post_url
904
+ )
905
+ end
906
+
907
+ def to_h
908
+ h = { "attachment_type" => @attachment_type }
909
+ h["media_hash_key"] = @media_hash_key unless @media_hash_key.nil?
910
+ h["width"] = @width unless @width.nil?
911
+ h["height"] = @height unless @height.nil?
912
+ h["filesize_bytes"] = @filesize_bytes unless @filesize_bytes.nil?
913
+ h["filename"] = @filename unless @filename.nil?
914
+ h["media_type"] = @media_type unless @media_type.nil?
915
+ h["duration_millis"] = @duration_millis unless @duration_millis.nil?
916
+ h["plaintext_sha256"] = @plaintext_sha256 unless @plaintext_sha256.nil?
917
+ h["url"] = @url unless @url.nil?
918
+ h["display_title"] = @display_title unless @display_title.nil?
919
+ h["banner_image"] = @banner_image.to_h unless @banner_image.nil?
920
+ h["favicon_image"] = @favicon_image.to_h unless @favicon_image.nil?
921
+ h["rest_id"] = @rest_id unless @rest_id.nil?
922
+ h["post_url"] = @post_url unless @post_url.nil?
923
+ h
924
+ end
925
+ end
926
+
927
+ # A single selectable quick-reply option.
928
+ class QuickReplyOption
929
+ attr_accessor :id, :label, :metadata, :description
930
+
931
+ def initialize(id: nil, label: nil, metadata: nil, description: nil)
932
+ @id = id
933
+ @label = label
934
+ @metadata = metadata
935
+ @description = description
936
+ end
937
+
938
+ def self.from_h(hash)
939
+ return hash if hash.is_a?(self)
940
+ raise ArgumentError, "expected Hash or QuickReplyOption" unless hash.is_a?(Hash)
941
+
942
+ new(
943
+ id: hash.key?("id") ? hash["id"] : hash[:id],
944
+ label: hash.key?("label") ? hash["label"] : hash[:label],
945
+ metadata: hash.key?("metadata") ? hash["metadata"] : hash[:metadata],
946
+ description: hash.key?("description") ? hash["description"] : hash[:description]
947
+ )
948
+ end
949
+
950
+ def to_h
951
+ h = {}
952
+ h["id"] = @id unless @id.nil?
953
+ h["label"] = @label unless @label.nil?
954
+ h["metadata"] = @metadata unless @metadata.nil?
955
+ h["description"] = @description unless @description.nil?
956
+ h
957
+ end
958
+ end
959
+
960
+ # The options offered by a quick-reply request.
961
+ class QuickReplyOptionsRequest
962
+ attr_accessor :id, :options
963
+
964
+ def initialize(id: nil, options: nil)
965
+ @id = id
966
+ @options = options
967
+ end
968
+
969
+ def self.from_h(hash)
970
+ return hash if hash.is_a?(self)
971
+ raise ArgumentError, "expected Hash or QuickReplyOptionsRequest" unless hash.is_a?(Hash)
972
+
973
+ raw_opts = hash.key?("options") ? hash["options"] : hash[:options]
974
+ opts = raw_opts.nil? ? nil : raw_opts.map { |o| QuickReplyOption.from_h(o) }
975
+ new(
976
+ id: hash.key?("id") ? hash["id"] : hash[:id],
977
+ options: opts
978
+ )
979
+ end
980
+
981
+ def to_h
982
+ h = {}
983
+ h["id"] = @id unless @id.nil?
984
+ h["options"] = @options.map(&:to_h) unless @options.nil?
985
+ h
986
+ end
987
+ end
988
+
989
+ # The option selected in a quick-reply response.
990
+ class QuickReplyOptionsResponse
991
+ attr_accessor :request_id, :metadata, :selected_option_id
992
+
993
+ def initialize(request_id: nil, metadata: nil, selected_option_id: nil)
994
+ @request_id = request_id
995
+ @metadata = metadata
996
+ @selected_option_id = selected_option_id
997
+ end
998
+
999
+ def self.from_h(hash)
1000
+ return hash if hash.is_a?(self)
1001
+ raise ArgumentError, "expected Hash or QuickReplyOptionsResponse" unless hash.is_a?(Hash)
1002
+
1003
+ new(
1004
+ request_id: hash.key?("request_id") ? hash["request_id"] : hash[:request_id],
1005
+ metadata: hash.key?("metadata") ? hash["metadata"] : hash[:metadata],
1006
+ selected_option_id: hash.key?("selected_option_id") ? hash["selected_option_id"] : hash[:selected_option_id]
1007
+ )
1008
+ end
1009
+
1010
+ def to_h
1011
+ h = {}
1012
+ h["request_id"] = @request_id unless @request_id.nil?
1013
+ h["metadata"] = @metadata unless @metadata.nil?
1014
+ h["selected_option_id"] = @selected_option_id unless @selected_option_id.nil?
1015
+ h
1016
+ end
1017
+ end
1018
+
1019
+ # A quick-reply request offering selectable options.
1020
+ class QuickReplyRequest
1021
+ attr_accessor :options
1022
+
1023
+ def initialize(options:)
1024
+ @options = options
1025
+ end
1026
+
1027
+ def self.from_h(hash)
1028
+ return hash if hash.is_a?(self)
1029
+ raise ArgumentError, "expected Hash or QuickReplyRequest" unless hash.is_a?(Hash)
1030
+
1031
+ opts = hash.key?("options") ? hash["options"] : hash[:options]
1032
+ new(options: opts.nil? ? nil : QuickReplyOptionsRequest.from_h(opts))
1033
+ end
1034
+
1035
+ def to_h
1036
+ h = {}
1037
+ h["options"] = @options.to_h unless @options.nil?
1038
+ h
1039
+ end
1040
+ end
1041
+
1042
+ # A quick-reply response selecting a previously offered option.
1043
+ class QuickReplyResponse
1044
+ attr_accessor :options
1045
+
1046
+ def initialize(options:)
1047
+ @options = options
1048
+ end
1049
+
1050
+ def self.from_h(hash)
1051
+ return hash if hash.is_a?(self)
1052
+ raise ArgumentError, "expected Hash or QuickReplyResponse" unless hash.is_a?(Hash)
1053
+
1054
+ opts = hash.key?("options") ? hash["options"] : hash[:options]
1055
+ new(options: opts.nil? ? nil : QuickReplyOptionsResponse.from_h(opts))
1056
+ end
1057
+
1058
+ def to_h
1059
+ h = {}
1060
+ h["options"] = @options.to_h unless @options.nil?
1061
+ h
1062
+ end
1063
+ end
1064
+
1065
+ # A quick reply carried by a text message. Set exactly one of {#request} or
1066
+ # {#response}. Deserializes from a decrypted event's quick_reply Hash via
1067
+ # {.from_h} so a received value can be sent back unchanged.
1068
+ class QuickReply
1069
+ attr_accessor :request, :response
1070
+
1071
+ def initialize(request: nil, response: nil)
1072
+ @request = request
1073
+ @response = response
1074
+ end
1075
+
1076
+ def self.request(options)
1077
+ new(request: QuickReplyRequest.new(options: options))
1078
+ end
1079
+
1080
+ def self.response(options)
1081
+ new(response: QuickReplyResponse.new(options: options))
1082
+ end
1083
+
1084
+ def self.from_h(hash)
1085
+ return nil if hash.nil?
1086
+ return hash if hash.is_a?(self)
1087
+ raise ArgumentError, "expected Hash or QuickReply" unless hash.is_a?(Hash)
1088
+
1089
+ req = hash.key?("request") ? hash["request"] : hash[:request]
1090
+ res = hash.key?("response") ? hash["response"] : hash[:response]
1091
+ new(
1092
+ request: req.nil? ? nil : QuickReplyRequest.from_h(req),
1093
+ response: res.nil? ? nil : QuickReplyResponse.from_h(res)
1094
+ )
1095
+ end
1096
+
1097
+ def to_h
1098
+ h = {}
1099
+ h["request"] = @request.to_h unless @request.nil?
1100
+ h["response"] = @response.to_h unless @response.nil?
1101
+ h
1102
+ end
1103
+ end
1104
+
1105
+ # --- Params classes ---
1106
+
1107
+ # Parameters for {Chat#set_identity}.
1108
+ class SetIdentityParams
1109
+ attr_accessor :user_id, :signing_key_version
1110
+
1111
+ def initialize(user_id:, signing_key_version:)
1112
+ @user_id = user_id
1113
+ @signing_key_version = signing_key_version
1114
+ end
1115
+ end
1116
+
1117
+ # Parameters for {Chat#import_keys}.
1118
+ class ImportKeysParams
1119
+ attr_accessor :keys, :signing_key_version
1120
+
1121
+ def initialize(keys:, signing_key_version: nil)
1122
+ @keys = keys
1123
+ @signing_key_version = signing_key_version
1124
+ end
1125
+
1126
+ def inspect
1127
+ "#<#{self.class.name} keys=[REDACTED] signing_key_version=#{@signing_key_version.inspect}>"
1128
+ end
1129
+ end
1130
+
1131
+ # Parameters for {Chat#decrypt_event}.
1132
+ class DecryptEventParams
1133
+ attr_accessor :event_b64, :conversation_keys, :signing_keys
1134
+
1135
+ def initialize(event_b64:, conversation_keys: nil, signing_keys: nil)
1136
+ @event_b64 = event_b64
1137
+ @conversation_keys = conversation_keys
1138
+ @signing_keys = signing_keys
1139
+ end
1140
+
1141
+ def inspect
1142
+ "#<#{self.class.name} event_b64=#{@event_b64.inspect} " \
1143
+ "conversation_keys=[REDACTED] signing_keys=#{@signing_keys ? @signing_keys.length : 'nil'}>"
1144
+ end
1145
+ end
1146
+
1147
+ # Parameters for {Chat#decrypt_events}.
1148
+ class DecryptEventsParams
1149
+ attr_accessor :events, :signing_keys
1150
+
1151
+ def initialize(events:, signing_keys: nil)
1152
+ @events = events
1153
+ @signing_keys = signing_keys
1154
+ end
1155
+ end
1156
+
1157
+ # Parameters for {Chat#encrypt_message}.
1158
+ class EncryptMessageParams
1159
+ attr_accessor :conversation_id, :text, :sender_id, :signing_key_version,
1160
+ :conversation_key, :conversation_key_version, :entities,
1161
+ :attachments, :quick_reply, :should_notify, :ttl_msec
1162
+
1163
+ def initialize(
1164
+ conversation_id:,
1165
+ text:,
1166
+ sender_id: nil,
1167
+ signing_key_version: nil,
1168
+ conversation_key: nil,
1169
+ conversation_key_version: nil,
1170
+ entities: nil,
1171
+ attachments: nil,
1172
+ quick_reply: nil,
1173
+ should_notify: nil,
1174
+ ttl_msec: nil
1175
+ )
1176
+ @conversation_id = conversation_id
1177
+ @text = text
1178
+ @sender_id = sender_id
1179
+ @signing_key_version = signing_key_version
1180
+ @conversation_key = conversation_key
1181
+ @conversation_key_version = conversation_key_version
1182
+ @entities = entities
1183
+ @attachments = attachments
1184
+ @quick_reply = quick_reply
1185
+ @should_notify = should_notify
1186
+ @ttl_msec = ttl_msec
1187
+ end
1188
+
1189
+ def inspect
1190
+ "#<#{self.class.name} conversation_id=#{@conversation_id.inspect} " \
1191
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'} " \
1192
+ "conversation_key_version=#{@conversation_key_version.inspect}>"
1193
+ end
1194
+ end
1195
+
1196
+ # Parameters for {Chat#encrypt_forward}.
1197
+ class EncryptForwardParams
1198
+ attr_accessor :conversation_id, :forwarded_text, :forwarded_entities,
1199
+ :text, :entities, :attachments, :sender_id, :signing_key_version,
1200
+ :conversation_key, :conversation_key_version, :should_notify, :ttl_msec
1201
+
1202
+ def initialize(
1203
+ conversation_id:,
1204
+ forwarded_text:,
1205
+ forwarded_entities: nil,
1206
+ text: nil,
1207
+ entities: nil,
1208
+ attachments: nil,
1209
+ sender_id: nil,
1210
+ signing_key_version: nil,
1211
+ conversation_key: nil,
1212
+ conversation_key_version: nil,
1213
+ should_notify: nil,
1214
+ ttl_msec: nil
1215
+ )
1216
+ @conversation_id = conversation_id
1217
+ @forwarded_text = forwarded_text
1218
+ @forwarded_entities = forwarded_entities
1219
+ @text = text
1220
+ @entities = entities
1221
+ @attachments = attachments
1222
+ @sender_id = sender_id
1223
+ @signing_key_version = signing_key_version
1224
+ @conversation_key = conversation_key
1225
+ @conversation_key_version = conversation_key_version
1226
+ @should_notify = should_notify
1227
+ @ttl_msec = ttl_msec
1228
+ end
1229
+
1230
+ def inspect
1231
+ "#<#{self.class.name} conversation_id=#{@conversation_id.inspect} " \
1232
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1233
+ end
1234
+ end
1235
+
1236
+ # Parameters for {Chat#encrypt_reply}.
1237
+ class EncryptReplyParams
1238
+ attr_accessor :conversation_id, :text, :reply_to_event, :reply_to_edit_event,
1239
+ :reply_to_ckces, :sender_id, :signing_key_version,
1240
+ :conversation_key, :conversation_key_version,
1241
+ :reply_to_sequence_id, :reply_to_message_id, :reply_to_sender_id,
1242
+ :reply_to_text, :entities, :attachments, :reply_to_entities,
1243
+ :reply_to_attachments, :reply_to_attachment_id, :quick_reply,
1244
+ :should_notify, :ttl_msec
1245
+
1246
+ def initialize(
1247
+ conversation_id:,
1248
+ text:,
1249
+ reply_to_event: nil,
1250
+ reply_to_edit_event: nil,
1251
+ reply_to_ckces: nil,
1252
+ sender_id: nil,
1253
+ signing_key_version: nil,
1254
+ conversation_key: nil,
1255
+ conversation_key_version: nil,
1256
+ reply_to_sequence_id: nil,
1257
+ reply_to_message_id: nil,
1258
+ reply_to_sender_id: nil,
1259
+ reply_to_text: nil,
1260
+ entities: nil,
1261
+ attachments: nil,
1262
+ reply_to_entities: nil,
1263
+ reply_to_attachments: nil,
1264
+ reply_to_attachment_id: nil,
1265
+ quick_reply: nil,
1266
+ should_notify: nil,
1267
+ ttl_msec: nil
1268
+ )
1269
+ @conversation_id = conversation_id
1270
+ @text = text
1271
+ @reply_to_event = reply_to_event.nil? || reply_to_event.empty? ? nil : reply_to_event
1272
+ @reply_to_edit_event = reply_to_edit_event
1273
+ @reply_to_ckces = reply_to_ckces
1274
+ @sender_id = sender_id
1275
+ @signing_key_version = signing_key_version
1276
+ @conversation_key = conversation_key
1277
+ @conversation_key_version = conversation_key_version
1278
+ @reply_to_sequence_id = reply_to_sequence_id
1279
+ @reply_to_message_id = reply_to_message_id
1280
+ @reply_to_sender_id = reply_to_sender_id
1281
+ @reply_to_text = reply_to_text
1282
+ @entities = entities
1283
+ @attachments = attachments
1284
+ @reply_to_entities = reply_to_entities
1285
+ @reply_to_attachments = reply_to_attachments
1286
+ @reply_to_attachment_id = reply_to_attachment_id
1287
+ @quick_reply = quick_reply
1288
+ @should_notify = should_notify
1289
+ @ttl_msec = ttl_msec
1290
+ end
1291
+
1292
+ def inspect
1293
+ "#<#{self.class.name} conversation_id=#{@conversation_id.inspect} " \
1294
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1295
+ end
1296
+ end
1297
+
1298
+ # Parameters for {Chat#encrypt_add_reaction} and {Chat#encrypt_remove_reaction}.
1299
+ class EncryptReactionParams
1300
+ attr_accessor :emoji, :target_event, :conversation_id, :target_message_sequence_id,
1301
+ :sender_id, :signing_key_version, :conversation_key,
1302
+ :conversation_key_version, :target_attachment_id
1303
+
1304
+ def initialize(
1305
+ emoji:,
1306
+ target_event: nil,
1307
+ conversation_id: nil,
1308
+ target_message_sequence_id: nil,
1309
+ sender_id: nil,
1310
+ signing_key_version: nil,
1311
+ conversation_key: nil,
1312
+ conversation_key_version: nil,
1313
+ target_attachment_id: nil
1314
+ )
1315
+ @emoji = emoji
1316
+ @target_event = target_event.nil? || target_event.empty? ? nil : target_event
1317
+ @conversation_id = conversation_id
1318
+ @target_message_sequence_id = target_message_sequence_id
1319
+ @sender_id = sender_id
1320
+ @signing_key_version = signing_key_version
1321
+ @conversation_key = conversation_key
1322
+ @conversation_key_version = conversation_key_version
1323
+ @target_attachment_id = target_attachment_id
1324
+ end
1325
+
1326
+ def inspect
1327
+ "#<#{self.class.name} emoji=#{@emoji.inspect} " \
1328
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1329
+ end
1330
+ end
1331
+
1332
+ # Parameters for {Chat#encrypt_edit}.
1333
+ class EncryptEditParams
1334
+ attr_accessor :updated_text, :target_event, :entities, :conversation_id,
1335
+ :target_message_sequence_id, :target_message_id, :sender_id,
1336
+ :signing_key_version, :conversation_key, :conversation_key_version
1337
+
1338
+ def initialize(
1339
+ updated_text:,
1340
+ target_event: nil,
1341
+ entities: nil,
1342
+ conversation_id: nil,
1343
+ target_message_sequence_id: nil,
1344
+ target_message_id: nil,
1345
+ sender_id: nil,
1346
+ signing_key_version: nil,
1347
+ conversation_key: nil,
1348
+ conversation_key_version: nil
1349
+ )
1350
+ @updated_text = updated_text
1351
+ @target_event = target_event.nil? || target_event.empty? ? nil : target_event
1352
+ @entities = entities
1353
+ @conversation_id = conversation_id
1354
+ @target_message_sequence_id = target_message_sequence_id
1355
+ @target_message_id = target_message_id
1356
+ @sender_id = sender_id
1357
+ @signing_key_version = signing_key_version
1358
+ @conversation_key = conversation_key
1359
+ @conversation_key_version = conversation_key_version
1360
+ end
1361
+
1362
+ def inspect
1363
+ "#<#{self.class.name} conversation_id=#{@conversation_id.inspect} " \
1364
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1365
+ end
1366
+ end
1367
+
1368
+ # Parameters for {Chat#encrypt_file}.
1369
+ class EncryptFileParams
1370
+ attr_accessor :file, :event_b64, :media_hash_key, :conversation_key,
1371
+ :conversation_key_version
1372
+
1373
+ def initialize(
1374
+ file:,
1375
+ event_b64:,
1376
+ media_hash_key:,
1377
+ conversation_key: nil,
1378
+ conversation_key_version: nil
1379
+ )
1380
+ @file = file
1381
+ @event_b64 = event_b64
1382
+ @media_hash_key = media_hash_key
1383
+ @conversation_key = conversation_key
1384
+ @conversation_key_version = conversation_key_version
1385
+ end
1386
+
1387
+ def inspect
1388
+ "#<#{self.class.name} media_hash_key=#{@media_hash_key.inspect} " \
1389
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1390
+ end
1391
+ end
1392
+
1393
+ # Parameters for {Chat#file_encryptor}.
1394
+ class FileEncryptorParams
1395
+ attr_accessor :event_b64, :media_hash_key, :conversation_key,
1396
+ :conversation_key_version
1397
+
1398
+ def initialize(
1399
+ event_b64:,
1400
+ media_hash_key:,
1401
+ conversation_key: nil,
1402
+ conversation_key_version: nil
1403
+ )
1404
+ @event_b64 = event_b64
1405
+ @media_hash_key = media_hash_key
1406
+ @conversation_key = conversation_key
1407
+ @conversation_key_version = conversation_key_version
1408
+ end
1409
+
1410
+ def inspect
1411
+ "#<#{self.class.name} media_hash_key=#{@media_hash_key.inspect} " \
1412
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1413
+ end
1414
+ end
1415
+
1416
+ # Parameters for {Chat#decrypt_file}.
1417
+ class DecryptFileParams
1418
+ attr_accessor :encrypted, :event_b64, :media_hash_key, :conversation_keys
1419
+
1420
+ def initialize(encrypted:, event_b64:, media_hash_key:, conversation_keys: nil)
1421
+ @encrypted = encrypted
1422
+ @event_b64 = event_b64
1423
+ @media_hash_key = media_hash_key
1424
+ @conversation_keys = conversation_keys
1425
+ end
1426
+
1427
+ def inspect
1428
+ "#<#{self.class.name} media_hash_key=#{@media_hash_key.inspect} conversation_keys=[REDACTED]>"
1429
+ end
1430
+ end
1431
+
1432
+ # Parameters for {Chat#file_decryptor}.
1433
+ class FileDecryptorParams
1434
+ attr_accessor :event_b64, :media_hash_key, :conversation_keys
1435
+
1436
+ def initialize(event_b64:, media_hash_key:, conversation_keys: nil)
1437
+ @event_b64 = event_b64
1438
+ @media_hash_key = media_hash_key
1439
+ @conversation_keys = conversation_keys
1440
+ end
1441
+
1442
+ def inspect
1443
+ "#<#{self.class.name} media_hash_key=#{@media_hash_key.inspect} conversation_keys=[REDACTED]>"
1444
+ end
1445
+ end
1446
+
1447
+ # Parameters for {Chat#encrypt_file_with_key}.
1448
+ class EncryptFileWithKeyParams
1449
+ attr_accessor :file, :key
1450
+
1451
+ def initialize(file:, key:)
1452
+ @file = file
1453
+ @key = key
1454
+ end
1455
+
1456
+ def inspect
1457
+ "#<#{self.class.name} key=[REDACTED]>"
1458
+ end
1459
+ end
1460
+
1461
+ # Parameters for {Chat#decrypt_file_with_key}.
1462
+ class DecryptFileWithKeyParams
1463
+ attr_accessor :encrypted, :key
1464
+
1465
+ def initialize(encrypted:, key:)
1466
+ @encrypted = encrypted
1467
+ @key = key
1468
+ end
1469
+
1470
+ def inspect
1471
+ "#<#{self.class.name} key=[REDACTED]>"
1472
+ end
1473
+ end
1474
+
1475
+ # Parameters for {Chat#prepare_conversation_key_change}.
1476
+ class ConversationKeyChangeParams
1477
+ attr_accessor :public_keys, :sender_id, :signing_key_version,
1478
+ :conversation_id, :member_ids
1479
+
1480
+ def initialize(
1481
+ public_keys: nil,
1482
+ sender_id: nil,
1483
+ signing_key_version: nil,
1484
+ conversation_id: nil,
1485
+ member_ids: nil
1486
+ )
1487
+ @public_keys = public_keys
1488
+ @sender_id = sender_id
1489
+ @signing_key_version = signing_key_version
1490
+ @conversation_id = conversation_id
1491
+ @member_ids = member_ids
1492
+ end
1493
+ end
1494
+
1495
+ # Parameters for {Chat#prepare_group_members_change}.
1496
+ class GroupMembersChangeParams
1497
+ attr_accessor :public_keys, :conversation_id, :new_member_ids,
1498
+ :current_member_ids, :current_admin_ids, :current_pending_member_ids,
1499
+ :sender_id, :signing_key_version, :current_title, :current_avatar_url,
1500
+ :current_description, :current_ttl_msec,
1501
+ :current_screen_capture_blocking_enabled
1502
+
1503
+ def initialize(
1504
+ conversation_id:,
1505
+ new_member_ids:,
1506
+ current_member_ids:,
1507
+ current_admin_ids:,
1508
+ current_pending_member_ids:,
1509
+ public_keys: nil,
1510
+ sender_id: nil,
1511
+ signing_key_version: nil,
1512
+ current_title: nil,
1513
+ current_avatar_url: nil,
1514
+ current_description: nil,
1515
+ current_ttl_msec: nil,
1516
+ current_screen_capture_blocking_enabled: nil
1517
+ )
1518
+ @public_keys = public_keys
1519
+ @conversation_id = conversation_id
1520
+ @new_member_ids = new_member_ids
1521
+ @current_member_ids = current_member_ids
1522
+ @current_admin_ids = current_admin_ids
1523
+ @current_pending_member_ids = current_pending_member_ids
1524
+ @sender_id = sender_id
1525
+ @signing_key_version = signing_key_version
1526
+ @current_title = current_title
1527
+ @current_avatar_url = current_avatar_url
1528
+ @current_description = current_description
1529
+ @current_ttl_msec = current_ttl_msec
1530
+ @current_screen_capture_blocking_enabled = current_screen_capture_blocking_enabled
1531
+ end
1532
+ end
1533
+
1534
+ # Parameters for {Chat#prepare_group_create}.
1535
+ class GroupCreateParams
1536
+ attr_accessor :public_keys, :conversation_id, :member_ids, :admin_ids,
1537
+ :sender_id, :signing_key_version, :title, :ttl_msec
1538
+
1539
+ def initialize(
1540
+ conversation_id:,
1541
+ member_ids:,
1542
+ admin_ids:,
1543
+ public_keys: nil,
1544
+ sender_id: nil,
1545
+ signing_key_version: nil,
1546
+ title: nil,
1547
+ ttl_msec: nil
1548
+ )
1549
+ @public_keys = public_keys
1550
+ @conversation_id = conversation_id
1551
+ @member_ids = member_ids
1552
+ @admin_ids = admin_ids
1553
+ @sender_id = sender_id
1554
+ @signing_key_version = signing_key_version
1555
+ @title = title
1556
+ @ttl_msec = ttl_msec
1557
+ end
1558
+ end
1559
+
1560
+ # Parameters for {Chat#prepare_group_members_remove}.
1561
+ class GroupMembersRemoveParams
1562
+ attr_accessor :public_keys, :conversation_id, :user_ids, :remaining_member_ids,
1563
+ :title, :description, :sender_id, :signing_key_version
1564
+
1565
+ def initialize(
1566
+ conversation_id:,
1567
+ user_ids:,
1568
+ public_keys: nil,
1569
+ remaining_member_ids: nil,
1570
+ title: nil,
1571
+ description: nil,
1572
+ sender_id: nil,
1573
+ signing_key_version: nil
1574
+ )
1575
+ @public_keys = public_keys
1576
+ @conversation_id = conversation_id
1577
+ @user_ids = user_ids
1578
+ @remaining_member_ids = remaining_member_ids
1579
+ @title = title
1580
+ @description = description
1581
+ @sender_id = sender_id
1582
+ @signing_key_version = signing_key_version
1583
+ end
1584
+ end
1585
+
1586
+ # Parameters for {Chat#prepare_group_leave}.
1587
+ class GroupLeaveParams
1588
+ attr_accessor :conversation_id, :promote_admin_id, :conversation_key_version,
1589
+ :sender_id, :signing_key_version
1590
+
1591
+ def initialize(
1592
+ conversation_id:,
1593
+ promote_admin_id: nil,
1594
+ conversation_key_version: nil,
1595
+ sender_id: nil,
1596
+ signing_key_version: nil
1597
+ )
1598
+ @conversation_id = conversation_id
1599
+ @promote_admin_id = promote_admin_id
1600
+ @conversation_key_version = conversation_key_version
1601
+ @sender_id = sender_id
1602
+ @signing_key_version = signing_key_version
1603
+ end
1604
+ end
1605
+
1606
+ # Parameters for {Chat#prepare_group_title_change}.
1607
+ class GroupTitleChangeParams
1608
+ attr_accessor :conversation_id, :new_title, :sender_id, :signing_key_version,
1609
+ :conversation_key, :conversation_key_version
1610
+
1611
+ def initialize(
1612
+ conversation_id:,
1613
+ new_title:,
1614
+ sender_id: nil,
1615
+ signing_key_version: nil,
1616
+ conversation_key: nil,
1617
+ conversation_key_version: nil
1618
+ )
1619
+ @conversation_id = conversation_id
1620
+ @new_title = new_title
1621
+ @sender_id = sender_id
1622
+ @signing_key_version = signing_key_version
1623
+ @conversation_key = conversation_key
1624
+ @conversation_key_version = conversation_key_version
1625
+ end
1626
+
1627
+ def inspect
1628
+ "#<#{self.class.name} conversation_id=#{@conversation_id.inspect} " \
1629
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1630
+ end
1631
+ end
1632
+
1633
+ # Parameters for {Chat#prepare_group_avatar_change}.
1634
+ class GroupAvatarChangeParams
1635
+ attr_accessor :conversation_id, :new_avatar_url, :conversation_key_version,
1636
+ :sender_id, :signing_key_version
1637
+
1638
+ def initialize(
1639
+ conversation_id:,
1640
+ new_avatar_url:,
1641
+ conversation_key_version: nil,
1642
+ sender_id: nil,
1643
+ signing_key_version: nil
1644
+ )
1645
+ @conversation_id = conversation_id
1646
+ @new_avatar_url = new_avatar_url
1647
+ @conversation_key_version = conversation_key_version
1648
+ @sender_id = sender_id
1649
+ @signing_key_version = signing_key_version
1650
+ end
1651
+ end
1652
+
1653
+ # Parameters for {Chat#prepare_group_description_change}.
1654
+ class GroupDescriptionChangeParams
1655
+ attr_accessor :conversation_id, :new_description, :sender_id, :signing_key_version,
1656
+ :conversation_key, :conversation_key_version
1657
+
1658
+ def initialize(
1659
+ conversation_id:,
1660
+ new_description:,
1661
+ sender_id: nil,
1662
+ signing_key_version: nil,
1663
+ conversation_key: nil,
1664
+ conversation_key_version: nil
1665
+ )
1666
+ @conversation_id = conversation_id
1667
+ @new_description = new_description
1668
+ @sender_id = sender_id
1669
+ @signing_key_version = signing_key_version
1670
+ @conversation_key = conversation_key
1671
+ @conversation_key_version = conversation_key_version
1672
+ end
1673
+
1674
+ def inspect
1675
+ "#<#{self.class.name} conversation_id=#{@conversation_id.inspect} " \
1676
+ "conversation_key=#{@conversation_key ? '[REDACTED]' : 'nil'}>"
1677
+ end
1678
+ end
1679
+
1680
+ # Parameters for {Chat#prepare_group_admins_add}.
1681
+ class GroupAdminsAddParams
1682
+ attr_accessor :conversation_id, :user_ids, :sender_id, :signing_key_version
1683
+
1684
+ def initialize(conversation_id:, user_ids:, sender_id: nil, signing_key_version: nil)
1685
+ @conversation_id = conversation_id
1686
+ @user_ids = user_ids
1687
+ @sender_id = sender_id
1688
+ @signing_key_version = signing_key_version
1689
+ end
1690
+ end
1691
+
1692
+ # Parameters for {Chat#prepare_group_admins_remove}.
1693
+ class GroupAdminsRemoveParams
1694
+ attr_accessor :conversation_id, :user_ids, :sender_id, :signing_key_version
1695
+
1696
+ def initialize(conversation_id:, user_ids:, sender_id: nil, signing_key_version: nil)
1697
+ @conversation_id = conversation_id
1698
+ @user_ids = user_ids
1699
+ @sender_id = sender_id
1700
+ @signing_key_version = signing_key_version
1701
+ end
1702
+ end
1703
+
1704
+ # Parameters for {Chat#prepare_group_invite_enable}.
1705
+ class GroupInviteEnableParams
1706
+ attr_accessor :conversation_id, :invite_url, :expires_at_msec, :affiliate_id,
1707
+ :sender_id, :signing_key_version
1708
+
1709
+ def initialize(
1710
+ conversation_id:,
1711
+ invite_url:,
1712
+ expires_at_msec: nil,
1713
+ affiliate_id: nil,
1714
+ sender_id: nil,
1715
+ signing_key_version: nil
1716
+ )
1717
+ @conversation_id = conversation_id
1718
+ @invite_url = invite_url
1719
+ @expires_at_msec = expires_at_msec
1720
+ @affiliate_id = affiliate_id
1721
+ @sender_id = sender_id
1722
+ @signing_key_version = signing_key_version
1723
+ end
1724
+ end
1725
+
1726
+ # Parameters for {Chat#prepare_group_invite_disable}.
1727
+ class GroupInviteDisableParams
1728
+ attr_accessor :conversation_id, :disabled_by, :sender_id, :signing_key_version
1729
+
1730
+ def initialize(conversation_id:, disabled_by: nil, sender_id: nil, signing_key_version: nil)
1731
+ @conversation_id = conversation_id
1732
+ @disabled_by = disabled_by
1733
+ @sender_id = sender_id
1734
+ @signing_key_version = signing_key_version
1735
+ end
1736
+ end
1737
+
1738
+ # Parameters for {Chat#prepare_group_join_request}.
1739
+ class GroupJoinRequestParams
1740
+ attr_accessor :conversation_id, :requesting_user_id, :sender_id, :signing_key_version
1741
+
1742
+ def initialize(conversation_id:, requesting_user_id: nil, sender_id: nil, signing_key_version: nil)
1743
+ @conversation_id = conversation_id
1744
+ @requesting_user_id = requesting_user_id
1745
+ @sender_id = sender_id
1746
+ @signing_key_version = signing_key_version
1747
+ end
1748
+ end
1749
+
1750
+ # Parameters for {Chat#prepare_group_join_reject}.
1751
+ class GroupJoinRejectParams
1752
+ attr_accessor :conversation_id, :user_ids, :sender_id, :signing_key_version
1753
+
1754
+ def initialize(conversation_id:, user_ids:, sender_id: nil, signing_key_version: nil)
1755
+ @conversation_id = conversation_id
1756
+ @user_ids = user_ids
1757
+ @sender_id = sender_id
1758
+ @signing_key_version = signing_key_version
1759
+ end
1760
+ end
1761
+
1762
+ # Parameters for {Chat#prepare_message_ttl_change}.
1763
+ class MessageTtlChangeParams
1764
+ attr_accessor :conversation_id, :ttl_msec, :sender_id, :signing_key_version
1765
+
1766
+ def initialize(conversation_id:, ttl_msec:, sender_id: nil, signing_key_version: nil)
1767
+ @conversation_id = conversation_id
1768
+ @ttl_msec = ttl_msec
1769
+ @sender_id = sender_id
1770
+ @signing_key_version = signing_key_version
1771
+ end
1772
+ end
1773
+
1774
+ # Parameters for {Chat#prepare_message_ttl_remove}.
1775
+ class MessageTtlRemoveParams
1776
+ attr_accessor :conversation_id, :sender_id, :signing_key_version
1777
+
1778
+ def initialize(conversation_id:, sender_id: nil, signing_key_version: nil)
1779
+ @conversation_id = conversation_id
1780
+ @sender_id = sender_id
1781
+ @signing_key_version = signing_key_version
1782
+ end
1783
+ end
1784
+
1785
+ # Parameters for {Chat#prepare_conversation_mute}.
1786
+ class ConversationMuteParams
1787
+ attr_accessor :conversation_id, :muted, :sender_id, :signing_key_version
1788
+
1789
+ def initialize(conversation_id:, muted:, sender_id: nil, signing_key_version: nil)
1790
+ @conversation_id = conversation_id
1791
+ @muted = muted
1792
+ @sender_id = sender_id
1793
+ @signing_key_version = signing_key_version
1794
+ end
1795
+ end
1796
+
1797
+ # Parameters for {Chat#prepare_screen_capture}.
1798
+ class ScreenCaptureParams
1799
+ attr_accessor :conversation_id, :change, :sender_id, :signing_key_version
1800
+
1801
+ def initialize(conversation_id:, change:, sender_id: nil, signing_key_version: nil)
1802
+ @conversation_id = conversation_id
1803
+ @change = change
1804
+ @sender_id = sender_id
1805
+ @signing_key_version = signing_key_version
1806
+ end
1807
+ end
1808
+
1809
+ # Parameters for {Chat#prepare_conversation_archive}.
1810
+ class ConversationArchiveParams
1811
+ attr_accessor :conversation_id, :archived, :sender_id, :signing_key_version
1812
+
1813
+ def initialize(conversation_id:, archived:, sender_id: nil, signing_key_version: nil)
1814
+ @conversation_id = conversation_id
1815
+ @archived = archived
1816
+ @sender_id = sender_id
1817
+ @signing_key_version = signing_key_version
1818
+ end
1819
+ end
1820
+
1821
+ # Parameters for {Chat#prepare_message_delete}.
1822
+ class MessageDeleteParams
1823
+ attr_accessor :conversation_id, :sequence_ids, :delete_for_all,
1824
+ :sender_id, :signing_key_version
1825
+
1826
+ def initialize(
1827
+ conversation_id:,
1828
+ sequence_ids:,
1829
+ delete_for_all:,
1830
+ sender_id: nil,
1831
+ signing_key_version: nil
1832
+ )
1833
+ @conversation_id = conversation_id
1834
+ @sequence_ids = sequence_ids
1835
+ @delete_for_all = delete_for_all
1836
+ @sender_id = sender_id
1837
+ @signing_key_version = signing_key_version
1838
+ end
1839
+ end
1840
+
1841
+ # Parameters for {Chat#prepare_mark_conversation_read}.
1842
+ class MarkConversationReadParams
1843
+ attr_accessor :conversation_id, :seen_until_sequence_id, :seen_at_msec,
1844
+ :sender_id, :signing_key_version
1845
+
1846
+ def initialize(
1847
+ conversation_id:,
1848
+ seen_until_sequence_id:,
1849
+ seen_at_msec: nil,
1850
+ sender_id: nil,
1851
+ signing_key_version: nil
1852
+ )
1853
+ @conversation_id = conversation_id
1854
+ @seen_until_sequence_id = seen_until_sequence_id
1855
+ @seen_at_msec = seen_at_msec
1856
+ @sender_id = sender_id
1857
+ @signing_key_version = signing_key_version
1858
+ end
1859
+ end
1860
+ end