docbrown/app/javascript/chat/actions/chat_channel_setting_actions.js
Sarthak Sharma 3addb64326
[deploy] 🚀 Feature: Chat channel membership manager component (#8945)
* 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

* fix video content issue

* add UI for membership management

* add api to update memberahip role

* add methods for manage membership

* Add integration test cases

* add emoji for admin

* Open member profile in sidecar only

* 🐞 Problem with direct channel sidecar

* 🐞 Few other UI enhancements

* fix mod typo

* add limit upto 4 for display active memberships

* fix UI issues

* fix action ui for membership

* fix sidebar redirection issue

* fix svg buttons

* add test cases

* fixed broken spec

* fix PR suggestions

* remove not used code

* fix typo

* fix PR suggestion

* fix typos

* add invitation url expiry

* fix specs

* fix PR suggestions

* removed unused gem

* remove presenter format

* handle invitation link expiry with redis

* fix PR suggestions

* user can view non-discoverable channel invitation link

* fix typos

* remove commented code

* add spacing

* PR suggestions

* remove class from button

* replace componentDidMount with commen function

* remove action button for single membership

* add chat message on update role

* add spece between lines

Co-authored-by: Narender Singh <narender2031@gmail.com>
Co-authored-by: Fernando Valverde <fdov88@gmail.com>
2020-07-20 08:08:31 -04:00

175 lines
4.4 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();
}
/**
* 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,
},
},
credentials: 'same-origin',
},
);
return response.json();
}