Skip to content

Commit 32f4e46

Browse files
authored
Merge pull request #231 from yoarslan/CU-3w8wm0c_Mute-Channel-Back-End
CU-3w8wm0c | Mute-Channel-Back-End
2 parents ae49c62 + ae25320 commit 32f4e46

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

app/controllers/api/v1/channel_participants_controller.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Api::V1::ChannelParticipantsController < Api::ApiController
2-
before_action :set_bench_channel, only: %i[index create join_public_channel]
2+
before_action :set_bench_channel, only: %i[index create join_public_channel mute_channel unmute_channel]
3+
before_action :set_channel_paticipant, only: %i[mute_channel unmute_channel]
34
before_action :check_profile_ids, only: %i[create]
45
before_action :check_channel_participants, only: %i[create]
56
before_action :check_workspace, only: %i[join_public_channel]
@@ -41,6 +42,22 @@ def join_public_channel
4142
end
4243
end
4344

45+
def mute_channel
46+
if @channel_participant.update(muted: true)
47+
render json: { message: t('.channel_muted') }, status: :ok
48+
else
49+
render json: { errors: @channel_participant.errors }, status: :unprocessable_entity
50+
end
51+
end
52+
53+
def unmute_channel
54+
if @channel_participant.update(muted: false)
55+
render json: { message: t('.channel_unmuted') }, status: :ok
56+
else
57+
render json: { errors: @channel_participant.errors }, status: :unprocessable_entity
58+
end
59+
end
60+
4461
private
4562

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

70+
def set_channel_paticipant
71+
@channel_participant = ChannelParticipant.where(bench_channel_id: @bench_channel.id, profile_id: Current.profile.id)
72+
end
73+
5374
def check_workspace
5475
return if Current.profile.workspace.eql?(@bench_channel.workspace)
5576

app/controllers/api/v1/profiles_controller.rb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,8 @@ def set_workspace
9696
end
9797

9898
def profile_params
99-
params.require(:profile).permit(
100-
:username,
101-
:description,
102-
:recording,
103-
:profile_image,
104-
:role,
105-
:display_name,
106-
:title,
107-
:text_status,
108-
:emoji_status,
109-
:clear_status_after,
110-
:time_zone,
111-
:pronounce_name,
112-
:phone,
113-
:skype
114-
).tap do |param|
99+
params.require(:profile).permit(:username, :description, :recording, :profile_image, :role, :display_name, :title, :text_status, :emoji_status,
100+
:clear_status_after, :time_zone, :pronounce_name, :phone, :skype).tap do |param|
115101
param[:workspace_id] = params[:workspace_id]
116102
end
117103
end

app/helpers/muted_channel_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module MutedChannelHelper
2+
def muted?(channel_id)
3+
Current.profile.channel_participants.find_by(bench_channel_id: channel_id).muted
4+
end
5+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
json.array! @bench_channels do |channel|
22
json.partial! 'api/v1/bench_channels/partials/bench_channel', bench_channel: channel
33
json.favourite_id Current.profile.get_favourite_id(channel.id, 'BenchChannel')
4+
json.is_muted muted?(channel.id)
45
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
en:
2+
api:
3+
v1:
4+
channel_participants:
5+
mute_channel:
6+
channel_muted: Channel has been muted.
7+
unmute_channel:
8+
channel_unmuted: Channel has been un-muted.
9+

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
resources :channel_participants, only: %i[create index] do
8888
collection do
8989
post :join_public_channel
90+
post :mute_channel
91+
post :unmute_channel
9092
end
9193
end
9294
resources :draft_messages, only: %i[index create update destroy]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddMutedToChannelParticipants < ActiveRecord::Migration[7.0]
2+
def change
3+
add_column :channel_participants, :muted, :boolean, default: false, null: false
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

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

@@ -85,6 +85,7 @@
8585
t.datetime "updated_at", null: false
8686
t.bigint "bench_channel_id", null: false
8787
t.bigint "profile_id", null: false
88+
t.boolean "muted", default: false, null: false
8889
t.index ["bench_channel_id", "profile_id"], name: "index_channel_participants_on_bench_channel_id_and_profile_id", unique: true
8990
t.index ["bench_channel_id"], name: "index_channel_participants_on_bench_channel_id"
9091
t.index ["profile_id"], name: "index_channel_participants_on_profile_id"

0 commit comments

Comments
 (0)