Adjust messages_controller to send message before it is persisted if it is valid (#434)

This commit is contained in:
Ben Halpern 2018-06-13 17:35:17 -04:00 committed by GitHub
parent a9bb3b0dee
commit e124decabc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View file

@ -7,10 +7,12 @@ class MessagesController < ApplicationController
authorize @message
success = false
if @message.valid?
message_json = create_pusher_payload(@message)
Pusher.trigger(@message.chat_channel.pusher_channels, "message-created", message_json)
end
if @message.save
begin
message_json = create_pusher_payload(@message)
Pusher.trigger(@message.chat_channel.pusher_channels, "message-created", message_json)
@message.delay.send_push
success = true
rescue Pusher::Error => e

View file

@ -53,6 +53,7 @@ const Channels = ({ activeChannelId, chatChannels, handleSwitchChannel, expanded
return (
<button
key={channel.id}
className='chatchanneltabbutton'
onClick={handleSwitchChannel}
data-channel-id={channel.id}

View file

@ -62,6 +62,10 @@ class Message < ApplicationRecord
end
def evaluate_channel_permission
if chat_channel_id.blank?
errors.add(:base, "Must be part of channel.")
return
end
channel = ChatChannel.find(chat_channel_id)
return if channel.channel_type == "open"
if channel.has_member?(user)