Class: StreamChat::Channel
- Inherits:
-
Object
- Object
- StreamChat::Channel
- Extended by:
- T::Sig
- Defined in:
- lib/stream-chat/channel.rb
Instance Attribute Summary collapse
-
#channel_type ⇒ Object
readonly
Returns the value of attribute channel_type.
-
#custom_data ⇒ Object
readonly
Returns the value of attribute custom_data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #accept_invite(user_id, **options) ⇒ Object
- #add_members(user_ids, **options) ⇒ Object
- #add_moderators(user_ids) ⇒ Object
- #assign_roles(members, message = nil) ⇒ Object
- #ban_user(user_id, **options) ⇒ Object
- #create(user_id) ⇒ Object
- #delete ⇒ Object
- #delete_file(url) ⇒ Object
- #delete_image(url) ⇒ Object
- #delete_reaction(message_id, reaction_type, user_id) ⇒ Object
- #demote_moderators(user_ids) ⇒ Object
- #get_messages(message_ids) ⇒ Object
- #get_reactions(message_id, **options) ⇒ Object
- #get_replies(parent_id, **options) ⇒ Object
- #hide(user_id) ⇒ Object
-
#initialize(client, channel_type, channel_id = nil, custom_data = nil) ⇒ Channel
constructor
A new instance of Channel.
- #invite_members(user_ids, **options) ⇒ Object
- #mark_read(user_id, **options) ⇒ Object
- #mute(user_id, expiration = nil) ⇒ Object
- #query(**options) ⇒ Object
- #query_members(filter_conditions = {}, sort: nil, **options) ⇒ Object
- #reject_invite(user_id, **options) ⇒ Object
- #remove_members(user_ids) ⇒ Object
- #send_event(event, user_id) ⇒ Object
- #send_file(url, user, content_type = nil) ⇒ Object
- #send_image(url, user, content_type = nil) ⇒ Object
- #send_message(message, user_id, **options) ⇒ Object
- #send_reaction(message_id, reaction, user_id) ⇒ Object
- #show(user_id) ⇒ Object
- #truncate(**options) ⇒ Object
- #unban_user(user_id) ⇒ Object
- #unmute(user_id) ⇒ Object
- #update(channel_data, update_message = nil, **options) ⇒ Object
- #update_partial(set = nil, unset = nil) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(client, channel_type, channel_id = nil, custom_data = nil) ⇒ Channel
Returns a new instance of Channel.
26 27 28 29 30 31 32 33 |
# File 'lib/stream-chat/channel.rb', line 26 def initialize(client, channel_type, channel_id = nil, custom_data = nil) @channel_type = channel_type @id = channel_id @cid = T.let("#{@channel_type}:#{@id}", String) @client = client @custom_data = T.let(custom_data || {}, StringKeyHash) @members = T.let([], T::Array[StringKeyHash]) end |
Instance Attribute Details
#channel_type ⇒ Object (readonly)
Returns the value of attribute channel_type.
17 18 19 |
# File 'lib/stream-chat/channel.rb', line 17 def channel_type @channel_type end |
#custom_data ⇒ Object (readonly)
Returns the value of attribute custom_data.
20 21 22 |
# File 'lib/stream-chat/channel.rb', line 20 def custom_data @custom_data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/stream-chat/channel.rb', line 14 def id @id end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
23 24 25 |
# File 'lib/stream-chat/channel.rb', line 23 def members @members end |
Instance Method Details
#accept_invite(user_id, **options) ⇒ Object
185 186 187 188 |
# File 'lib/stream-chat/channel.rb', line 185 def accept_invite(user_id, **) payload = .merge({ user_id: user_id, accept_invite: true }) update(nil, nil, **payload) end |
#add_members(user_ids, **options) ⇒ Object
171 172 173 174 |
# File 'lib/stream-chat/channel.rb', line 171 def add_members(user_ids, **) payload = .merge({ add_members: user_ids }) update(nil, nil, **payload) end |
#add_moderators(user_ids) ⇒ Object
199 200 201 |
# File 'lib/stream-chat/channel.rb', line 199 def add_moderators(user_ids) update(nil, nil, add_moderators: user_ids) end |
#assign_roles(members, message = nil) ⇒ Object
211 212 213 |
# File 'lib/stream-chat/channel.rb', line 211 def assign_roles(members, = nil) update(nil, , assign_roles: members) end |
#ban_user(user_id, **options) ⇒ Object
242 243 244 |
# File 'lib/stream-chat/channel.rb', line 242 def ban_user(user_id, **) @client.ban_user(user_id, type: @channel_type, id: @id, **) end |
#create(user_id) ⇒ Object
80 81 82 83 |
# File 'lib/stream-chat/channel.rb', line 80 def create(user_id) @custom_data['created_by'] = { id: user_id } query(watch: false, state: false, presence: false) end |
#delete ⇒ Object
140 141 142 |
# File 'lib/stream-chat/channel.rb', line 140 def delete @client.delete(url) end |
#delete_file(url) ⇒ Object
288 289 290 |
# File 'lib/stream-chat/channel.rb', line 288 def delete_file(url) @client.delete("#{self.url}/file", params: { url: url }) end |
#delete_image(url) ⇒ Object
294 295 296 |
# File 'lib/stream-chat/channel.rb', line 294 def delete_image(url) @client.delete("#{self.url}/image", params: { url: url }) end |
#delete_reaction(message_id, reaction_type, user_id) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/stream-chat/channel.rb', line 71 def delete_reaction(, reaction_type, user_id) @client.delete( "messages/#{}/reaction/#{reaction_type}", params: { user_id: user_id } ) end |
#demote_moderators(user_ids) ⇒ Object
217 218 219 |
# File 'lib/stream-chat/channel.rb', line 217 def demote_moderators(user_ids) update(nil, nil, demote_moderators: user_ids) end |
#get_messages(message_ids) ⇒ Object
44 45 46 |
# File 'lib/stream-chat/channel.rb', line 44 def () @client.get("#{url}/messages", params: { 'ids' => .join(',') }) end |
#get_reactions(message_id, **options) ⇒ Object
236 237 238 |
# File 'lib/stream-chat/channel.rb', line 236 def get_reactions(, **) @client.get("messages/#{}/reactions", params: ) end |
#get_replies(parent_id, **options) ⇒ Object
230 231 232 |
# File 'lib/stream-chat/channel.rb', line 230 def get_replies(parent_id, **) @client.get("messages/#{parent_id}/replies", params: ) end |
#hide(user_id) ⇒ Object
255 256 257 |
# File 'lib/stream-chat/channel.rb', line 255 def hide(user_id) @client.post("#{url}/hide", data: { user_id: user_id }) end |
#invite_members(user_ids, **options) ⇒ Object
178 179 180 181 |
# File 'lib/stream-chat/channel.rb', line 178 def invite_members(user_ids, **) payload = .merge({ invites: user_ids }) update(nil, nil, **payload) end |
#mark_read(user_id, **options) ⇒ Object
223 224 225 226 |
# File 'lib/stream-chat/channel.rb', line 223 def mark_read(user_id, **) payload = add_user_id(, user_id) @client.post("#{url}/read", data: payload) end |
#mute(user_id, expiration = nil) ⇒ Object
157 158 159 160 161 |
# File 'lib/stream-chat/channel.rb', line 157 def mute(user_id, expiration = nil) data = { user_id: user_id, channel_cid: @cid } data['expiration'] = expiration if expiration @client.post('moderation/mute/channel', data: data) end |
#query(**options) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/stream-chat/channel.rb', line 87 def query(**) payload = { state: true, data: @custom_data }.merge() url = "channels/#{@channel_type}" url = "#{url}/#{@id}" unless @id.nil? state = @client.post("#{url}/query", data: payload) @id = state['channel']['id'] if @id.nil? state end |
#query_members(filter_conditions = {}, sort: nil, **options) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/stream-chat/channel.rb', line 104 def query_members(filter_conditions = {}, sort: nil, **) params = {}.merge().merge({ id: @id, type: @channel_type, filter_conditions: filter_conditions, sort: StreamChat.get_sort_fields(sort) }) if @id == '' && @members.length.positive? params['members'] = [] @members.each do |m| params['members'] << m['user'].nil? ? m['user_id'] : m['user']['id'] end end @client.get('members', params: { payload: params.to_json }) end |
#reject_invite(user_id, **options) ⇒ Object
192 193 194 195 |
# File 'lib/stream-chat/channel.rb', line 192 def reject_invite(user_id, **) payload = .merge({ user_id: user_id, reject_invite: true }) update(nil, nil, **payload) end |
#remove_members(user_ids) ⇒ Object
205 206 207 |
# File 'lib/stream-chat/channel.rb', line 205 def remove_members(user_ids) update(nil, nil, remove_members: user_ids) end |
#send_event(event, user_id) ⇒ Object
57 58 59 60 |
# File 'lib/stream-chat/channel.rb', line 57 def send_event(event, user_id) payload = { 'event' => add_user_id(event, user_id) } @client.post("#{url}/event", data: payload) end |
#send_file(url, user, content_type = nil) ⇒ Object
271 272 273 |
# File 'lib/stream-chat/channel.rb', line 271 def send_file(url, user, content_type = nil) @client.send_file("#{self.url}/file", url, user, content_type) end |
#send_image(url, user, content_type = nil) ⇒ Object
282 283 284 |
# File 'lib/stream-chat/channel.rb', line 282 def send_image(url, user, content_type = nil) @client.send_file("#{self.url}/image", url, user, content_type) end |
#send_message(message, user_id, **options) ⇒ Object
50 51 52 53 |
# File 'lib/stream-chat/channel.rb', line 50 def (, user_id, **) payload = .merge({ message: add_user_id(, user_id) }) @client.post("#{url}/message", data: payload) end |
#send_reaction(message_id, reaction, user_id) ⇒ Object
64 65 66 67 |
# File 'lib/stream-chat/channel.rb', line 64 def send_reaction(, reaction, user_id) payload = { reaction: add_user_id(reaction, user_id) } @client.post("messages/#{}/reaction", data: payload) end |
#show(user_id) ⇒ Object
262 263 264 |
# File 'lib/stream-chat/channel.rb', line 262 def show(user_id) @client.post("#{url}/show", data: { user_id: user_id }) end |
#truncate(**options) ⇒ Object
146 147 148 |
# File 'lib/stream-chat/channel.rb', line 146 def truncate(**) @client.post("#{url}/truncate", data: ) end |
#unban_user(user_id) ⇒ Object
248 249 250 |
# File 'lib/stream-chat/channel.rb', line 248 def unban_user(user_id) @client.unban_user(user_id, type: @channel_type, id: @id) end |
#unmute(user_id) ⇒ Object
165 166 167 |
# File 'lib/stream-chat/channel.rb', line 165 def unmute(user_id) @client.post('moderation/unmute/channel', data: { 'user_id' => user_id, 'channel_cid' => @cid }) end |
#update(channel_data, update_message = nil, **options) ⇒ Object
124 125 126 127 |
# File 'lib/stream-chat/channel.rb', line 124 def update(channel_data, = nil, **) payload = { data: channel_data, message: }.merge() @client.post(url, data: payload) end |
#update_partial(set = nil, unset = nil) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/stream-chat/channel.rb', line 131 def update_partial(set = nil, unset = nil) raise StreamChannelException, 'set or unset is needed' if set.nil? && unset.nil? payload = { set: set, unset: unset } @client.patch(url, data: payload) end |
#url ⇒ Object
36 37 38 39 40 |
# File 'lib/stream-chat/channel.rb', line 36 def url raise StreamChannelException, 'channel does not have an id' if @id.nil? "channels/#{@channel_type}/#{@id}" end |