docbrown/app/javascript/chat/actions/chat_channel_setting_actions.js
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

186 lines
4.5 KiB
JavaScript

import { request } from '../../utilities/http';
/**
* This function will get all details of the chat channel accrding to the membership role.
*
* @param {number} chatChannelMembershipId Current User chat channel membership ID
*/
export async function getChannelDetails(chatChannelMembershipId) {
const response = await request(
`/chat_channel_memberships/chat_channel_info/${chatChannelMembershipId}`,
);
return response.json();
}
/**
* This function is used to update the notification settings.
*
* @param {number} membershipId Current user Chat Channel membership Id.
* @param {boolean} notificationBadge Boolean value for the notification
*/
export async function updatePersonalChatChannelNotificationSettings(
membershipId,
notificationBadge,
) {
const response = await request(
`/chat_channel_memberships/update_membership/${membershipId}`,
{
method: 'PATCH',
body: {
chat_channel_membership: {
show_global_badge_notification: notificationBadge,
},
},
},
);
return response.json();
}
/**
* This function is used to reject chat channel joining request & pending requests.
*
* @param { number } channelId Active Chat Channel ID
* @param { number } membershipId Requested user membership Id
* @param { string } membershipStatus Requested user membership status
*/
export async function rejectChatChannelJoiningRequest(
channelId,
membershipId,
membershipStatus,
) {
const response = await request(
`/chat_channel_memberships/remove_membership`,
{
method: 'POST',
body: {
status: membershipStatus || 'pending',
chat_channel_id: channelId,
membership_id: membershipId,
},
},
);
return response.json();
}
/**
*
* @param {number} channelId Active chat channel Id
* @param {number} membershipId Chat channel joining request membership id
*/
export async function acceptChatChannelJoiningRequest(channelId, membershipId) {
const response = await request(`/chat_channel_memberships/add_membership`, {
method: 'POST',
body: {
chat_channel_id: channelId,
membership_id: membershipId,
chat_channel_membership: {
user_action: 'accept',
},
},
});
return response.json();
}
export async function updateChatChannelDescription(
channelId,
description,
discoverable,
) {
const response = await request(`/chat_channels/update_channel/${channelId}`, {
method: 'PATCH',
body: { chat_channel: { description, discoverable } },
credentials: 'same-origin',
});
return response.json();
}
/**
* Send Active chat channel invitation
*
* @param {numner} channelId Active chat channel
* @param {string} invitationUsernames UserNames coma seprated
*/
export async function sendChatChannelInvitation(
channelId,
invitationUsernames,
) {
const response = await request(
`/chat_channel_memberships/create_membership_request`,
{
method: 'POST',
body: {
chat_channel_membership: {
chat_channel_id: channelId,
invitation_usernames: invitationUsernames,
},
},
},
);
return response.json();
}
/**
* This function is used to leave the chat channel.
*
* @param {number} membershipId Current User Chat channel membership id
*/
export async function leaveChatChannelMembership(membershipId) {
const response = await request(
`/chat_channel_memberships/leave_membership/${membershipId}`,
{
method: 'PATCH',
},
);
return response.json();
}
/**
* This function is used to update the membership role
* @param {number} membershipId selected User Chat channel membership id
* @param {number} chatChannelId Current chat chaneel id
* @param {string} role updated role for the membership
*/
export async function updateMembershipRole(membershipId, chatChannelId, role) {
const response = await request(
`/chat_channel_memberships/update_membership_role/${chatChannelId}`,
{
method: 'PATCH',
body: {
chat_channel_membership: {
chat_channel_id: chatChannelId,
membership_id: membershipId,
role,
},
},
},
);
return response.json();
}
/**
* Create Chat Channel
* @param {string} channelName
* @param {string} userNames
*/
export async function createChannel(channelName, userNames) {
const response = await request(`/create_channel`, {
method: 'POST',
body: {
chat_channel: {
channel_name: channelName,
invitation_usernames: userNames,
},
},
});
return response.json();
}