Class: SelfSDK::Chat::Message
- Inherits:
-
Object
- Object
- SelfSDK::Chat::Message
- Defined in:
- lib/chat/message.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#cid ⇒ Object
Returns the value of attribute cid.
-
#from ⇒ Object
Returns the value of attribute from.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#rid ⇒ Object
Returns the value of attribute rid.
Instance Method Summary collapse
-
#delete! ⇒ Object
delete! deletes the current message from the conversation.
-
#edit(body) ⇒ Object
edit changes the current message body for all participants.
-
#initialize(chat, recipients, payload, auth_token, self_url) ⇒ Message
constructor
A new instance of Message.
-
#mark_as_delivered ⇒ Object
mark_as_delivered marks the current message as delivered if it comes from another recipient.
-
#mark_as_read ⇒ Object
mark_as_read marks the current message as read if it comes from another recipient.
-
#message(body, opts = {}) ⇒ Object
message sends a new message to the same conversation as the current message.
-
#respond(body, opts = {}) ⇒ Object
respond sends a direct response to the current message.
Constructor Details
#initialize(chat, recipients, payload, auth_token, self_url) ⇒ Message
Returns a new instance of Message.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/chat/message.rb', line 10 def initialize(chat, recipients, payload, auth_token, self_url) @chat = chat @recipients = recipients @recipients = [@recipients] if @recipients.is_a? String @gid = payload[:gid] if payload.key? :gid @rid = payload[:rid] if payload.key? :rid @cid = payload[:cid] if payload.key? :cid @payload = payload @payload[:jti] = SecureRandom.uuid unless @payload.include?(:jti) @body = @payload[:msg] @from = @payload[:iss] return unless @payload.key?(:objects) @objects = [] @payload[:objects].each do |o| @objects << if o.key? :link SelfSDK::Chat::FileObject.new(auth_token, self_url).build_from_object(o) else SelfSDK::Chat::FileObject.new(auth_token, self_url).build_from_data(o[:name], o[:data], o[:mime]) end end @payload[:objects] = [] @payload[:objects] = payload[:raw_objects] if payload[:raw_objects] @objects.each do |o| @payload[:objects] << o.to_payload end end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def body @body end |
#cid ⇒ Object
Returns the value of attribute cid.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def cid @cid end |
#from ⇒ Object
Returns the value of attribute from.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def from @from end |
#gid ⇒ Object
Returns the value of attribute gid.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def gid @gid end |
#objects ⇒ Object
Returns the value of attribute objects.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def objects @objects end |
#payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def payload @payload end |
#recipients ⇒ Object
Returns the value of attribute recipients.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def recipients @recipients end |
#rid ⇒ Object
Returns the value of attribute rid.
8 9 10 |
# File 'lib/chat/message.rb', line 8 def rid @rid end |
Instance Method Details
#delete! ⇒ Object
delete! deletes the current message from the conversation.
39 40 41 |
# File 'lib/chat/message.rb', line 39 def delete! @chat.delete(@recipients, @payload[:jti], @payload[:gid]) end |
#edit(body) ⇒ Object
edit changes the current message body for all participants.
46 47 48 49 50 51 |
# File 'lib/chat/message.rb', line 46 def edit(body) return if @recipients == [@chat.app_id] @body = body @chat.edit(@recipients, @payload[:jti], body, @payload[:gid]) end |
#mark_as_delivered ⇒ Object
mark_as_delivered marks the current message as delivered if it comes from another recipient.
55 56 57 58 59 |
# File 'lib/chat/message.rb', line 55 def mark_as_delivered return if @recipients != [@chat.app_id] @chat.delivered(@payload[:iss], @payload[:jti], @payload[:gid]) end |
#mark_as_read ⇒ Object
mark_as_read marks the current message as read if it comes from another recipient.
63 64 65 66 67 |
# File 'lib/chat/message.rb', line 63 def mark_as_read return if @recipients != [@chat.app_id] @chat.read(@payload[:iss], @payload[:jti], @payload[:gid]) end |
#message(body, opts = {}) ⇒ Object
message sends a new message to the same conversation as the current message.
90 91 92 93 94 95 96 97 98 |
# File 'lib/chat/message.rb', line 90 def (body, opts = {}) opts[:aud] = @payload[:gid] if @payload.key? :gid opts[:gid] = @payload[:gid] if @payload.key? :gid to = opts[:recipients] if opts.key? :recipients to = [@payload[:iss]] if @recipients == [@chat.app_id] @chat.(to, body, opts) end |
#respond(body, opts = {}) ⇒ Object
respond sends a direct response to the current message.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chat/message.rb', line 74 def respond(body, opts = {}) opts[:aud] = @payload[:gid] if @payload.key? :gid opts[:gid] = @payload[:gid] if @payload.key? :gid opts[:rid] = @payload[:jti] to = @recipients to = [@payload[:iss]] if @recipients == [@chat.app_id] @chat.(to, body, opts) end |