docbrown/app/javascript/chat/actions.js
Sarthak Sharma 90d60bf73f
[deploy] 🚀 Feature: Ability to search discoverable channels and send request to join (#7385)
* 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

* added new column discoverable for public channel and changes in elasticsearch

* fix corrections

* changes in serializer file, added channel_discoverable

* added checkbox with discoverable policy

* changes in code for discoverable channels

* accept and reject member invitation by mod

* add joining request to closed groups

* fixed merge error

* changes in joining member to closed groups

* join to closed group

* changes in message action of joining

* changes in chat upopened json

* 🚀Feature : Ability to search Global Channels

* touch updated_at in after commit update

* 🚀Feature : Ability to send request to discoverable channel

* 🚀Feature : Ability to send request to discoverable channel

* created new route for joining closed channel

* 🚀 Success handle on joining request sent

* removed redundant code

* join_channel improvement, removed authorization for join channel

* list of joining requests

* added joining_request status channels on search list

* changes in mailer and query builder optimized

* 🛠 Adding filter for new Query

* added rspec for add membership method in controller

* rspec for sending join channel request

* invite join request channel list rspec

* test case for query builder discoverable

* viewable and discoverable channel list

* refactored logic for search channels

* 🚀 Check if Request already sent

* 🛠 Optimizing code and making channelButton Component

* 🛠 Optimizing codefor SVG problem

* 🛠 Optimized action.js

* changes in search controller query

* hot fix

* removed unwanted code

* 🛠  Fix the Channel Name problem

* 🛠  Optimizing code further for CodeClimate

* added new column discoverable for public channel and changes in elasticsearch

* fix corrections

* changes in serializer file, added channel_discoverable

* added checkbox with discoverable policy

* changes in code for discoverable channels

* accept and reject member invitation by mod

* add joining request to closed groups

* fixed merge error

* changes in joining member to closed groups

* join to closed group

* changes in message action of joining

* changes in chat upopened json

* touch updated_at in after commit update

* 🚀Feature : Ability to search Global Channels

* 🚀Feature : Ability to send request to discoverable channel

* 🚀Feature : Ability to send request to discoverable channel

* created new route for joining closed channel

* 🚀 Success handle on joining request sent

* removed redundant code

* join_channel improvement, removed authorization for join channel

* list of joining requests

* added joining_request status channels on search list

* changes in mailer and query builder optimized

* added rspec for add membership method in controller

* rspec for sending join channel request

* invite join request channel list rspec

* 🛠 Adding filter for new Query

* test case for query builder discoverable

* viewable and discoverable channel list

* refactored logic for search channels

* 🚀 Check if Request already sent

* 🛠 Optimizing code and making channelButton Component

* 🛠 Optimizing codefor SVG problem

* 🛠 Optimized action.js

* changes in search controller query

* hot fix

* 🛠  Fix the Channel Name problem

* 🛠  Fixing merge problem

* 🛠  Optimizing code further for CodeClimate

* updated UI for membership edit

* fixed test casses and fixed UI for chat_channel_edit

* 🛠napshots added

* test cases fixed

* 🛠 Test cases added for new component

* channel settings accesible only by mod

* 🛠 More Test cases added

* 🛠 Svg code optimized

* 🛠 Svg code optimized in videocontent

* optimized code for search query

* fix test case for query builder

* changes in joining closed channel logic

* refactored join channel

* redirect to edit channel after joining request

* changes in test case for redirect

* optimized code

* 🛠 Eslint bugs fixed

* test case fixed

* optimization

* olving channel repetition problem

* optimization of code for query builder

* changes in query builder

* test cases fixed

* 🛠 Handling reduntant data on frontend

* 🛠  Don't show data if no filter query

* 🛠 Optimized code for fixing bugs and code coverage

* 🛠  Optimizing code further for CodeClimate

Co-authored-by: Parasgr-code <paras.gaur@skynox.tech>
2020-05-11 09:29:15 -04:00

248 lines
6.2 KiB
JavaScript

import { fetchSearch } from '../src/utils/search';
export function getAllMessages(channelId, messageOffset, successCb, failureCb) {
fetch(`/chat_channels/${channelId}?message_offset=${messageOffset}`, {
Accept: 'application/json',
'Content-Type': 'application/json',
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function sendMessage(messageObject, successCb, failureCb) {
fetch('/messages', {
method: 'POST',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
message_markdown: messageObject.message,
user_id: window.currentUser.id,
chat_channel_id: messageObject.activeChannelId,
mentioned_users_id: messageObject.mentionedUsersId,
},
}),
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function editMessage(editedMessage, successCb, failureCb) {
fetch(`/messages/${editedMessage.id}`, {
method: 'PATCH',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
message_markdown: editedMessage.message,
user_id: window.currentUser.id,
chat_channel_id: editedMessage.activeChannelId,
},
}),
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function sendOpen(activeChannelId, successCb, failureCb) {
fetch(`/chat_channels/${activeChannelId}/open`, {
method: 'POST',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function conductModeration(
activeChannelId,
message,
successCb,
failureCb,
) {
fetch(`/chat_channels/${activeChannelId}/moderate`, {
method: 'POST',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
chat_channel: {
command: message,
},
}),
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function getChannels(
query,
retrievalID,
searchType,
paginationNumber,
additionalFilters,
successCb,
_failureCb,
) {
const dataHash = {};
if (additionalFilters.filters) {
const [key, value] = additionalFilters.filters.split(':');
dataHash[key] = value;
}
dataHash.per_page = 30;
dataHash.page = paginationNumber;
dataHash.channel_text = query;
if (searchType === 'discoverable') {
dataHash.user_id = 'all';
}
const responsePromise = fetchSearch('chat_channels', dataHash);
return responsePromise.then((response) => {
const channels = response.result;
if (
retrievalID === null ||
channels.filter((e) => e.chat_channel_id === retrievalID).length === 1
) {
successCb(channels, query);
} else {
fetch(
`/chat_channel_memberships/find_by_chat_channel_id?chat_channel_id=${retrievalID}`,
{
Accept: 'application/json',
'Content-Type': 'application/json',
credentials: 'same-origin',
},
)
.then((individualResponse) => individualResponse.json())
.then((json) => {
channels.unshift(json);
successCb(channels, query);
});
}
});
}
export function getUnopenedChannelIds(successCb) {
fetch('/chat_channels?state=unopened_ids', {
credentials: 'same-origin',
})
.then((response) => response.json())
.then((json) => {
successCb(json.unopened_ids);
});
}
export function getContent(url, successCb, failureCb) {
fetch(url, {
Accept: 'application/json',
'Content-Type': 'application/json',
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function getJSONContents(url, successCb, failureCb) {
fetch(url, {
Accept: 'application/json',
'Content-Type': 'application/json',
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function getChannelInvites(successCb, failureCb) {
fetch('/chat_channels?state=pending', {
Accept: 'application/json',
'Content-Type': 'application/json',
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function sendChannelInviteAction(id, action, successCb, failureCb) {
fetch(`/chat_channel_memberships/${id}`, {
method: 'PUT',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
chat_channel_membership: {
user_action: action,
},
}),
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function deleteMessage(messageId, successCb, failureCb) {
fetch(`/messages/${messageId}`, {
method: 'DELETE',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
user_id: window.currentUser.id,
},
}),
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}
export function sendChannelRequest(id, successCb, failureCb) {
fetch(`/join_chat_channel`, {
method: 'POST',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
chat_channel_membership: {
chat_channel_id: id,
},
}),
credentials: 'same-origin',
})
.then((response) => response.json())
.then(successCb)
.catch(failureCb);
}