simplex-chat 0.5.0 → 0.6.0

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: a5abf1b7b550f998760cb68e89636e031dcf96aff3449e9422903db050521bd2
4
- data.tar.gz: 4602313dfbf09bfd9b650c5668f16389d885cf16202b1896fc81f4dd71dfa869
3
+ metadata.gz: 0b49dea10199c71c10df356701b53087eda1e8aeb5c31348e39a62032280d96b
4
+ data.tar.gz: e97b4de663eb4abe3aac556b6f8a1b2cf1dcce1d37b2ebfdfc645a7b8e9c05a4
5
5
  SHA512:
6
- metadata.gz: 5f77b4edf376118de56ff6dde9a99ee06fc49c12f6ef348053a8ba1ec807b885fac6c2ef4c5c6fe48c21d95a10d7b3351a6ad07a8429603f0ec1ee997ea2923e
7
- data.tar.gz: f59fb84f87c57f491eda4e3ab58c30451a376c1c8b79c8e6b190df433f53d4394c4c41b459e8e18940bea91c95517ebd82643cf1e3e65c6093462be3910455c1
6
+ metadata.gz: c2c78755a44732f0b2ab43a080981d4f332c414e2080ff8e4d8ddf76a6af8ed53a0e6c5699561df33b0d8e9d713c92774c1dbff75cc60809adb4ff463f10af8f
7
+ data.tar.gz: 70eb7367381d1442ed72ff4ae92ed7d876d99e1d3d506bd4da9eafa833f7e1e32c814bec37e052ca9c0b932f726bba59668459de646fac20b004fff14f0ced15
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleXChat
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/simplex-chat.rb CHANGED
@@ -18,7 +18,7 @@ module SimpleXChat
18
18
 
19
19
  def initialize(client_uri, connect: true, log_level: Logger::INFO, timeout_ms: 10_000, interval_ms: 100)
20
20
  @uri = client_uri
21
- @message_queue = SizedQueue.new 4096
21
+ @message_queue = Queue.new
22
22
  @chat_message_queue = Queue.new
23
23
  @socket = nil
24
24
  @handshake = nil
@@ -74,8 +74,8 @@ module SimpleXChat
74
74
  single_use_queue.push(resp)
75
75
  @logger.debug("Message sent to waiter with corrId '#{corr_id}'")
76
76
  else
77
- @logger.debug("Message put on message queue")
78
77
  @message_queue.push resp
78
+ @logger.debug("Message put on message queue (number of messages in queue: #{@message_queue.size})")
79
79
  end
80
80
  rescue IO::WaitReadable
81
81
  IO.select([@socket])
@@ -97,7 +97,9 @@ module SimpleXChat
97
97
  end
98
98
 
99
99
  def next_message
100
- @message_queue.pop
100
+ msg = @message_queue.pop
101
+ @logger.debug("Message retrieved from queue (number of messages in queue: #{@message_queue.size})")
102
+ msg
101
103
  end
102
104
 
103
105
  def next_chat_message(
@@ -135,7 +137,11 @@ module SimpleXChat
135
137
  @chat_message_queue.push chat_message
136
138
  end
137
139
 
138
- return @chat_message_queue.pop
140
+ # NOTE: Even after parsing the messages, the
141
+ # chat message queue can be empty because
142
+ # all the messages are too old, so we have
143
+ # to check again
144
+ return @chat_message_queue.pop if not @chat_message_queue.empty?
139
145
  end
140
146
 
141
147
  nil
@@ -365,6 +371,19 @@ module SimpleXChat
365
371
  end.filter { |x| x != nil }
366
372
  end
367
373
 
374
+ # TODO: Add `/_reaction members` support, either on this
375
+ # function or in a separate one
376
+ def api_reaction(chat_type, chat_id, message_item_id, add: true, emoji: '👍')
377
+ onoff = add ? "on" : "off"
378
+ param_obj = {
379
+ "type" => "emoji",
380
+ "emoji" => emoji
381
+ }
382
+ cmd = "/_reaction #{chat_type}#{chat_id} #{message_item_id} #{onoff} #{param_obj.to_json}"
383
+ resp = send_command cmd
384
+ check_response_type(resp, "chatItemReaction")
385
+ end
386
+
368
387
  private
369
388
 
370
389
  def check_response_type(resp, expected_resp_type)
@@ -389,35 +408,52 @@ module SimpleXChat
389
408
  def parse_chat_item(chat_item)
390
409
  chat_type = parse_chat_info_type chat_item["chatInfo"]["type"]
391
410
  group = nil
411
+ group_id = nil
392
412
  sender = nil
413
+ sender_id = nil
393
414
  contact = nil
415
+ contact_id = nil
394
416
  contact_role = nil
395
417
  if chat_type == ChatType::GROUP
396
418
  # NOTE: The group can "send messages" without a contact
397
419
  # For example, when a member is removed, the group
398
420
  # sends a message about his removal, with no contact
399
421
  contact = chat_item.dig "chatItem", "chatDir", "groupMember", "localDisplayName"
422
+ contact_id = chat_item.dig "chatItem", "chatDir", "groupMember", "groupMemberId"
400
423
  contact_role = chat_item.dig "chatItem", "chatDir", "groupMember", "memberRole"
401
424
  group = chat_item["chatInfo"]["groupInfo"]["localDisplayName"]
425
+ group_id = chat_item["chatInfo"]["groupInfo"]["groupId"]
402
426
  sender = group
427
+ sender_id = group_id
403
428
  else
404
429
  contact = chat_item["chatInfo"]["contact"]["localDisplayName"]
430
+ contact_id = chat_item["chatInfo"]["contact"]["contactId"]
405
431
  sender = contact
432
+ sender_id = contact_id
406
433
  end
407
434
 
408
435
  msg_text = chat_item["chatItem"]["meta"]["itemText"]
436
+ msg_item_id = chat_item["chatItem"]["meta"]["itemId"]
409
437
  timestamp = Time.parse(chat_item["chatItem"]["meta"]["updatedAt"])
410
- image_preview = chat_item.dig "chatItem", "content", "msgContent", "image"
438
+ msg_image_preview = chat_item.dig "chatItem", "content", "msgContent", "image"
411
439
 
412
440
  chat_message = {
413
441
  :chat_type => chat_type,
442
+
414
443
  :sender => sender,
415
- :contact_role => contact_role,
444
+ :sender_id => sender_id,
445
+
416
446
  :contact => contact,
447
+ :contact_id => contact_id,
448
+ :contact_role => contact_role,
449
+
417
450
  :group => group,
451
+ :group_id => group_id,
452
+
418
453
  :msg_text => msg_text,
454
+ :msg_item_id => msg_item_id,
419
455
  :msg_timestamp => timestamp,
420
- :img_preview => image_preview
456
+ :msg_img_preview => msg_image_preview
421
457
  }
422
458
  end
423
459
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplex-chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rdbo
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-04 00:00:00.000000000 Z
10
+ date: 2025-03-05 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: websocket