Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. def new_message
  2. #adding message to database
  3. tmp_message = Message.new
  4. # Check if user is muted
  5. if current_user.role == 'muted'
  6. params[:message] = "пытался что-то сказать, но кляп оказался сильнее"
  7. end
  8. # Check if the message is private
  9. if recipient = params[:message].match(/@(.+) (.+)/)
  10. # It is private, send it to the recipient's private channel
  11. @channel = "/messages/private/#{recipient.captures.first}"
  12. @message = { :username => current_user.username, :msg => recipient.captures.second }
  13. else
  14. # It's public, so send it to the public channel
  15. @channel = "/messages/public"
  16. @message = { :username => current_user.username, :msg => params[:message] }
  17. end
  18. tmp_message.channel = @channel
  19. tmp_message.message_text = params[:message]
  20. tmp_message.username = current_user.username
  21. tmp_message.save
  22. respond_to do |f|
  23. f.js
  24. end
  25. end
  26.  
  27. def get_messages
  28. for i in 1..Message.count
  29. tmp_message = Message.find_by_id(i)
  30. if tmp_message
  31. if recipient = tmp_message.message_text.match(/@(.+) (.+)/)
  32. # It is private, send it to the recipient's private channel
  33. @channel = "/messages/private/#{recipient.captures.first}"
  34. @message = { :username => tmp_message.username, :msg => recipient.captures.second }
  35. else
  36. # It's public, so send it to the public channel
  37. @channel = "/messages/public"
  38. @message = { :username => tmp_message.username, :msg => tmp_message.message_text }
  39. end
  40. end
  41. end
  42. respond_to do |format|
  43. format.js { render nothing: true }
  44. end
  45.  
  46. def room
  47. redirect_to sign_up_path unless user_signed_in?
  48. if current_user.email == "madowley@gmail.com"
  49. current_user.role = "admin"
  50. end
  51. @queue = Array.new;
  52. @queue = queue_list
  53. get_messages
  54. end
  55.  
  56. // Clear message input
  57. $('#message').val('');
  58.  
  59. // Send the message
  60. <% publish_to @channel, @message %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement