diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index e73e5e5ca..c94e8040a 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -42,7 +42,7 @@ class ChatChannelsController < ApplicationController if banned_user banned_user.add_role :banned banned_user.messages.each(&:destroy!) - notification_channels = @chat_channel.chat_channel_memberships.pluck(:user_id).map { |id| "message-notifications-#{id}"} + notification_channels = @chat_channel.chat_channel_memberships.pluck(:user_id).map { |id| "private-message-notifications-#{id}"} Pusher.trigger(notification_channels, "user-banned", { userId: banned_user.id }.to_json) render json: { status: "success", message: "banned!" }, status: 200 else diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 687714df6..dda816c7e 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -3,13 +3,14 @@ class MessagesController < ApplicationController def create @message = Message.new(message_params) + @message.user_id = current_user.id authorize @message success = false if @message.save begin message_json = create_pusher_payload(@message) - notification_channels = @message.chat_channel.chat_channel_memberships.pluck(:user_id).map { |id| "message-notifications-#{id}"} + notification_channels = @message.chat_channel.chat_channel_memberships.pluck(:user_id).map { |id| "private-message-notifications-#{id}"} Pusher.trigger(notification_channels, "message-created", message_json) success = true rescue Pusher::Error => e diff --git a/app/controllers/pusher_controller.rb b/app/controllers/pusher_controller.rb index f382a6609..7aa3a5c1e 100644 --- a/app/controllers/pusher_controller.rb +++ b/app/controllers/pusher_controller.rb @@ -1,8 +1,8 @@ class PusherController < ApplicationController def auth - if current_user - response = pusher_client.authenticate(params[:channel_name], params[:socket_id], { + if current_user && params[:channel_name] == "private-message-notifications-#{current_user.id}" + response = Pusher.authenticate(params[:channel_name], params[:socket_id], { user_id: current_user.id, # => required }) render json: response diff --git a/app/javascript/chat/chat.jsx b/app/javascript/chat/chat.jsx index 94874f423..372bd5a12 100644 --- a/app/javascript/chat/chat.jsx +++ b/app/javascript/chat/chat.jsx @@ -39,7 +39,7 @@ export default class Chat extends Component { }); setupObserver(this.observerCallback); setupPusher(this.props.pusherKey, { - channelId: `message-notifications-${window.currentUser.id}`, + channelId: `private-message-notifications-${window.currentUser.id}`, messageCreated: this.receiveNewMessage, channelCleared: this.clearChannel, redactUserMessages: this.redactUserMessages, diff --git a/app/javascript/src/utils/getUnopenedChannels.jsx b/app/javascript/src/utils/getUnopenedChannels.jsx index 441d41bc5..1c8e25281 100644 --- a/app/javascript/src/utils/getUnopenedChannels.jsx +++ b/app/javascript/src/utils/getUnopenedChannels.jsx @@ -15,7 +15,7 @@ class UnopenedChannelNotice extends Component { componentDidMount() { setupPusher(this.props.pusherKey, { - channelId: `message-notifications-${window.currentUser.id}`, + channelId: `private-message-notifications-${window.currentUser.id}`, messageCreated: this.receiveNewMessage, }); } diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index 9408ea09d..19d8d0a7b 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -10,7 +10,7 @@ class ChatChannel < ApplicationRecord def clear_channel messages.each(&:destroy!) - notification_channels = chat_channel_memberships.pluck(:user_id).map { |id| "message-notifications-#{id}"} + notification_channels = chat_channel_memberships.pluck(:user_id).map { |id| "private-message-notifications-#{id}"} Pusher.trigger(notification_channels, "channel-cleared", { chat_channel_id: id }.to_json) true rescue Pusher::Error => e diff --git a/config/routes.rb b/config/routes.rb index 92e37c38c..71246ebb9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -102,7 +102,7 @@ Rails.application.routes.draw do get "/💌" => "chat_channels#index" get "/💌/:slug" => "chat_channels#index" - post "/pusher/auth" => "chat_channels#index" + post "/pusher/auth" => "pusher#auth" # resources :users