class MessageApi
Public Instance Methods
create_notifications_for(conversation, message)
click to toggle source
# File lib/api/message_api.rb, line 26 def create_notifications_for(conversation, message) # Take sender and recipient sender = conversation.sender recipient = conversation.recipient # Find conversation, where sender it's recipient conversation_2 = recipient.find_conversation_with(sender) # If recipient deletes the conversation, create it again conversation_2 = create_conversation_for_recipient(sender, recipient) if conversation_2.nil? # Send notifications of new messages to sender and recipient [conversation.id, conversation_2.id].each { |id| message.notifications.create(conversation_id: id) } end
densh_conversation()
click to toggle source
# File lib/api/message_api.rb, line 45 def densh_conversation Denshobato::Conversation end
formated_messages(klass)
click to toggle source
# File lib/api/message_api.rb, line 12 def formated_messages(klass) # Prepare JSON for React { body: klass.body, id: klass.id, author: klass.author.email, full_name: klass.author.full_name, avatar: klass.author.image, time: klass.message_time } end
message_class()
click to toggle source
# File lib/api/message_api.rb, line 41 def message_class Denshobato::Message end
send_notification(id, message)
click to toggle source
# File lib/api/message_api.rb, line 18 def send_notification(id, message) # Find current conversation conversation = densh_conversation.find(id) # Create Notifications create_notifications_for(conversation, message) end
take_current_user(params)
click to toggle source
# File lib/api/message_api.rb, line 8 def take_current_user(params) params[:class].constantize.find(params[:user]) end