Class: StreamChat::Channel
- Inherits:
-
Object
- Object
- StreamChat::Channel
- 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.
Instance Method Summary collapse
- #add_members(user_ids) ⇒ Object
- #add_moderators(user_ids) ⇒ Object
- #ban_user(user_id, **options) ⇒ Object
- #create(user_id) ⇒ Object
- #delete ⇒ Object
- #delete_reaction(message_id, reaction_type, user_id) ⇒ Object
- #demote_moderators(user_ids) ⇒ Object
- #get_reactions(message_id, **options) ⇒ Object
- #get_replies(parent_id, **options) ⇒ Object
-
#initialize(client, channel_type, channel_id = nil, custom_data = nil) ⇒ Channel
constructor
A new instance of Channel.
- #mark_read(user_id, **options) ⇒ Object
- #query(**options) ⇒ Object
- #remove_members(user_ids) ⇒ Object
- #send_event(event, user_id) ⇒ Object
- #send_message(message, user_id) ⇒ Object
- #send_reaction(message_id, reaction, user_id) ⇒ Object
- #truncate ⇒ Object
- #unban_user(user_id) ⇒ Object
- #update(channel_data, update_message = nil) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(client, channel_type, channel_id = nil, custom_data = nil) ⇒ Channel
Returns a new instance of Channel.
10 11 12 13 14 15 16 17 18 |
# File 'lib/stream-chat/channel.rb', line 10 def initialize(client, channel_type, channel_id=nil, custom_data=nil) @channel_type = channel_type @id = channel_id @client = client @custom_data = custom_data if @custom_data == nil @custom_data = {} end end |
Instance Attribute Details
#channel_type ⇒ Object (readonly)
Returns the value of attribute channel_type.
7 8 9 |
# File 'lib/stream-chat/channel.rb', line 7 def channel_type @channel_type end |
#custom_data ⇒ Object (readonly)
Returns the value of attribute custom_data.
8 9 10 |
# File 'lib/stream-chat/channel.rb', line 8 def custom_data @custom_data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/stream-chat/channel.rb', line 6 def id @id end |
Instance Method Details
#add_members(user_ids) ⇒ Object
81 82 83 |
# File 'lib/stream-chat/channel.rb', line 81 def add_members(user_ids) @client.post(url, data: {"add_members": user_ids}) end |
#add_moderators(user_ids) ⇒ Object
85 86 87 |
# File 'lib/stream-chat/channel.rb', line 85 def add_moderators(user_ids) @client.post(url, data: {"add_moderators": user_ids}) end |
#ban_user(user_id, **options) ⇒ Object
110 111 112 |
# File 'lib/stream-chat/channel.rb', line 110 def ban_user(user_id, **) @client.ban_user(user_id, type: @channel_type, id: @id, **) end |
#create(user_id) ⇒ Object
49 50 51 52 |
# File 'lib/stream-chat/channel.rb', line 49 def create(user_id) @custom_data["created_by"] = {"id": user_id} query(watch: false, state: false, presence: false) end |
#delete ⇒ Object
73 74 75 |
# File 'lib/stream-chat/channel.rb', line 73 def delete @client.delete(url) end |
#delete_reaction(message_id, reaction_type, user_id) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/stream-chat/channel.rb', line 42 def delete_reaction(, reaction_type, user_id) @client.delete( "messages/#{message_id}/reaction/#{reaction_type}", params: {"user_id": user_id} ) end |
#demote_moderators(user_ids) ⇒ Object
93 94 95 |
# File 'lib/stream-chat/channel.rb', line 93 def demote_moderators(user_ids) @client.post(url, data: {"demote_moderators": user_ids}) end |
#get_reactions(message_id, **options) ⇒ Object
106 107 108 |
# File 'lib/stream-chat/channel.rb', line 106 def get_reactions(, **) @client.get("messages/#{message_id}/reactions", params: ) end |
#get_replies(parent_id, **options) ⇒ Object
102 103 104 |
# File 'lib/stream-chat/channel.rb', line 102 def get_replies(parent_id, **) @client.get("messages/#{parent_id}/replies", params: ) end |
#mark_read(user_id, **options) ⇒ Object
97 98 99 100 |
# File 'lib/stream-chat/channel.rb', line 97 def mark_read(user_id, **) payload = add_user_id(, user_id) @client.post("#{url}/read", data: payload) end |
#query(**options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/stream-chat/channel.rb', line 54 def query(**) payload = {"state": true, "data": @custom_data}.merge() url = "channels/#{@channel_type}" if @id != nil url = "#{url}/#{@id}" end state = @client.post("#{url}/query", data: payload) if @id == nil @id = state["channel"]["id"] end state end |
#remove_members(user_ids) ⇒ Object
89 90 91 |
# File 'lib/stream-chat/channel.rb', line 89 def remove_members(user_ids) @client.post(url, data: {"remove_members": user_ids}) end |
#send_event(event, user_id) ⇒ Object
32 33 34 35 |
# File 'lib/stream-chat/channel.rb', line 32 def send_event(event, user_id) payload = {'event' => add_user_id(event, user_id)} @client.post("#{url}/event", data: payload) end |
#send_message(message, user_id) ⇒ Object
27 28 29 30 |
# File 'lib/stream-chat/channel.rb', line 27 def (, user_id) payload = {"message": add_user_id(, user_id)} @client.post("#{url}/message", data: payload) end |
#send_reaction(message_id, reaction, user_id) ⇒ Object
37 38 39 40 |
# File 'lib/stream-chat/channel.rb', line 37 def send_reaction(, reaction, user_id) payload = {"reaction": add_user_id(reaction, user_id)} @client.post("messages/#{message_id}/reaction", data: payload) end |
#truncate ⇒ Object
77 78 79 |
# File 'lib/stream-chat/channel.rb', line 77 def truncate @client.post("#{url}/truncate") end |
#unban_user(user_id) ⇒ Object
114 115 116 |
# File 'lib/stream-chat/channel.rb', line 114 def unban_user(user_id) @client.unban_user(user_id, type: @channel_type, id: @id) end |
#update(channel_data, update_message = nil) ⇒ Object
68 69 70 71 |
# File 'lib/stream-chat/channel.rb', line 68 def update(channel_data, =nil) payload = {"data": channel_data, "message": } @client.post(url, data: payload) end |
#url ⇒ Object
20 21 22 23 24 25 |
# File 'lib/stream-chat/channel.rb', line 20 def url if @id == nil raise StreamChannelException "channel does not have an id" end "channels/#{@channel_type}/#{@id}" end |