Skip to content

Commit

Permalink
Merge pull request #231 from yoarslan/CU-3w8wm0c_Mute-Channel-Back-End
Browse files Browse the repository at this point in the history
CU-3w8wm0c | Mute-Channel-Back-End
  • Loading branch information
deveu-s authored Feb 3, 2023
2 parents ae49c62 + ae25320 commit 32f4e46
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 18 deletions.
23 changes: 22 additions & 1 deletion app/controllers/api/v1/channel_participants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Api::V1::ChannelParticipantsController < Api::ApiController
before_action :set_bench_channel, only: %i[index create join_public_channel]
before_action :set_bench_channel, only: %i[index create join_public_channel mute_channel unmute_channel]
before_action :set_channel_paticipant, only: %i[mute_channel unmute_channel]
before_action :check_profile_ids, only: %i[create]
before_action :check_channel_participants, only: %i[create]
before_action :check_workspace, only: %i[join_public_channel]
Expand Down Expand Up @@ -41,6 +42,22 @@ def join_public_channel
end
end

def mute_channel
if @channel_participant.update(muted: true)
render json: { message: t('.channel_muted') }, status: :ok
else
render json: { errors: @channel_participant.errors }, status: :unprocessable_entity
end
end

def unmute_channel
if @channel_participant.update(muted: false)
render json: { message: t('.channel_unmuted') }, status: :ok
else
render json: { errors: @channel_participant.errors }, status: :unprocessable_entity
end
end

private

def set_bench_channel
Expand All @@ -50,6 +67,10 @@ def set_bench_channel
render json: { errors: 'User is not part of channel.' }, status: :not_found
end

def set_channel_paticipant
@channel_participant = ChannelParticipant.where(bench_channel_id: @bench_channel.id, profile_id: Current.profile.id)
end

def check_workspace
return if Current.profile.workspace.eql?(@bench_channel.workspace)

Expand Down
18 changes: 2 additions & 16 deletions app/controllers/api/v1/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,8 @@ def set_workspace
end

def profile_params
params.require(:profile).permit(
:username,
:description,
:recording,
:profile_image,
:role,
:display_name,
:title,
:text_status,
:emoji_status,
:clear_status_after,
:time_zone,
:pronounce_name,
:phone,
:skype
).tap do |param|
params.require(:profile).permit(:username, :description, :recording, :profile_image, :role, :display_name, :title, :text_status, :emoji_status,
:clear_status_after, :time_zone, :pronounce_name, :phone, :skype).tap do |param|
param[:workspace_id] = params[:workspace_id]
end
end
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/muted_channel_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module MutedChannelHelper
def muted?(channel_id)
Current.profile.channel_participants.find_by(bench_channel_id: channel_id).muted
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
json.array! @bench_channels do |channel|
json.partial! 'api/v1/bench_channels/partials/bench_channel', bench_channel: channel
json.favourite_id Current.profile.get_favourite_id(channel.id, 'BenchChannel')
json.is_muted muted?(channel.id)
end
9 changes: 9 additions & 0 deletions config/locales/controllers/channel_participants/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
en:
api:
v1:
channel_participants:
mute_channel:
channel_muted: Channel has been muted.
unmute_channel:
channel_unmuted: Channel has been un-muted.

2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
resources :channel_participants, only: %i[create index] do
collection do
post :join_public_channel
post :mute_channel
post :unmute_channel
end
end
resources :draft_messages, only: %i[index create update destroy]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddMutedToChannelParticipants < ActiveRecord::Migration[7.0]
def change
add_column :channel_participants, :muted, :boolean, default: false, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_01_24_075350) do
ActiveRecord::Schema[7.0].define(version: 2023_01_31_103317) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -85,6 +85,7 @@
t.datetime "updated_at", null: false
t.bigint "bench_channel_id", null: false
t.bigint "profile_id", null: false
t.boolean "muted", default: false, null: false
t.index ["bench_channel_id", "profile_id"], name: "index_channel_participants_on_bench_channel_id_and_profile_id", unique: true
t.index ["bench_channel_id"], name: "index_channel_participants_on_bench_channel_id"
t.index ["profile_id"], name: "index_channel_participants_on_profile_id"
Expand Down

0 comments on commit 32f4e46

Please sign in to comment.