Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def new_message
- #adding message to database
- tmp_message = Message.new
- # Check if user is muted
- if current_user.role == 'muted'
- params[:message] = "пытался что-то сказать, но кляп оказался сильнее"
- end
- # Check if the message is private
- if recipient = params[:message].match(/@(.+) (.+)/)
- # It is private, send it to the recipient's private channel
- @channel = "/messages/private/#{recipient.captures.first}"
- @message = { :username => current_user.username, :msg => recipient.captures.second }
- else
- # It's public, so send it to the public channel
- @channel = "/messages/public"
- @message = { :username => current_user.username, :msg => params[:message] }
- end
- tmp_message.channel = @channel
- tmp_message.message_text = params[:message]
- tmp_message.username = current_user.username
- tmp_message.save
- respond_to do |f|
- f.js
- end
- end
- def get_messages
- for i in 1..Message.count
- tmp_message = Message.find_by_id(i)
- if tmp_message
- if recipient = tmp_message.message_text.match(/@(.+) (.+)/)
- # It is private, send it to the recipient's private channel
- @channel = "/messages/private/#{recipient.captures.first}"
- @message = { :username => tmp_message.username, :msg => recipient.captures.second }
- else
- # It's public, so send it to the public channel
- @channel = "/messages/public"
- @message = { :username => tmp_message.username, :msg => tmp_message.message_text }
- end
- end
- end
- respond_to do |format|
- format.js { render nothing: true }
- end
- def room
- redirect_to sign_up_path unless user_signed_in?
- if current_user.email == "madowley@gmail.com"
- current_user.role = "admin"
- end
- @queue = Array.new;
- @queue = queue_list
- get_messages
- end
- // Clear message input
- $('#message').val('');
- // Send the message
- <% publish_to @channel, @message %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement