feat: Add pending message on dashboard (#1547)

This commit is contained in:
Nithin David Thomas
2020-12-25 13:15:01 +05:30
committed by GitHub
parent 3e61ea5cfa
commit 7c62d3629c
17 changed files with 260 additions and 53 deletions

View File

@@ -1,5 +1,8 @@
/* eslint no-console: 0 */
/* eslint no-param-reassign: 0 */
import getUuid from 'widget/helpers/uuid';
import { MESSAGE_STATUS, MESSAGE_TYPE } from 'shared/constants/messages';
export default () => {
if (!Array.prototype.last) {
Object.assign(Array.prototype, {
@@ -26,3 +29,41 @@ export const getTypingUsersText = (users = []) => {
const rest = users.length - 1;
return `${user.name} and ${rest} others are typing`;
};
export const createPendingMessage = data => {
const timestamp = Math.floor(new Date().getTime() / 1000);
const tempMessageId = getUuid();
const pendingMessage = {
...data,
content: data.message,
id: tempMessageId,
echo_id: tempMessageId,
status: MESSAGE_STATUS.PROGRESS,
created_at: timestamp,
message_type: MESSAGE_TYPE.OUTGOING,
conversation_id: data.conversationId,
};
return pendingMessage;
};
export const createPendingAttachment = data => {
const [conversationId, { isPrivate = false }] = data;
const timestamp = Math.floor(new Date().getTime() / 1000);
const tempMessageId = getUuid();
const pendingMessage = {
id: tempMessageId,
echo_id: tempMessageId,
status: MESSAGE_STATUS.PROGRESS,
created_at: timestamp,
message_type: MESSAGE_TYPE.OUTGOING,
conversation_id: conversationId,
attachments: [
{
id: tempMessageId,
},
],
private: isPrivate,
content: null,
};
return pendingMessage;
};