docbrown/app/helpers/chat_channels_helper.rb
Sarthak Sharma 6dee5edd0e
🚀 Ability to allow tag moderators to create chat channels (#9741)
* Feature 🚀 : Ability to delete messages in chat channels

- Sending message ID to frontend
- Deleting Message
- Use pusher to delete message realtime

* Minor Bug 🐞: Show message action only for current user

- User can delete or edit their own messages

* Test cases added

* Bug 🐞: Update message id for receiver

Message id was not sent to receiver by pusher

* Refactoring🛠: Message controller refactoring

* Test Cases📝 : Specs for Delete message added

* Feature 🚀 : Ability to edit messages

* Test Cases📝 : Specs for Edit message added

* Merge conflict resolved

* UI completed for Create Channel

* API for create channel & invitations

* 🚀 Combining Backend and Frontend

* Test cases added

* UI completed for Create Channel

* API for create channel & invitations

* 🚀 Combining Backend and Frontend

* Test cases added

* fix suggestions

* add test cases

* replace mod_relations_admin to tag_moderator

* fix test cases

* refactor and fix code climate issues

* Update app/controllers/chat_channel_memberships_controller.rb

Co-authored-by: Michael Kohl <me@citizen428.net>

* fix suggestions

* renaming the methods

* Update app/javascript/chat/chat.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/components/createChatModal.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add jsDoc and add validation

* add PR suggestions

* renmae the file name to  PascalCase

* add styled component

* refactor channel button component

* fix specs

* fix code smell issues

* fix file name issue

* handle error message

* add jsDoc

* Update app/controllers/chat_channels_controller.rb

Co-authored-by: Michael Kohl <me@citizen428.net>

* refactor chat_channel_helpers

* update old hash to new hash

* Update app/javascript/chat/components/ChannelButton.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/views/chat_channels/index.html.erb

Co-authored-by: Michael Kohl <me@citizen428.net>

* fix syntax error

* Update app/views/chat_channels/index.html.erb

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Policies changed

* The Disable Button issue 🐞

* Fixing Disabled button Issue 🐞

* New group doesn't show up 🐞

Co-authored-by: Narender Singh <narender2031@gmail.com>
Co-authored-by: Michael Kohl <me@citizen428.net>
Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
2020-12-08 13:10:36 +07:00

44 lines
1.5 KiB
Ruby

module ChatChannelsHelper
def unopened_json_response
if session_current_user_id
ChatChannelMembership.where(user_id: session_current_user_id)
.where(has_unopened_messages: true)
.where(show_global_badge_notification: true)
.where.not(status: %w[removed_from_channel left_channel])
.includes(%i[chat_channel user])
.order("chat_channel_memberships.updated_at" => :desc)
else
ChatChannelMembership.none
end
end
def pending_json_response
if current_user
current_user
.chat_channel_memberships.includes(:chat_channel)
.where(status: "pending")
.order("chat_channel_memberships.updated_at" => :desc)
else
ChatChannelMembership.none
end
end
def unopened_ids_response
ChatChannelMembership.where(user_id: session_current_user_id).includes(:chat_channel)
.where(has_unopened_messages: true).where.not(status: %w[removed_from_channel
left_channel]).pluck(:chat_channel_id)
end
def joining_request_json_response
requested_memberships_id = current_user
.chat_channel_memberships
.includes(:chat_channel)
.where(chat_channels: { discoverable: true }, role: "mod")
.pluck(:chat_channel_id)
.flat_map { |membership_id| ChatChannel.find_by(id: membership_id).requested_memberships.ids }
ChatChannelMembership
.includes(%i[user chat_channel])
.where(id: requested_memberships_id)
end
end