chore: Add controllers for conversation participants (#6462)

Co-authored-by: Aswin Dev P.S <aswindevps@gmail.com>
Co-authored-by: Sojan Jose <sojan@chatwoot.com>
This commit is contained in:
Pranav Raj S
2023-02-15 16:33:31 -08:00
committed by GitHub
parent 949ddf68ba
commit 7044eda281
34 changed files with 546 additions and 63 deletions

View File

@@ -9,6 +9,7 @@ class Messages::MentionService
Conversations::UserMentionJob.perform_later(validated_mentioned_ids, message.conversation.id, message.account.id)
generate_notifications_for_mentions(validated_mentioned_ids)
add_mentioned_users_as_participants(validated_mentioned_ids)
end
private
@@ -38,4 +39,10 @@ class Messages::MentionService
).perform
end
end
def add_mentioned_users_as_participants(validated_mentioned_ids)
validated_mentioned_ids.each do |user_id|
message.conversation.conversation_participants.find_or_create_by!(user_id: user_id)
end
end
end

View File

@@ -4,6 +4,7 @@ class Messages::NewMessageNotificationService
def perform
return unless message.notifiable?
notify_participating_users
notify_conversation_assignee
end
@@ -11,8 +12,23 @@ class Messages::NewMessageNotificationService
delegate :conversation, :sender, :account, to: :message
def notify_participating_users
participating_users = conversation.conversation_participants.map(&:user)
participating_users -= [sender] if sender.is_a?(User)
participating_users.uniq.each do |participant|
NotificationBuilder.new(
notification_type: 'participating_conversation_new_message',
user: participant,
account: account,
primary_actor: message
).perform
end
end
def notify_conversation_assignee
return if conversation.assignee.blank?
return if assignee_already_notified_via_participation?
return if conversation.assignee == sender
NotificationBuilder.new(
@@ -22,4 +38,13 @@ class Messages::NewMessageNotificationService
primary_actor: message
).perform
end
def assignee_already_notified_via_participation?
return unless conversation.conversation_participants.map(&:user).include?(conversation.assignee)
# check whether participation notifcation is disabled for assignee
notification_setting = conversation.assignee.notification_settings.find_by(account_id: account.id)
notification_setting.public_send(:email_participating_conversation_new_message?) || notification_setting
.public_send(:push_participating_conversation_new_message?)
end
end