Skip to content

Commit f24c1bd

Browse files
Merge branch 'master' into feature/cha-665_team_based_roles
2 parents 498330f + 62ea5a4 commit f24c1bd

File tree

6 files changed

+193
-1
lines changed

6 files changed

+193
-1
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [3.13.0](https://github.com/GetStream/stream-chat-ruby/compare/v3.12.0...v3.13.0) (2025-04-04)
6+
7+
8+
### Features
9+
10+
* deactivate users ([#162](https://github.com/GetStream/stream-chat-ruby/issues/162)) ([12bf4d1](https://github.com/GetStream/stream-chat-ruby/commit/12bf4d19846b5100f1886929b74c7ad05d753be4))
11+
* draft messages ([#161](https://github.com/GetStream/stream-chat-ruby/pull/161)) ([1719104](https://github.com/GetStream/stream-chat-ruby/commit/c7bccb3ad30721a20f32fd60eb13ab6d97a08208))
12+
13+
### Other
14+
15+
* added nijeesh to code owners ([#156](https://github.com/GetStream/stream-chat-ruby/issues/156)) ([7cd4e54](https://github.com/GetStream/stream-chat-ruby/commit/7cd4e5443a8f283596b8eadc873030d737cd621c))
16+
* **release:** v3.12.0 ([#157](https://github.com/GetStream/stream-chat-ruby/issues/157)) ([993b7a3](https://github.com/GetStream/stream-chat-ruby/commit/993b7a30bd2222ee328ca7a862384c7baf7d53e1))
17+
518
## [3.11.0](https://github.com/GetStream/stream-chat-ruby/compare/v3.9.0...v3.11.0) (2025-03-21)
619

720

lib/stream-chat/channel.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,41 @@ def delete_image(url)
360360
@client.delete("#{self.url}/image", params: { url: url })
361361
end
362362

363+
# Creates or updates a draft message for this channel.
364+
#
365+
# @param [StringKeyHash] message The draft message content
366+
# @param [String] user_id The ID of the user creating/updating the draft
367+
# @return [StreamChat::StreamResponse]
368+
sig { params(message: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
369+
def create_draft(message, user_id)
370+
payload = { message: add_user_id(message, user_id) }
371+
@client.post("#{url}/draft", data: payload)
372+
end
373+
374+
# Deletes a draft message for this channel.
375+
#
376+
# @param [String] user_id The ID of the user deleting the draft
377+
# @param [String] parent_id Optional parent message ID for thread drafts
378+
# @return [StreamChat::StreamResponse]
379+
sig { params(user_id: String, parent_id: T.nilable(String)).returns(StreamChat::StreamResponse) }
380+
def delete_draft(user_id, parent_id: nil)
381+
params = { user_id: user_id }
382+
params[:parent_id] = parent_id if parent_id
383+
@client.delete("#{url}/draft", params: params)
384+
end
385+
386+
# Gets a draft message for this channel.
387+
#
388+
# @param [String] user_id The ID of the user getting the draft
389+
# @param [String] parent_id Optional parent message ID for thread drafts
390+
# @return [StreamChat::StreamResponse]
391+
sig { params(user_id: String, parent_id: T.nilable(String)).returns(StreamChat::StreamResponse) }
392+
def get_draft(user_id, parent_id: nil)
393+
params = { user_id: user_id }
394+
params[:parent_id] = parent_id if parent_id
395+
@client.get("#{url}/draft", params: params)
396+
end
397+
363398
private
364399

365400
sig { params(payload: StringKeyHash, user_id: String).returns(StringKeyHash) }

lib/stream-chat/client.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ def deactivate_user(user_id, **options)
280280
post("users/#{user_id}/deactivate", params: options)
281281
end
282282

283+
# Deactivates a users
284+
sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
285+
def deactivate_users(user_ids, **options)
286+
raise ArgumentError, 'user_ids should not be empty' if user_ids.empty?
287+
288+
post('users/deactivate', data: { user_ids: user_ids, **options })
289+
end
290+
283291
# Reactivates a deactivated user. Use deactivate_user to deactivate a user.
284292
sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
285293
def reactivate_user(user_id, **options)
@@ -783,6 +791,22 @@ def create_command(command)
783791
post('commands', data: command)
784792
end
785793

794+
# Queries draft messages for the current user.
795+
#
796+
# @param [String] user_id The ID of the user to query drafts for
797+
# @param [StringKeyHash] filter Optional filter conditions for the query
798+
# @param [Array] sort Optional sort parameters
799+
# @param [Hash] options Additional query options
800+
# @return [StreamChat::StreamResponse]
801+
sig { params(user_id: String, filter: T.nilable(StringKeyHash), sort: T.nilable(T::Array[StringKeyHash]), options: T.untyped).returns(StreamChat::StreamResponse) }
802+
def query_drafts(user_id, filter: nil, sort: nil, **options)
803+
data = { user_id: user_id }
804+
data['filter'] = filter if filter
805+
data['sort'] = sort if sort
806+
data.merge!(options) if options
807+
post('drafts/query', data: data)
808+
end
809+
786810
# Gets a comamnd.
787811
sig { params(name: String).returns(StreamChat::StreamResponse) }
788812
def get_command(name)

lib/stream-chat/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# frozen_string_literal: true
33

44
module StreamChat
5-
VERSION = '3.12.0'
5+
VERSION = '3.13.0'
66
end

spec/channel_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,65 @@ def loop_times(times)
430430
# Verify the custom field was unset
431431
expect(updated_msg['message']).not_to include 'custom_field'
432432
end
433+
434+
it 'can create draft message' do
435+
draft_message = { 'text' => 'This is a draft message' }
436+
response = @channel.create_draft(draft_message, @random_user[:id])
437+
438+
expect(response).to include 'draft'
439+
expect(response['draft']['message']['text']).to eq 'This is a draft message'
440+
expect(response['draft']['channel_cid']).to eq @channel.cid
441+
end
442+
443+
it 'can get draft message' do
444+
# First create a draft
445+
draft_message = { 'text' => 'This is a draft to retrieve' }
446+
@channel.create_draft(draft_message, @random_user[:id])
447+
448+
# Then get the draft
449+
response = @channel.get_draft(@random_user[:id])
450+
451+
expect(response).to include 'draft'
452+
expect(response['draft']['message']['text']).to eq 'This is a draft to retrieve'
453+
expect(response['draft']['channel_cid']).to eq @channel.cid
454+
end
455+
456+
it 'can delete draft message' do
457+
# First create a draft
458+
draft_message = { 'text' => 'This is a draft to delete' }
459+
@channel.create_draft(draft_message, @random_user[:id])
460+
461+
# Then delete the draft
462+
@channel.delete_draft(@random_user[:id])
463+
464+
# Verify it's deleted by trying to get it
465+
expect { @channel.get_draft(@random_user[:id]) }.to raise_error(StreamChat::StreamAPIException)
466+
end
467+
468+
it 'can create and manage thread draft' do
469+
# First create a parent message
470+
msg = @channel.send_message({ 'text' => 'Parent message' }, @random_user[:id])
471+
parent_id = msg['message']['id']
472+
473+
# Create a draft reply
474+
draft_reply = { 'text' => 'This is a draft reply', 'parent_id' => parent_id }
475+
response = @channel.create_draft(draft_reply, @random_user[:id])
476+
477+
expect(response).to include 'draft'
478+
expect(response['draft']['message']['text']).to eq 'This is a draft reply'
479+
expect(response['draft']['parent_id']).to eq parent_id
480+
481+
# Get the draft reply
482+
response = @channel.get_draft(@random_user[:id], parent_id: parent_id)
483+
484+
expect(response).to include 'draft'
485+
expect(response['draft']['message']['text']).to eq 'This is a draft reply'
486+
expect(response['draft']['parent_id']).to eq parent_id
487+
488+
# Delete the draft reply
489+
@channel.delete_draft(@random_user[:id], parent_id: parent_id)
490+
491+
# Verify it's deleted
492+
expect { @channel.get_draft(@random_user[:id], parent_id: parent_id) }.to raise_error(StreamChat::StreamAPIException)
493+
end
433494
end

spec/client_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ def loop_times(times)
198198
expect(response['user']['id']).to eq(@random_user[:id])
199199
end
200200

201+
it 'deactivates multiple users' do
202+
response = @client.deactivate_users([@random_users[0][:id], @random_users[1][:id]])
203+
expect(response).to include 'task_id'
204+
expect(response['task_id']).not_to be_empty
205+
end
206+
207+
it 'raises an error if user_ids is not an array' do
208+
expect { @client.deactivate_users('not an array') }.to raise_error(TypeError)
209+
end
210+
211+
it 'raises an error if user_ids is empty' do
212+
expect { @client.deactivate_users([]) }.to raise_error(ArgumentError)
213+
end
214+
201215
it 'reactivates a user' do
202216
@client.deactivate_user(@random_user[:id])
203217
response = @client.reactivate_user(@random_user[:id])
@@ -811,6 +825,51 @@ def loop_times(times)
811825
list_resp = @client.list_imports({ limit: 1 })
812826
expect(list_resp['import_tasks'].length).to eq 1
813827
end
828+
829+
it 'can query drafts' do
830+
# Create multiple drafts in different channels
831+
draft1 = { 'text' => 'Draft in channel 1' }
832+
@channel.create_draft(draft1, @random_user[:id])
833+
834+
# Create another channel with a draft
835+
channel2 = @client.channel('messaging', data: { 'members' => @random_users.map { |u| u[:id] } })
836+
channel2.create(@random_user[:id])
837+
838+
draft2 = { 'text' => 'Draft in channel 2' }
839+
channel2.create_draft(draft2, @random_user[:id])
840+
841+
# Sort by created_at
842+
sort = [{ 'field' => 'created_at', 'direction' => 1 }]
843+
response = @client.query_drafts(@random_user[:id], sort: sort)
844+
expect(response['drafts']).not_to be_empty
845+
expect(response['drafts'].length).to eq(2)
846+
expect(response['drafts'][0]['channel']['id']).to eq(@channel.id)
847+
expect(response['drafts'][1]['channel']['id']).to eq(channel2.id)
848+
849+
# Query for a specific channel
850+
response = @client.query_drafts(@random_user[:id], filter: { 'channel_cid' => @channel.cid })
851+
expect(response['drafts']).not_to be_empty
852+
expect(response['drafts'].length).to eq(1)
853+
expect(response['drafts'][0]['channel']['id']).to eq(@channel.id)
854+
855+
# Query all drafts for the user
856+
response = @client.query_drafts(@random_user[:id])
857+
expect(response['drafts']).not_to be_empty
858+
expect(response['drafts'].length).to eq(2)
859+
860+
# Paginate
861+
response = @client.query_drafts(@random_user[:id], sort: sort, limit: 1)
862+
expect(response['drafts']).not_to be_empty
863+
expect(response['drafts'].length).to eq(1)
864+
expect(response['drafts'][0]['channel']['id']).to eq(@channel.id)
865+
866+
# Cleanup
867+
begin
868+
channel2.delete
869+
rescue StandardError
870+
# Ignore errors if channel is already deleted
871+
end
872+
end
814873
end
815874

816875
describe 'permissions' do

0 commit comments

Comments
 (0)