From 69d60f47f2637f6ca073a869f70c23ae21d58137 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Mon, 15 Sep 2025 10:21:26 +0200 Subject: [PATCH 1/5] feat[cha-1225]: support delivery receipts --- lib/stream-chat/client.rb | 11 +++++++++++ spec/client_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/stream-chat/client.rb b/lib/stream-chat/client.rb index dbbd7ab..8f49a0b 100644 --- a/lib/stream-chat/client.rb +++ b/lib/stream-chat/client.rb @@ -1065,6 +1065,17 @@ def query_reminders(user_id, filter_conditions = {}, sort: nil, **options) post('reminders/query', data: params) end + # Send the mark delivered event for this user, only works if the `delivery_receipts` setting is enabled + # + # @param [StringKeyHash, nil] data The delivery confirmation data + # @return [StreamChat::StreamResponse] API response + sig { params(data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) } + def mark_channels_delivered(data = nil) + # Note: In the Ruby SDK, we don't have access to user privacy settings from the client + # The server will handle the delivery_receipts check and return appropriate response + post('channels/delivered', data: data || {}) + end + private sig { returns(T::Hash[String, String]) } diff --git a/spec/client_spec.rb b/spec/client_spec.rb index ddde19e..57dd88a 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -1435,4 +1435,38 @@ def loop_times(times) expect(response['active_live_locations'].length).to be >= 1 end end + + describe '#mark_channels_delivered' do + it 'should mark channels as delivered' do + # Create some test messages first + message1 = @channel.send_message({ text: 'Test message 1' }, @frodo) + message2 = @channel.send_message({ text: 'Test message 2' }, @sam) + + # Create delivery confirmation data + delivery_data = { + latest_delivered_messages: [ + { + cid: @channel.cid, + id: message1['message']['id'] + }, + { + cid: @channel.cid, + id: message2['message']['id'] + } + ], + user_id: @gandalf + } + + # Call the method + response = @client.mark_channels_delivered(delivery_data) + + # The response should be successful (status 200) + expect(response.status_code).to eq(200) + end + + it 'should handle empty data' do + response = @client.mark_channels_delivered + expect(response.status_code).to eq(200) + end + end end From 417d6f3a71601774f8669693791d1d827421da8a Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Mon, 15 Sep 2025 10:25:59 +0200 Subject: [PATCH 2/5] remove comment --- lib/stream-chat/client.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/stream-chat/client.rb b/lib/stream-chat/client.rb index 8f49a0b..74295c7 100644 --- a/lib/stream-chat/client.rb +++ b/lib/stream-chat/client.rb @@ -1071,8 +1071,6 @@ def query_reminders(user_id, filter_conditions = {}, sort: nil, **options) # @return [StreamChat::StreamResponse] API response sig { params(data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) } def mark_channels_delivered(data = nil) - # Note: In the Ruby SDK, we don't have access to user privacy settings from the client - # The server will handle the delivery_receipts check and return appropriate response post('channels/delivered', data: data || {}) end From 70eee3b632bb2a29af27dcbd4e788b34cb22328f Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Sat, 4 Oct 2025 09:07:04 +0200 Subject: [PATCH 3/5] fix --- lib/stream-chat/client.rb | 4 ++-- spec/client_spec.rb | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/stream-chat/client.rb b/lib/stream-chat/client.rb index 74295c7..ff69a08 100644 --- a/lib/stream-chat/client.rb +++ b/lib/stream-chat/client.rb @@ -1070,8 +1070,8 @@ def query_reminders(user_id, filter_conditions = {}, sort: nil, **options) # @param [StringKeyHash, nil] data The delivery confirmation data # @return [StreamChat::StreamResponse] API response sig { params(data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) } - def mark_channels_delivered(data = nil) - post('channels/delivered', data: data || {}) + def mark_delivered(data = nil, user_id: nil) + post('channels/delivered', data: data || {}, params: { user_id: user_id }) end private diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 57dd88a..cb4f6f4 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -1436,37 +1436,27 @@ def loop_times(times) end end - describe '#mark_channels_delivered' do - it 'should mark channels as delivered' do + describe '#mark_delivered' do + it 'should mark messages as delivered' do # Create some test messages first - message1 = @channel.send_message({ text: 'Test message 1' }, @frodo) - message2 = @channel.send_message({ text: 'Test message 2' }, @sam) + message = @channel.send_message({ text: 'Test message 1' }, @frodo) # Create delivery confirmation data delivery_data = { latest_delivered_messages: [ { cid: @channel.cid, - id: message1['message']['id'] - }, - { - cid: @channel.cid, - id: message2['message']['id'] + id: message['message']['id'] } ], user_id: @gandalf } # Call the method - response = @client.mark_channels_delivered(delivery_data) + response = @client.mark_delivered(delivery_data, user_id: @gandalf) # The response should be successful (status 200) expect(response.status_code).to eq(200) end - - it 'should handle empty data' do - response = @client.mark_channels_delivered - expect(response.status_code).to eq(200) - end end end From 7eb8162db5d2a609267b84ab462b80ed059e8a6f Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Sat, 4 Oct 2025 09:19:35 +0200 Subject: [PATCH 4/5] fix unit tests --- lib/stream-chat/client.rb | 2 +- spec/channel_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/stream-chat/client.rb b/lib/stream-chat/client.rb index ff69a08..13a96f1 100644 --- a/lib/stream-chat/client.rb +++ b/lib/stream-chat/client.rb @@ -1069,7 +1069,7 @@ def query_reminders(user_id, filter_conditions = {}, sort: nil, **options) # # @param [StringKeyHash, nil] data The delivery confirmation data # @return [StreamChat::StreamResponse] API response - sig { params(data: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) } + sig { params(data: T.nilable(StringKeyHash), user_id: T.nilable(String)).returns(StreamChat::StreamResponse) } def mark_delivered(data = nil, user_id: nil) post('channels/delivered', data: data || {}, params: { user_id: user_id }) end diff --git a/spec/channel_spec.rb b/spec/channel_spec.rb index 9ff2755..0971ef3 100644 --- a/spec/channel_spec.rb +++ b/spec/channel_spec.rb @@ -354,6 +354,9 @@ def loop_times(times) end it 'can send message with restricted visibility' do + # Add users as members before testing restricted visibility + @channel.add_members([@random_users[0][:id], @random_users[1][:id]]) + # Send a message that's only visible to specific users msg = @channel.send_message( { @@ -372,6 +375,9 @@ def loop_times(times) end it 'can update message with restricted visibility' do + # Add users as members before testing restricted visibility + @channel.add_members([@random_users[0][:id], @random_users[1][:id]]) + # First send a regular message msg = @channel.send_message( { @@ -399,6 +405,9 @@ def loop_times(times) end it 'can update message partially with restricted visibility' do + # Add users as members before testing restricted visibility + @channel.add_members([@random_users[0][:id], @random_users[1][:id]]) + # First send a regular message msg = @channel.send_message( { From 27bc4779d807ef1d1ef52f04c503177d13741654 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Sat, 4 Oct 2025 09:22:19 +0200 Subject: [PATCH 5/5] fix http code --- spec/client_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/client_spec.rb b/spec/client_spec.rb index cb4f6f4..5dc819d 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -1455,8 +1455,8 @@ def loop_times(times) # Call the method response = @client.mark_delivered(delivery_data, user_id: @gandalf) - # The response should be successful (status 200) - expect(response.status_code).to eq(200) + # The response should be successful (status 201) + expect(response.status_code).to eq(201) end end end