From 23382fb2e19cd49babe489fbc8d7f620c94bab2a Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 09:20:54 +0100 Subject: [PATCH 1/9] feat: add hide_history_before option for adding members --- lib/stream-chat/channel.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/stream-chat/channel.rb b/lib/stream-chat/channel.rb index ed91ed7..9e35b74 100644 --- a/lib/stream-chat/channel.rb +++ b/lib/stream-chat/channel.rb @@ -234,7 +234,19 @@ def update_member_partial(user_id, set: nil, unset: nil) # Adds members to the channel. sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) } def add_members(user_ids, **options) - payload = options.merge({ add_members: user_ids }) + payload = options.dup + + # Convert hide_history_before timestamp to RFC 3339 format if it's a DateTime or Time object + if payload.key?(:hide_history_before) + hide_history_before = payload[:hide_history_before] + if hide_history_before.is_a?(DateTime) + payload[:hide_history_before] = hide_history_before.rfc3339 + elsif hide_history_before.is_a?(Time) + payload[:hide_history_before] = hide_history_before.iso8601 + end + end + + payload = payload.merge({ add_members: user_ids }) update(nil, nil, **payload) end From ec8839ca7e682794de5ee143ad5ea932e0bcb783 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 09:33:40 +0100 Subject: [PATCH 2/9] remove trailing whitespace --- lib/stream-chat/channel.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stream-chat/channel.rb b/lib/stream-chat/channel.rb index 9e35b74..f9552e1 100644 --- a/lib/stream-chat/channel.rb +++ b/lib/stream-chat/channel.rb @@ -235,7 +235,7 @@ def update_member_partial(user_id, set: nil, unset: nil) sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) } def add_members(user_ids, **options) payload = options.dup - + # Convert hide_history_before timestamp to RFC 3339 format if it's a DateTime or Time object if payload.key?(:hide_history_before) hide_history_before = payload[:hide_history_before] @@ -245,7 +245,7 @@ def add_members(user_ids, **options) payload[:hide_history_before] = hide_history_before.iso8601 end end - + payload = payload.merge({ add_members: user_ids }) update(nil, nil, **payload) end From b2129e34d0a57430a529048b393b520caec06478 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 17:00:32 +0100 Subject: [PATCH 3/9] Add helper for normalizing timestamps --- lib/stream-chat/channel.rb | 12 +----------- lib/stream-chat/client.rb | 8 ++++---- lib/stream-chat/util.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/stream-chat/channel.rb b/lib/stream-chat/channel.rb index f9552e1..19b2ec1 100644 --- a/lib/stream-chat/channel.rb +++ b/lib/stream-chat/channel.rb @@ -235,17 +235,7 @@ def update_member_partial(user_id, set: nil, unset: nil) sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) } def add_members(user_ids, **options) payload = options.dup - - # Convert hide_history_before timestamp to RFC 3339 format if it's a DateTime or Time object - if payload.key?(:hide_history_before) - hide_history_before = payload[:hide_history_before] - if hide_history_before.is_a?(DateTime) - payload[:hide_history_before] = hide_history_before.rfc3339 - elsif hide_history_before.is_a?(Time) - payload[:hide_history_before] = hide_history_before.iso8601 - end - end - + payload[:hide_history_before] = StreamChat.normalize_timestamp(payload[:hide_history_before]) if payload[:hide_history_before] payload = payload.merge({ add_members: user_ids }) update(nil, nil, **payload) end diff --git a/lib/stream-chat/client.rb b/lib/stream-chat/client.rb index 13a96f1..86291ae 100644 --- a/lib/stream-chat/client.rb +++ b/lib/stream-chat/client.rb @@ -738,7 +738,7 @@ def delete_channels(cids, hard_delete: false) # Revoke tokens for an application issued since the given date. sig { params(before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) } def revoke_tokens(before) - before = before.rfc3339 if before.instance_of?(DateTime) + before = StreamChat.normalize_timestamp(before) update_app_settings({ 'revoke_tokens_issued_before' => before }) end @@ -751,7 +751,7 @@ def revoke_user_token(user_id, before) # Revoke tokens for users issued since. sig { params(user_ids: T::Array[String], before: T.any(DateTime, String)).returns(StreamChat::StreamResponse) } def revoke_users_token(user_ids, before) - before = before.rfc3339 if before.instance_of?(DateTime) + before = StreamChat.normalize_timestamp(before) updates = [] user_ids.map do |user_id| @@ -1024,7 +1024,7 @@ def query_threads(filter, sort: nil, **options) sig { params(message_id: String, user_id: String, remind_at: T.nilable(DateTime)).returns(StreamChat::StreamResponse) } def create_reminder(message_id, user_id, remind_at = nil) data = { user_id: user_id } - data[:remind_at] = remind_at.rfc3339 if remind_at.instance_of?(DateTime) + data[:remind_at] = StreamChat.normalize_timestamp(remind_at) if remind_at post("messages/#{message_id}/reminders", data: data) end @@ -1036,7 +1036,7 @@ def create_reminder(message_id, user_id, remind_at = nil) sig { params(message_id: String, user_id: String, remind_at: T.nilable(DateTime)).returns(StreamChat::StreamResponse) } def update_reminder(message_id, user_id, remind_at = nil) data = { user_id: user_id } - data[:remind_at] = remind_at.rfc3339 if remind_at + data[:remind_at] = StreamChat.normalize_timestamp(remind_at) if remind_at patch("messages/#{message_id}/reminders", data: data) end diff --git a/lib/stream-chat/util.rb b/lib/stream-chat/util.rb index 4b343be..e4cc252 100644 --- a/lib/stream-chat/util.rb +++ b/lib/stream-chat/util.rb @@ -14,4 +14,13 @@ def self.get_sort_fields(sort) end sort_fields end + + # Normalizes a timestamp to RFC 3339 / ISO 8601 string format. + def self.normalize_timestamp(t) + case t + when DateTime then t.rfc3339 + when Time then t.iso8601 + else t + end + end end From 5a5ee5256099289c912819f14168674a31f79783 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 17:02:35 +0100 Subject: [PATCH 4/9] Use hide_history_before in test case --- spec/channel_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/channel_spec.rb b/spec/channel_spec.rb index 0971ef3..0e767ce 100644 --- a/spec/channel_spec.rb +++ b/spec/channel_spec.rb @@ -145,7 +145,8 @@ def loop_times(times) response = @channel.remove_members([@random_users[0][:id], @random_users[1][:id]]) expect(response['members'].length).to eq 0 - @channel.add_members([@random_users[0][:id]]) + history_cutoff = DateTime.now - 1.day + @channel.add_members([@random_users[0][:id]], hide_history_before: history_cutoff) response = @channel.add_members([@random_users[1][:id]], hide_history: true) expect(response['members'].length).to eq 2 response['members']&.each do |m| From df16e5fcdfa6ca77120fa11204f9739b00d02b19 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 17:05:24 +0100 Subject: [PATCH 5/9] Fix error --- spec/channel_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/channel_spec.rb b/spec/channel_spec.rb index 0e767ce..1215c1c 100644 --- a/spec/channel_spec.rb +++ b/spec/channel_spec.rb @@ -145,7 +145,7 @@ def loop_times(times) response = @channel.remove_members([@random_users[0][:id], @random_users[1][:id]]) expect(response['members'].length).to eq 0 - history_cutoff = DateTime.now - 1.day + history_cutoff = DateTime.now - 1 @channel.add_members([@random_users[0][:id]], hide_history_before: history_cutoff) response = @channel.add_members([@random_users[1][:id]], hide_history: true) expect(response['members'].length).to eq 2 From 56b83d54ab177d248f0474ece68a3d8e530f9070 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 17:09:28 +0100 Subject: [PATCH 6/9] Don't use short argument name --- lib/stream-chat/util.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/stream-chat/util.rb b/lib/stream-chat/util.rb index e4cc252..b19c31e 100644 --- a/lib/stream-chat/util.rb +++ b/lib/stream-chat/util.rb @@ -16,11 +16,11 @@ def self.get_sort_fields(sort) end # Normalizes a timestamp to RFC 3339 / ISO 8601 string format. - def self.normalize_timestamp(t) - case t - when DateTime then t.rfc3339 - when Time then t.iso8601 - else t + def self.normalize_timestamp(timestamp) + case timestamp + when DateTime then timestamp.rfc3339 + when Time then timestamp.iso8601 + else timestamp end end end From 9b3fc9f866552d9c9c719e1579bcf08df0968157 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 17:19:43 +0100 Subject: [PATCH 7/9] Add signature --- lib/stream-chat/util.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/stream-chat/util.rb b/lib/stream-chat/util.rb index b19c31e..6a288a7 100644 --- a/lib/stream-chat/util.rb +++ b/lib/stream-chat/util.rb @@ -16,6 +16,7 @@ def self.get_sort_fields(sort) end # Normalizes a timestamp to RFC 3339 / ISO 8601 string format. + sig { params(timestamp: T.anything).returns(T.untyped) } def self.normalize_timestamp(timestamp) case timestamp when DateTime then timestamp.rfc3339 From 79c30d681d854320e40f7b2820aaa4dbfe25981c Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 17:23:38 +0100 Subject: [PATCH 8/9] Use suggested signature --- lib/stream-chat/util.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stream-chat/util.rb b/lib/stream-chat/util.rb index 6a288a7..f3ea90c 100644 --- a/lib/stream-chat/util.rb +++ b/lib/stream-chat/util.rb @@ -16,7 +16,7 @@ def self.get_sort_fields(sort) end # Normalizes a timestamp to RFC 3339 / ISO 8601 string format. - sig { params(timestamp: T.anything).returns(T.untyped) } + sig { params(timestamp: T.any(DateTime, Time, String)).returns(String)} def self.normalize_timestamp(timestamp) case timestamp when DateTime then timestamp.rfc3339 From 00b90623d6b77086f391e18f79b120491c2b0675 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Wed, 5 Nov 2025 17:28:02 +0100 Subject: [PATCH 9/9] Fix lint --- lib/stream-chat/util.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stream-chat/util.rb b/lib/stream-chat/util.rb index f3ea90c..6842384 100644 --- a/lib/stream-chat/util.rb +++ b/lib/stream-chat/util.rb @@ -16,7 +16,7 @@ def self.get_sort_fields(sort) end # Normalizes a timestamp to RFC 3339 / ISO 8601 string format. - sig { params(timestamp: T.any(DateTime, Time, String)).returns(String)} + sig { params(timestamp: T.any(DateTime, Time, String)).returns(String) } def self.normalize_timestamp(timestamp) case timestamp when DateTime then timestamp.rfc3339