Skip to content

Commit 6ec3816

Browse files
committed
Make call query threads directly
1 parent c5a0491 commit 6ec3816

File tree

4 files changed

+91
-164
lines changed

4 files changed

+91
-164
lines changed

lib/stream-chat/client.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
require 'stream-chat/util'
1616
require 'stream-chat/types'
1717
require 'stream-chat/moderation'
18-
require 'stream-chat/thread'
1918

2019
module StreamChat
2120
DEFAULT_BLOCKLIST = 'profanity_en_2020_v1'
@@ -40,9 +39,6 @@ class Client
4039
sig { returns(Moderation) }
4140
attr_reader :moderation
4241

43-
sig { returns(Thread) }
44-
attr_reader :thread
45-
4642
# initializes a Stream Chat API Client
4743
#
4844
# @param [string] api_key your application api_key
@@ -73,7 +69,6 @@ def initialize(api_key, api_secret, timeout = nil, **options)
7369
end
7470
@conn = T.let(conn, Faraday::Connection)
7571
@moderation = T.let(Moderation.new(self), Moderation)
76-
@thread = T.let(Thread.new(self), Thread)
7772
end
7873

7974
# initializes a Stream Chat API Client from STREAM_KEY and STREAM_SECRET
@@ -935,8 +930,13 @@ def list_imports(options)
935930
end
936931

937932
sig { params(filter: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
938-
def query_threads(filter, sort, **options)
939-
@thread.query_threads(filter, sort: sort, **options)
933+
def query_threads(filter, sort: nil, **options)
934+
params = {}.merge(options).merge({
935+
filter: filter,
936+
sort: StreamChat.get_sort_fields(sort)
937+
})
938+
939+
post('threads', data: params)
940940
end
941941

942942
private

lib/stream-chat/thread.rb

Lines changed: 0 additions & 41 deletions
This file was deleted.

spec/client_spec.rb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,4 +966,88 @@ def loop_times(times)
966966
end
967967
end
968968
end
969+
970+
describe '#query_threads' do
971+
it 'queries threads with filter' do
972+
# Create a channel and send a message to create a thread
973+
channel = @client.channel('messaging', channel_id: SecureRandom.uuid, data: { test: true })
974+
channel.create(@random_user[:id])
975+
976+
# Send a message to create a thread
977+
message = channel.send_message({ text: 'Thread parent message' }, @random_user[:id])
978+
979+
# Send a reply to create a thread
980+
channel.send_message({ text: 'Thread reply', parent_id: message['message']['id'] }, @random_user[:id])
981+
982+
# Query threads with filter
983+
filter = {
984+
'created_by_user_id' => { '$eq' => @random_user[:id] }
985+
}
986+
987+
response = @client.query_threads(filter, user_id: @random_user[:id])
988+
989+
# Verify the response
990+
expect(response).to include 'threads'
991+
expect(response['threads'].length).to be >= 1
992+
993+
# Clean up
994+
channel.delete
995+
end
996+
997+
it 'queries threads with sort' do
998+
# Create a channel and send a message to create a thread
999+
channel = @client.channel('messaging', channel_id: SecureRandom.uuid, data: { test: true })
1000+
channel.create(@random_user[:id])
1001+
1002+
# Send a message to create a thread
1003+
message = channel.send_message({ text: 'Thread parent message' }, @random_user[:id])
1004+
1005+
# Send a reply to create a thread
1006+
channel.send_message({ text: 'Thread reply', parent_id: message['message']['id'] }, @random_user[:id])
1007+
1008+
# Query threads with sort
1009+
sort = {
1010+
'created_at' => -1
1011+
}
1012+
1013+
response = @client.query_threads(sort: sort, user_id: @random_user[:id])
1014+
1015+
# Verify the response
1016+
expect(response).to include 'threads'
1017+
expect(response['threads'].length).to be >= 1
1018+
1019+
# Clean up
1020+
channel.delete
1021+
end
1022+
1023+
it 'queries threads with both filter and sort' do
1024+
# Create a channel and send a message to create a thread
1025+
channel = @client.channel('messaging', channel_id: SecureRandom.uuid, data: { test: true })
1026+
channel.create(@random_user[:id])
1027+
1028+
# Send a message to create a thread
1029+
message = channel.send_message({ text: 'Thread parent message' }, @random_user[:id])
1030+
1031+
# Send a reply to create a thread
1032+
channel.send_message({ text: 'Thread reply', parent_id: message['message']['id'] }, @random_user[:id])
1033+
1034+
# Query threads with both filter and sort
1035+
filter = {
1036+
'created_by_user_id' => { '$eq' => @random_user[:id] }
1037+
}
1038+
1039+
sort = {
1040+
'created_at' => -1
1041+
}
1042+
1043+
response = @client.query_threads(filter, sort: sort, user_id: @random_user[:id])
1044+
1045+
# Verify the response
1046+
expect(response).to include 'threads'
1047+
expect(response['threads'].length).to be >= 1
1048+
1049+
# Clean up
1050+
channel.delete
1051+
end
1052+
end
9691053
end

spec/thread_spec.rb

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)