Skip to content

Commit b796d0f

Browse files
rafaelmf3Rafael Marinho
andauthored
feat[cha-1225]: support delivery receipts (#180)
* feat[cha-1225]: support delivery receipts * remove comment * fix * fix unit tests * fix http code --------- Co-authored-by: Rafael Marinho <[email protected]>
1 parent bae463b commit b796d0f

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

lib/stream-chat/client.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,15 @@ def query_reminders(user_id, filter_conditions = {}, sort: nil, **options)
10651065
post('reminders/query', data: params)
10661066
end
10671067

1068+
# Send the mark delivered event for this user, only works if the `delivery_receipts` setting is enabled
1069+
#
1070+
# @param [StringKeyHash, nil] data The delivery confirmation data
1071+
# @return [StreamChat::StreamResponse] API response
1072+
sig { params(data: T.nilable(StringKeyHash), user_id: T.nilable(String)).returns(StreamChat::StreamResponse) }
1073+
def mark_delivered(data = nil, user_id: nil)
1074+
post('channels/delivered', data: data || {}, params: { user_id: user_id })
1075+
end
1076+
10681077
private
10691078

10701079
sig { returns(T::Hash[String, String]) }

spec/channel_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ def loop_times(times)
354354
end
355355

356356
it 'can send message with restricted visibility' do
357+
# Add users as members before testing restricted visibility
358+
@channel.add_members([@random_users[0][:id], @random_users[1][:id]])
359+
357360
# Send a message that's only visible to specific users
358361
msg = @channel.send_message(
359362
{
@@ -372,6 +375,9 @@ def loop_times(times)
372375
end
373376

374377
it 'can update message with restricted visibility' do
378+
# Add users as members before testing restricted visibility
379+
@channel.add_members([@random_users[0][:id], @random_users[1][:id]])
380+
375381
# First send a regular message
376382
msg = @channel.send_message(
377383
{
@@ -399,6 +405,9 @@ def loop_times(times)
399405
end
400406

401407
it 'can update message partially with restricted visibility' do
408+
# Add users as members before testing restricted visibility
409+
@channel.add_members([@random_users[0][:id], @random_users[1][:id]])
410+
402411
# First send a regular message
403412
msg = @channel.send_message(
404413
{

spec/client_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,4 +1435,28 @@ def loop_times(times)
14351435
expect(response['active_live_locations'].length).to be >= 1
14361436
end
14371437
end
1438+
1439+
describe '#mark_delivered' do
1440+
it 'should mark messages as delivered' do
1441+
# Create some test messages first
1442+
message = @channel.send_message({ text: 'Test message 1' }, @frodo)
1443+
1444+
# Create delivery confirmation data
1445+
delivery_data = {
1446+
latest_delivered_messages: [
1447+
{
1448+
cid: @channel.cid,
1449+
id: message['message']['id']
1450+
}
1451+
],
1452+
user_id: @gandalf
1453+
}
1454+
1455+
# Call the method
1456+
response = @client.mark_delivered(delivery_data, user_id: @gandalf)
1457+
1458+
# The response should be successful (status 201)
1459+
expect(response.status_code).to eq(201)
1460+
end
1461+
end
14381462
end

0 commit comments

Comments
 (0)