diff --git a/app/channels/room_channel.rb b/app/channels/room_channel.rb index df1a05d6b..1a0cbb434 100644 --- a/app/channels/room_channel.rb +++ b/app/channels/room_channel.rb @@ -1,10 +1,42 @@ class RoomChannel < ApplicationCable::Channel def subscribed - stream_from params[:pubsub_token] - ::OnlineStatusTracker.add_subscription(params[:pubsub_token]) + ensure_stream + current_user + current_account + update_subscription end - def unsubscribed - ::OnlineStatusTracker.remove_subscription(params[:pubsub_token]) + def update_presence + update_subscription + data = { account_id: @current_account.id, users: ::OnlineStatusTracker.get_available_users(@current_account.id) } + data[:contacts] = ::OnlineStatusTracker.get_available_contacts(@current_account.id) if @current_user.is_a? User + ActionCable.server.broadcast(@pubsub_token, { event: 'presence.update', data: data }) + end + + private + + def ensure_stream + @pubsub_token = params[:pubsub_token] + stream_from @pubsub_token + end + + def update_subscription + ::OnlineStatusTracker.update_presence(@current_account.id, @current_user.class.name, @current_user.id) + end + + def current_user + @current_user ||= if params[:user_id].blank? + Contact.find_by!(pubsub_token: @pubsub_token) + else + User.find_by!(pubsub_token: @pubsub_token, id: params[:user_id]) + end + end + + def current_account + @current_account ||= if @current_user.is_a? Contact + @current_user.account + else + @current_user.accounts.find(params[:account_id]) + end end end diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb index bd415ffeb..38f1a9b3b 100644 --- a/app/controllers/api/v1/profiles_controller.rb +++ b/app/controllers/api/v1/profiles_controller.rb @@ -16,6 +16,6 @@ class Api::V1::ProfilesController < Api::BaseController end def profile_params - params.require(:profile).permit(:email, :name, :password, :password_confirmation, :avatar) + params.require(:profile).permit(:email, :name, :password, :password_confirmation, :avatar, :availability) end end diff --git a/app/javascript/dashboard/api/auth.js b/app/javascript/dashboard/api/auth.js index f247089cd..42d1fbc41 100644 --- a/app/javascript/dashboard/api/auth.js +++ b/app/javascript/dashboard/api/auth.js @@ -118,21 +118,18 @@ export default { return axios.post(urlData.url, { email }); }, - profileUpdate({ name, email, password, password_confirmation, avatar }) { + profileUpdate({ password, password_confirmation, ...profileAttributes }) { const formData = new FormData(); - if (name) { - formData.append('profile[name]', name); - } - if (email) { - formData.append('profile[email]', email); - } + Object.keys(profileAttributes).forEach(key => { + const value = profileAttributes[key]; + if (value) { + formData.append(`profile[${key}]`, value); + } + }); if (password && password_confirmation) { formData.append('profile[password]', password); formData.append('profile[password_confirmation]', password_confirmation); } - if (avatar) { - formData.append('profile[avatar]', avatar); - } return axios.put(endPoints('profileUpdate').url, formData); }, }; diff --git a/app/javascript/dashboard/components/layout/Sidebar.vue b/app/javascript/dashboard/components/layout/Sidebar.vue index 4ec6c239f..d6ab8a75d 100644 --- a/app/javascript/dashboard/components/layout/Sidebar.vue +++ b/app/javascript/dashboard/components/layout/Sidebar.vue @@ -56,7 +56,11 @@
- +

{{ currentUser.name }} diff --git a/app/javascript/dashboard/components/widgets/Thumbnail.vue b/app/javascript/dashboard/components/widgets/Thumbnail.vue index 25b707c04..2d1c3e200 100644 --- a/app/javascript/dashboard/components/widgets/Thumbnail.vue +++ b/app/javascript/dashboard/components/widgets/Thumbnail.vue @@ -21,11 +21,6 @@ :style="badgeStyle" src="~dashboard/assets/images/fb-badge.png" /> -
- +