Make pusher channels private (#410)
This commit is contained in:
parent
645de032df
commit
1a85bddd2c
7 changed files with 9 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue