Class: ChatUser

Inherits:
Object show all
Defined in:
lib/cockatoo_http_server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ChatUser

Returns a new instance of ChatUser.



23
24
25
26
# File 'lib/cockatoo_http_server.rb', line 23

def initialize(attributes)
  @uid = attributes[:uid]
  @friends_ids = []
end

Instance Attribute Details

#discussionObject

Returns the value of attribute discussion.



17
18
19
# File 'lib/cockatoo_http_server.rb', line 17

def discussion
  @discussion
end

#friends_idsObject

Returns the value of attribute friends_ids.



17
18
19
# File 'lib/cockatoo_http_server.rb', line 17

def friends_ids
  @friends_ids
end

#uidObject

Returns the value of attribute uid.



17
18
19
# File 'lib/cockatoo_http_server.rb', line 17

def uid
  @uid
end

Class Method Details

.new_from_query(query) ⇒ Object



18
19
20
21
# File 'lib/cockatoo_http_server.rb', line 18

def self.new_from_query(query)
  return nil unless query.present? && query['uid'].present?
  new(:uid => query['uid'].first.to_i)
end

Instance Method Details

#clear_discussion(did) ⇒ Object



32
33
34
35
36
# File 'lib/cockatoo_http_server.rb', line 32

def clear_discussion(did)
  if self.discussion.present?
    self.discussion.log.delete_if { |message| message["sid"] == did || message["did"] == did }
  end
end

#log_with_user(other_chat_user) ⇒ Object



28
29
30
# File 'lib/cockatoo_http_server.rb', line 28

def log_with_user(other_chat_user)
  self.discussion.present? ? self.discussion.log.select { |message| message["type"] == "message" && (message["sid"] == other_chat_user.uid || message["did"] == other_chat_user.uid) } : []
end