docbrown/app/javascript/chat/actions/chat_channel_setting_actions.js
narender2031 e78a0078a7
[deploy] Refactor 🚀 : Replaced Chat Channel Setting page with Preact component. (#8271)
* 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

* 🐞 Channel List bug in mobile view

* changes in joining request responses

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* changes in api for remove membership

* Merge conflict resolved

* 🐞 Channel List bug in mobile view

* changes in joining request responses

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* changes in api for remove membership

* 🛠Optimizing for CodeClimate

* 🛠Optimizing again for CodeClimate

* 🛠Optimizing again 2 for CodeClimate

* 🛠 Added more test cases

* 🛠 Optimizing code

* 🚀 Action to open setting page added

* 🛠  Dummy page added for chat setting

* add JSON routes for chat channel settings

* Integrate chat channel settings API with UI

* 🐞 Channel List bug in mobile view

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* 🐞 Channel List bug in mobile view

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* 🛠Optimizing again for CodeClimate

* 🚀 Action to open setting page added

* 🛠  Dummy page added for chat setting

* add JSON routes for chat channel settings

* Integrate chat channel settings API with UI

* Fix PR requested changes

* Add JSDoc documentation to exported functions

* fix/add rspec test cases

* refactor channelSettinngs render part

* add test cases for chat channel settings component

* fix code-climate

* add rest component tests

* add more test coverage

* fix code-climate bugs

* add API function test

Co-authored-by: Sarthak Sharma <7lovesharma7@gmail.com>
Co-authored-by: Parasgr-code <paras.gaur@skynox.tech>
2020-06-10 16:58:37 -04:00

151 lines
3.7 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}`,
{
credentials: 'same-origin',
},
);
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,
},
},
credentials: 'same-origin',
},
);
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,
},
credentials: 'same-origin',
},
);
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',
},
},
credentials: 'same-origin',
});
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,
},
},
credentials: 'same-origin',
},
);
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',
credentials: 'same-origin',
},
);
return response.json();
}