Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/stream-chat/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,16 @@ def list_imports(options)
get('imports', params: options)
end

sig { params(filter: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
def query_threads(filter, sort: nil, **options)
params = {}.merge(options).merge({
filter: filter,
sort: StreamChat.get_sort_fields(sort)
})

post('threads', data: params)
end

private

sig { returns(T::Hash[String, String]) }
Expand Down
64 changes: 62 additions & 2 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ def loop_times(times)
response = @client.update_user_partial({
id: user_id,
set: {
team: 'blue',
teams: ['blue'],
teams_role: { 'blue' => 'admin' }
}
})

expect(response['users'][user_id]['team']).to eq('blue')
expect(response['users'][user_id]['teams']).to eq(['blue'])
expect(response['users'][user_id]['teams_role']['blue']).to eq('admin')
end

Expand Down Expand Up @@ -960,4 +960,64 @@ def loop_times(times)
end
end
end

describe '#query_threads' do
before(:all) do
# Create a dedicated random user for this block
@thread_test_user = { id: SecureRandom.uuid }
@client.upsert_users([@thread_test_user])

# Create a channel and send a message to create a thread
@thread_channel = @client.channel('messaging', channel_id: SecureRandom.uuid, data: { test: true })
@thread_channel.create(@thread_test_user[:id])

# Send a message to create a thread
@thread_message = @thread_channel.send_message({ text: 'Thread parent message' }, @thread_test_user[:id])

# Send a reply to create a thread
@thread_channel.send_message({ text: 'Thread reply', parent_id: @thread_message['message']['id'] }, @thread_test_user[:id])
end

after(:all) do
@thread_channel.delete
@client.delete_user(@thread_test_user[:id])
end

it 'queries threads with filter' do
filter = {
'created_by_user_id' => { '$eq' => @thread_test_user[:id] }
}

response = @client.query_threads(filter, user_id: @thread_test_user[:id])

expect(response).to include 'threads'
expect(response['threads'].length).to be >= 1
end

it 'queries threads with sort' do
sort = {
'created_at' => -1
}

response = @client.query_threads({}, sort: sort, user_id: @thread_test_user[:id])

expect(response).to include 'threads'
expect(response['threads'].length).to be >= 1
end

it 'queries threads with both filter and sort' do
filter = {
'created_by_user_id' => { '$eq' => @thread_test_user[:id] }
}

sort = {
'created_at' => -1
}

response = @client.query_threads(filter, sort: sort, user_id: @thread_test_user[:id])

expect(response).to include 'threads'
expect(response['threads'].length).to be >= 1
end
end
end