robbyson-frontend-library 1.0.83 → 1.0.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/chat.constants.js +21 -14
- package/dist/types/chat/chat.types.js +24 -25
- package/dist/utils/chat.utils.js +90 -0
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
- package/src/constants/chat.constants.ts +11 -4
- package/src/models/angel-friend-status.model.ts +2 -2
- package/src/models/chat.model.ts +3 -3
- package/src/models/message.model.ts +1 -0
- package/src/models/user-list.model.ts +2 -2
- package/src/repositories/index.d.ts +2 -2
- package/src/services/angel-friend.service.interface.ts +1 -0
- package/src/services/chat.service.interface.ts +26 -6
- package/src/services/dtos/chat.dto.ts +33 -8
- package/src/states/chat-container/chat-app.state.interface.ts +2 -4
- package/src/types/chat/chat.types.ts +53 -52
- package/src/utils/chat.utils.ts +132 -0
- package/src/utils/index.ts +1 -0
|
@@ -7,18 +7,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7
7
|
}
|
|
8
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
9
|
};
|
|
10
|
-
export var
|
|
11
|
-
(function (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})(
|
|
17
|
-
export var
|
|
18
|
-
(function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})(
|
|
10
|
+
export var TYPE_CHAT;
|
|
11
|
+
(function (TYPE_CHAT) {
|
|
12
|
+
TYPE_CHAT["CHAT"] = "chat";
|
|
13
|
+
TYPE_CHAT["GROUP"] = "group";
|
|
14
|
+
TYPE_CHAT["GROUPS"] = "groups";
|
|
15
|
+
TYPE_CHAT["CHATBOT"] = "chat-bot";
|
|
16
|
+
})(TYPE_CHAT || (TYPE_CHAT = {}));
|
|
17
|
+
export var CHAT_CLASSIFICATION;
|
|
18
|
+
(function (CHAT_CLASSIFICATION) {
|
|
19
|
+
CHAT_CLASSIFICATION["TREE_MESSAGE"] = "tree-message";
|
|
20
|
+
CHAT_CLASSIFICATION["ANGEL_FRIEND"] = "angel-friend";
|
|
21
|
+
})(CHAT_CLASSIFICATION || (CHAT_CLASSIFICATION = {}));
|
|
22
22
|
var IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif"];
|
|
23
23
|
var ALLOWED_EXTENSIONS = new Set(__spreadArray(__spreadArray([], IMAGE_EXTENSIONS, true), [
|
|
24
24
|
"mp4",
|
|
@@ -30,9 +30,16 @@ var ALLOWED_EXTENSIONS = new Set(__spreadArray(__spreadArray([], IMAGE_EXTENSION
|
|
|
30
30
|
"ppt",
|
|
31
31
|
"pptx",
|
|
32
32
|
], false));
|
|
33
|
+
export var MEETINGS_SIDEBAR_OPTIONS;
|
|
34
|
+
(function (MEETINGS_SIDEBAR_OPTIONS) {
|
|
35
|
+
MEETINGS_SIDEBAR_OPTIONS["PARTICIPANTS"] = "participants";
|
|
36
|
+
MEETINGS_SIDEBAR_OPTIONS["CHAT"] = "chat";
|
|
37
|
+
MEETINGS_SIDEBAR_OPTIONS["MENU"] = "menu";
|
|
38
|
+
})(MEETINGS_SIDEBAR_OPTIONS || (MEETINGS_SIDEBAR_OPTIONS = {}));
|
|
33
39
|
export var ChatConstants = {
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
TYPE_CHAT: TYPE_CHAT,
|
|
41
|
+
CHAT_CLASSIFICATION: CHAT_CLASSIFICATION,
|
|
36
42
|
ALLOWED_EXTENSIONS: ALLOWED_EXTENSIONS,
|
|
37
43
|
IMAGE_EXTENSIONS: IMAGE_EXTENSIONS,
|
|
44
|
+
MEETINGS_SIDEBAR_OPTIONS: MEETINGS_SIDEBAR_OPTIONS,
|
|
38
45
|
};
|
|
@@ -3,33 +3,32 @@ export var Classification;
|
|
|
3
3
|
Classification["tree_message"] = "tree-message";
|
|
4
4
|
Classification["angel_friend"] = "angel-friend";
|
|
5
5
|
})(Classification || (Classification = {}));
|
|
6
|
-
;
|
|
7
6
|
export var MessagesType;
|
|
8
7
|
(function (MessagesType) {
|
|
9
8
|
MessagesType["ALL"] = "all";
|
|
10
9
|
MessagesType["FAVORITE"] = "fav";
|
|
11
10
|
})(MessagesType || (MessagesType = {}));
|
|
12
|
-
export var SET_CHAT_LIST_VISIBILITY =
|
|
13
|
-
export var SET_SEARCH_MESSAGE =
|
|
14
|
-
export var SET_MARK_POSITION_ID =
|
|
15
|
-
export var CLEAR_SEARCH_MESSAGE =
|
|
16
|
-
export var OPEN_CONVERSATION =
|
|
17
|
-
export var CLOSE_CONVERSATION =
|
|
18
|
-
export var SUCCESS_CONVERSATIONS =
|
|
19
|
-
export var SUCCESS_CONVERSATION =
|
|
20
|
-
export var SUCCESS_MESSAGES =
|
|
21
|
-
export var ADD_MESSAGE =
|
|
22
|
-
export var UPDATE_CONVERSATION =
|
|
23
|
-
export var UPDATE_USERS =
|
|
24
|
-
export var UPDATE_MESSAGES =
|
|
25
|
-
export var UPDATE_MESSAGE =
|
|
26
|
-
export var UPDATE_MESSAGE_BY_MESSAGE_ID =
|
|
27
|
-
export var UPDATE_GROUP =
|
|
28
|
-
export var UPDATE_COUNT_NOT_READ_CONVERSATION =
|
|
29
|
-
export var UPDATE_CONVERSATIONS =
|
|
30
|
-
export var SET_FILTERS =
|
|
31
|
-
export var HAS_ERROR =
|
|
32
|
-
export var IS_LOADING =
|
|
33
|
-
export var LOGOUT =
|
|
34
|
-
export var SET_CONTAINER_OPEN =
|
|
35
|
-
export var SET_CHAT_MODAL_PREVIEW =
|
|
11
|
+
export var SET_CHAT_LIST_VISIBILITY = "chat/SET_CHAT_LIST_VISIBILITY";
|
|
12
|
+
export var SET_SEARCH_MESSAGE = "chat/SET_SEARCH_MESSAGE";
|
|
13
|
+
export var SET_MARK_POSITION_ID = "chat/SET_MARK_POSITION_ID";
|
|
14
|
+
export var CLEAR_SEARCH_MESSAGE = "chat/CLEAR_SEARCH_MESSAGE";
|
|
15
|
+
export var OPEN_CONVERSATION = "chat/OPEN_CONVERSATION";
|
|
16
|
+
export var CLOSE_CONVERSATION = "chat/CLOSE_CONVERSATION";
|
|
17
|
+
export var SUCCESS_CONVERSATIONS = "chat/SUCCESS_CONVERSATIONS";
|
|
18
|
+
export var SUCCESS_CONVERSATION = "chat/SUCCESS_CONVERSATION";
|
|
19
|
+
export var SUCCESS_MESSAGES = "chat/SUCCESS_MESSAGES";
|
|
20
|
+
export var ADD_MESSAGE = "chat/ADD_MESSAGE";
|
|
21
|
+
export var UPDATE_CONVERSATION = "chat/UPDATE_CONVERSATION";
|
|
22
|
+
export var UPDATE_USERS = "chat/UPDATE_USERS";
|
|
23
|
+
export var UPDATE_MESSAGES = "chat/UPDATE_MESSAGES";
|
|
24
|
+
export var UPDATE_MESSAGE = "chat/UPDATE_MESSAGE";
|
|
25
|
+
export var UPDATE_MESSAGE_BY_MESSAGE_ID = "chat/UPDATE_MESSAGE_BY_MESSAGE_ID";
|
|
26
|
+
export var UPDATE_GROUP = "chat/UPDATE_GROUP";
|
|
27
|
+
export var UPDATE_COUNT_NOT_READ_CONVERSATION = "chat/UPDATE_COUNT_NOT_READ_CONVERSATION";
|
|
28
|
+
export var UPDATE_CONVERSATIONS = "chat/UPDATE_CONVERSATIONS";
|
|
29
|
+
export var SET_FILTERS = "chat/SET_FILTERS";
|
|
30
|
+
export var HAS_ERROR = "chat/HAS_ERROR";
|
|
31
|
+
export var IS_LOADING = "chat/IS_LOADING";
|
|
32
|
+
export var LOGOUT = "chat/LOGOUT";
|
|
33
|
+
export var SET_CONTAINER_OPEN = "chat/SET_CONTAINER_OPEN";
|
|
34
|
+
export var SET_CHAT_MODAL_PREVIEW = "chat/SET_CHAT_MODAL_PREVIEW";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ChatConstants } from "../constants";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
function getCanSendToSuperiors(chat, chatPermissions, quitedGroup, identification, userHierarchy) {
|
|
4
|
+
if (quitedGroup ||
|
|
5
|
+
!chatPermissions.canSendToSuperiors ||
|
|
6
|
+
chatPermissions.canSend) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (chat.users) {
|
|
10
|
+
for (var _i = 0, _a = chat.users; _i < _a.length; _i++) {
|
|
11
|
+
var user = _a[_i];
|
|
12
|
+
if (identification !== user.identification &&
|
|
13
|
+
user.active &&
|
|
14
|
+
!user.deleted &&
|
|
15
|
+
user.isUserActive &&
|
|
16
|
+
user.hierarchyLevel) {
|
|
17
|
+
if (userHierarchy && userHierarchy < user.hierarchyLevel) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
function getIsParentImmediateInChatAndCanSend(chat, chatPermissions, quitedGroup, parentImmediate) {
|
|
26
|
+
if (quitedGroup ||
|
|
27
|
+
!chatPermissions.canSendToParentImmediate ||
|
|
28
|
+
chatPermissions.canSend ||
|
|
29
|
+
!parentImmediate ||
|
|
30
|
+
!chat.users) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return chat.users.some(function (user) {
|
|
34
|
+
return user.identification === parentImmediate &&
|
|
35
|
+
user.active &&
|
|
36
|
+
!user.deleted &&
|
|
37
|
+
user.isUserActive;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function checkNotInGroup(chat, identification) {
|
|
41
|
+
var _a;
|
|
42
|
+
var user = (_a = chat.users) === null || _a === void 0 ? void 0 : _a.find(function (user) { return user.identification === identification; });
|
|
43
|
+
var quitedGroup = chat.type !== ChatConstants.TYPE_CHAT.GROUP
|
|
44
|
+
? false
|
|
45
|
+
: !(user === null || user === void 0 ? void 0 : user.active) || user.deleted;
|
|
46
|
+
return quitedGroup;
|
|
47
|
+
}
|
|
48
|
+
export function checkIfUserIsSingleAdmin(identification, group) {
|
|
49
|
+
if (!group || !group.users || group.users.length === 0 || !identification)
|
|
50
|
+
return false;
|
|
51
|
+
var isAdmin = false;
|
|
52
|
+
var adminCount = 0;
|
|
53
|
+
for (var _i = 0, _a = group.users; _i < _a.length; _i++) {
|
|
54
|
+
var user = _a[_i];
|
|
55
|
+
if (user.identification === identification) {
|
|
56
|
+
isAdmin = user.admin;
|
|
57
|
+
}
|
|
58
|
+
if (user.admin) {
|
|
59
|
+
adminCount++;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return isAdmin && adminCount === 1;
|
|
63
|
+
}
|
|
64
|
+
export function getChatName(chat) {
|
|
65
|
+
var _a;
|
|
66
|
+
return chat.type !== ChatConstants.TYPE_CHAT.GROUP
|
|
67
|
+
? _.startCase((_a = chat.name) === null || _a === void 0 ? void 0 : _a.toLowerCase())
|
|
68
|
+
: chat.name;
|
|
69
|
+
}
|
|
70
|
+
export function getPlaceholderMessage(canSendMessages, isActive) {
|
|
71
|
+
if (!isActive)
|
|
72
|
+
return "inactive_user";
|
|
73
|
+
if (!canSendMessages)
|
|
74
|
+
return "chat_type_your_message_no_permission";
|
|
75
|
+
return "chat_type_your_message";
|
|
76
|
+
}
|
|
77
|
+
export function generateMessageTempId() {
|
|
78
|
+
var timestamp = Date.now().toString(36);
|
|
79
|
+
var randomNum = Math.random().toString(36).substring(2, 8);
|
|
80
|
+
return "".concat(timestamp, "-").concat(randomNum);
|
|
81
|
+
}
|
|
82
|
+
export var ChatUtils = {
|
|
83
|
+
getCanSendToSuperiors: getCanSendToSuperiors,
|
|
84
|
+
getIsParentImmediateInChatAndCanSend: getIsParentImmediateInChatAndCanSend,
|
|
85
|
+
checkNotInGroup: checkNotInGroup,
|
|
86
|
+
checkIfUserIsSingleAdmin: checkIfUserIsSingleAdmin,
|
|
87
|
+
getChatName: getChatName,
|
|
88
|
+
getPlaceholderMessage: getPlaceholderMessage,
|
|
89
|
+
generateMessageTempId: generateMessageTempId,
|
|
90
|
+
};
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export enum
|
|
1
|
+
export enum TYPE_CHAT {
|
|
2
2
|
CHAT = "chat",
|
|
3
3
|
GROUP = "group",
|
|
4
4
|
GROUPS = "groups",
|
|
5
5
|
CHATBOT = "chat-bot",
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export enum
|
|
8
|
+
export enum CHAT_CLASSIFICATION {
|
|
9
9
|
TREE_MESSAGE = "tree-message",
|
|
10
10
|
ANGEL_FRIEND = "angel-friend",
|
|
11
11
|
}
|
|
@@ -24,9 +24,16 @@ const ALLOWED_EXTENSIONS = new Set([
|
|
|
24
24
|
"pptx",
|
|
25
25
|
]);
|
|
26
26
|
|
|
27
|
+
export enum MEETINGS_SIDEBAR_OPTIONS {
|
|
28
|
+
PARTICIPANTS = "participants",
|
|
29
|
+
CHAT = "chat",
|
|
30
|
+
MENU = "menu",
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
export const ChatConstants = {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
TYPE_CHAT,
|
|
35
|
+
CHAT_CLASSIFICATION,
|
|
30
36
|
ALLOWED_EXTENSIONS,
|
|
31
37
|
IMAGE_EXTENSIONS,
|
|
38
|
+
MEETINGS_SIDEBAR_OPTIONS,
|
|
32
39
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseRepositoryModel } from "./base.repository.model";
|
|
2
2
|
import { IProfileImageProps } from "../components/profile-image/profile-image.interface";
|
|
3
3
|
import { IBaseComponentProp } from "../components/base-component.prop.interface";
|
|
4
|
-
import {
|
|
4
|
+
import { CHAT_CLASSIFICATION } from "../constants";
|
|
5
5
|
|
|
6
6
|
export class AngelFriendStatusModel extends BaseRepositoryModel {
|
|
7
7
|
configuration: IConfiguration;
|
|
@@ -186,7 +186,7 @@ export interface IAngelFriendProfileImageProps
|
|
|
186
186
|
extends IProfileImageProps,
|
|
187
187
|
IBaseComponentProp {
|
|
188
188
|
robbysonUserId?: number;
|
|
189
|
-
classification?:
|
|
189
|
+
classification?: CHAT_CLASSIFICATION | "";
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
export interface INotification {
|
package/src/models/chat.model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CHAT_CLASSIFICATION, TYPE_CHAT } from "../constants";
|
|
2
2
|
import { UserListModel } from "./user-list.model";
|
|
3
3
|
|
|
4
4
|
export class ChatModel {
|
|
@@ -9,7 +9,7 @@ export class ChatModel {
|
|
|
9
9
|
name: string;
|
|
10
10
|
names?: string[];
|
|
11
11
|
temporary?: boolean;
|
|
12
|
-
type?:
|
|
12
|
+
type?: TYPE_CHAT;
|
|
13
13
|
users?: ChatUser[];
|
|
14
14
|
_id: string;
|
|
15
15
|
id?: string;
|
|
@@ -22,7 +22,7 @@ export class ChatModel {
|
|
|
22
22
|
admin?: boolean;
|
|
23
23
|
active?: boolean;
|
|
24
24
|
deleted?: boolean;
|
|
25
|
-
classification?:
|
|
25
|
+
classification?: CHAT_CLASSIFICATION;
|
|
26
26
|
isUserActive?: boolean;
|
|
27
27
|
lastUpdatedBy?: string;
|
|
28
28
|
lastUpdatedAt?: Date;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CHAT_CLASSIFICATION } from "../constants";
|
|
2
2
|
import { BaseRepositoryModel } from "./base.repository.model";
|
|
3
3
|
import { ChatUser } from "./chat.model";
|
|
4
4
|
|
|
@@ -26,7 +26,7 @@ export class UserListModel extends BaseRepositoryModel {
|
|
|
26
26
|
profileImage?: string;
|
|
27
27
|
users?: ChatUser[];
|
|
28
28
|
countNotRead?: number;
|
|
29
|
-
classification?:
|
|
29
|
+
classification?: CHAT_CLASSIFICATION;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
interface System {
|
|
@@ -21,7 +21,7 @@ export * from "./configuration.repository.interface";
|
|
|
21
21
|
export * from "./hierarchy.repository.interface";
|
|
22
22
|
export * from "./profile.repository.interface";
|
|
23
23
|
export * from "./tips.repository.interface";
|
|
24
|
-
export * from "./goal.repository.interface"
|
|
24
|
+
export * from "./goal.repository.interface";
|
|
25
25
|
export * from "./campaign.repository.interface";
|
|
26
26
|
export * from "./indicator.repository.interface";
|
|
27
27
|
export * from "./currency.repository.interface";
|
|
@@ -33,4 +33,4 @@ export * from "./module.repository.interface";
|
|
|
33
33
|
export * from "./portal-dashboard.repository.interface";
|
|
34
34
|
export * from "./socket.repository.interface";
|
|
35
35
|
export * from "./sounds.repository.interface";
|
|
36
|
-
export * from "./contractor.repository.interface";
|
|
36
|
+
export * from "./contractor.repository.interface";
|
|
@@ -50,13 +50,22 @@ export interface IChatService {
|
|
|
50
50
|
getMemberSidebar(): ChatDTO.IMemberSidebar;
|
|
51
51
|
setMemberSidebar(data: ChatDTO.IMemberSidebar): void;
|
|
52
52
|
getMessages(
|
|
53
|
-
|
|
53
|
+
chat: ChatModel,
|
|
54
54
|
params: ChatDTO.IGetMessagesDTO
|
|
55
|
-
): Promise<
|
|
55
|
+
): Promise<ChatDTO.IChatFormattedMessage[]>;
|
|
56
56
|
decryptConversationMessage(text: string, chat: ChatModel): string;
|
|
57
57
|
clearMessages(message: ChatDTO.IClearMessages): void;
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
setMessageError(conversationId: string, temp_id: string): void;
|
|
59
|
+
sendMessage(
|
|
60
|
+
newMessage: ChatDTO.INewMessageInterface,
|
|
61
|
+
temp_id: string
|
|
62
|
+
): Promise<void>;
|
|
63
|
+
sendFile(
|
|
64
|
+
file: File,
|
|
65
|
+
fileExtension: string,
|
|
66
|
+
newMessage: ChatDTO.INewMessageInterface,
|
|
67
|
+
temp_id: string
|
|
68
|
+
): Promise<void>;
|
|
60
69
|
clearConversation(conversationId: string): Promise<void>;
|
|
61
70
|
setFavoriteMessage(
|
|
62
71
|
conversationId: string,
|
|
@@ -76,8 +85,14 @@ export interface IChatService {
|
|
|
76
85
|
user: UserDTO.GetUserDTO
|
|
77
86
|
): Promise<void>;
|
|
78
87
|
addMessage(message: ChatDTO.ISubscribeMessage): void;
|
|
79
|
-
updateUsers(message: {
|
|
80
|
-
|
|
88
|
+
updateUsers(message: {
|
|
89
|
+
conversation_id: string;
|
|
90
|
+
identification: string;
|
|
91
|
+
}): Promise<void>;
|
|
92
|
+
updateGroup(message: {
|
|
93
|
+
conversation_id: string;
|
|
94
|
+
identification: string;
|
|
95
|
+
}): Promise<void>;
|
|
81
96
|
getConversationSidebar(): ChatDTO.IConversationDTO;
|
|
82
97
|
setConversationSidebar(payload: ChatDTO.IConversationDTO): void;
|
|
83
98
|
sendBroadcast(
|
|
@@ -104,4 +119,9 @@ export interface IChatService {
|
|
|
104
119
|
avoidCheckUserInCall?: boolean
|
|
105
120
|
): Promise<void>;
|
|
106
121
|
updateMessage(payload: MessageModel): Promise<MessageModel>;
|
|
122
|
+
getStateMessages(conversationId: string): ChatDTO.IStateMessages;
|
|
123
|
+
canSendMessages(chat: ChatModel): Promise<boolean>;
|
|
124
|
+
canSendFiles(canSendMessages: boolean): boolean;
|
|
125
|
+
isChatPage(conversationId?: string): boolean;
|
|
126
|
+
getCurrentConversations(search?: string): ChatModel[];
|
|
107
127
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CHAT_CLASSIFICATION, TYPE_CHAT } from "../../constants";
|
|
2
2
|
import { ChatModel, MessageModel, UserListModel } from "../../models";
|
|
3
3
|
import { GetUserDTO } from "./user.dto";
|
|
4
4
|
|
|
@@ -22,7 +22,7 @@ export interface ICreateConversationDTO {
|
|
|
22
22
|
temporary?: boolean;
|
|
23
23
|
photo?: string;
|
|
24
24
|
admin?: boolean;
|
|
25
|
-
classification?:
|
|
25
|
+
classification?: CHAT_CLASSIFICATION;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface IUpdateGroupDTO {
|
|
@@ -32,7 +32,7 @@ export interface IUpdateGroupDTO {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export interface IUpdateClassificationDTO {
|
|
35
|
-
classification:
|
|
35
|
+
classification: CHAT_CLASSIFICATION;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface IChatPermissions {
|
|
@@ -68,14 +68,14 @@ export interface RequestPayload {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export interface IGetMessagesDTO {
|
|
71
|
-
page
|
|
72
|
-
per
|
|
71
|
+
page: number;
|
|
72
|
+
per: number;
|
|
73
73
|
search?: string;
|
|
74
74
|
name?: string;
|
|
75
75
|
identification?: string;
|
|
76
76
|
classification?: string;
|
|
77
77
|
favorite?: boolean;
|
|
78
|
-
type?:
|
|
78
|
+
type?: TYPE_CHAT;
|
|
79
79
|
append?: boolean;
|
|
80
80
|
direction?: string;
|
|
81
81
|
}
|
|
@@ -125,7 +125,7 @@ export interface IChatBotFormattedMessage {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
export interface IChatFormattedMessage extends MessageModel {
|
|
128
|
-
|
|
128
|
+
temp_id?: string;
|
|
129
129
|
uncryptedText?: string;
|
|
130
130
|
content: string;
|
|
131
131
|
from: "me" | "other";
|
|
@@ -161,7 +161,8 @@ export interface IConversationDTO extends Partial<ChatModel> {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
export interface IChatMessages {
|
|
164
|
-
data:
|
|
164
|
+
data: IChatFormattedMessage[];
|
|
165
|
+
hasMoreResults: boolean;
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
export interface IChatListSidebar {
|
|
@@ -186,6 +187,29 @@ export interface ISubscribeMessage {
|
|
|
186
187
|
conversation?: ChatModel;
|
|
187
188
|
}
|
|
188
189
|
|
|
190
|
+
export interface ISetChatMessages {
|
|
191
|
+
conversations?: ChatModel[];
|
|
192
|
+
chatMessages: { [conversationId: string]: IChatMessages };
|
|
193
|
+
countNotRead?: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface INewChatMessage {
|
|
197
|
+
conversations: ChatModel[];
|
|
198
|
+
chatMessages: { [conversationId: string]: IChatMessages };
|
|
199
|
+
smallChats?: ISmallChat[];
|
|
200
|
+
countNotRead?: number;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface IStateMessages {
|
|
204
|
+
messages: IChatFormattedMessage[];
|
|
205
|
+
hasMoreResults: boolean;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface INewMessageInterface {
|
|
209
|
+
text: string;
|
|
210
|
+
chat: ChatModel;
|
|
211
|
+
}
|
|
212
|
+
|
|
189
213
|
export interface IUpdatedUsers {
|
|
190
214
|
conversation_id: string;
|
|
191
215
|
user: ChatModel;
|
|
@@ -198,4 +222,5 @@ export interface IUpdatedGroup {
|
|
|
198
222
|
|
|
199
223
|
export interface IClearMessages {
|
|
200
224
|
conversation_id: string;
|
|
225
|
+
identification: string;
|
|
201
226
|
}
|
|
@@ -3,11 +3,9 @@ import { ChatDTO } from "../../services";
|
|
|
3
3
|
|
|
4
4
|
export interface IChatApp {
|
|
5
5
|
activeConversations: {
|
|
6
|
-
conversation_id: string
|
|
6
|
+
conversation_id: string;
|
|
7
7
|
}[];
|
|
8
|
-
chatListSideBar:
|
|
9
|
-
isOpen: boolean;
|
|
10
|
-
};
|
|
8
|
+
chatListSideBar: ChatDTO.IChatListSidebar;
|
|
11
9
|
smallChats: ChatDTO.ISmallChat[];
|
|
12
10
|
profileSideBar: {
|
|
13
11
|
isOpen: boolean;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TYPE_CHAT } from "../../constants";
|
|
2
2
|
|
|
3
3
|
export enum Classification {
|
|
4
|
-
tree_message =
|
|
5
|
-
angel_friend =
|
|
6
|
-
}
|
|
4
|
+
tree_message = "tree-message",
|
|
5
|
+
angel_friend = "angel-friend",
|
|
6
|
+
}
|
|
7
7
|
|
|
8
8
|
export enum MessagesType {
|
|
9
|
-
ALL =
|
|
10
|
-
FAVORITE =
|
|
9
|
+
ALL = "all",
|
|
10
|
+
FAVORITE = "fav",
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type Parameters = {
|
|
@@ -18,8 +18,8 @@ export type Parameters = {
|
|
|
18
18
|
identification?: string;
|
|
19
19
|
classification?: string;
|
|
20
20
|
favorite?: boolean;
|
|
21
|
-
type?:
|
|
22
|
-
}
|
|
21
|
+
type?: TYPE_CHAT;
|
|
22
|
+
};
|
|
23
23
|
|
|
24
24
|
export type PaginationParams = {
|
|
25
25
|
pages: number[];
|
|
@@ -28,19 +28,19 @@ export type PaginationParams = {
|
|
|
28
28
|
per: number;
|
|
29
29
|
markPositionId?: number;
|
|
30
30
|
favorite?: boolean;
|
|
31
|
-
}
|
|
31
|
+
};
|
|
32
32
|
|
|
33
33
|
export type SearchMessageDTO = {
|
|
34
34
|
page?: number;
|
|
35
35
|
per?: number;
|
|
36
36
|
searchMessage: string;
|
|
37
37
|
pagesParam?: number[];
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
|
|
40
40
|
export type ColorsGroup = {
|
|
41
41
|
primary: string;
|
|
42
42
|
secondary: string;
|
|
43
|
-
}
|
|
43
|
+
};
|
|
44
44
|
|
|
45
45
|
export type UserChatDTO = {
|
|
46
46
|
name?: string;
|
|
@@ -77,13 +77,13 @@ export type User = {
|
|
|
77
77
|
color?: string;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
export type ConversationWindowSize =
|
|
80
|
+
export type ConversationWindowSize = "minimized" | "normal" | "fullscreen";
|
|
81
81
|
|
|
82
82
|
export type Conversation = {
|
|
83
83
|
_id: string;
|
|
84
84
|
name: string;
|
|
85
85
|
description: string;
|
|
86
|
-
type:
|
|
86
|
+
type: TYPE_CHAT;
|
|
87
87
|
colors: ColorsGroup;
|
|
88
88
|
users: User[];
|
|
89
89
|
countNotRead: number;
|
|
@@ -93,34 +93,34 @@ export type Conversation = {
|
|
|
93
93
|
windowSize: ConversationWindowSize;
|
|
94
94
|
opened: boolean;
|
|
95
95
|
openedAt: Date;
|
|
96
|
-
}
|
|
96
|
+
};
|
|
97
97
|
|
|
98
98
|
export type ConversationDTO = {
|
|
99
99
|
name?: string;
|
|
100
100
|
description?: string;
|
|
101
|
-
type?:
|
|
101
|
+
type?: TYPE_CHAT;
|
|
102
102
|
users?: UserChatDTO[];
|
|
103
103
|
temporary?: boolean;
|
|
104
104
|
photo?: string;
|
|
105
|
-
}
|
|
105
|
+
};
|
|
106
106
|
|
|
107
107
|
export type UpdateGroupDTO = {
|
|
108
108
|
name?: string;
|
|
109
109
|
description?: string;
|
|
110
110
|
photo?: string;
|
|
111
|
-
}
|
|
111
|
+
};
|
|
112
112
|
|
|
113
113
|
export type Conversations = {
|
|
114
114
|
data: Conversation[];
|
|
115
115
|
meta: Meta;
|
|
116
|
-
}
|
|
116
|
+
};
|
|
117
117
|
|
|
118
|
-
export type File ={
|
|
118
|
+
export type File = {
|
|
119
119
|
fileName: string;
|
|
120
120
|
attachment: string;
|
|
121
121
|
publicUrl: string;
|
|
122
122
|
fileType: string;
|
|
123
|
-
}
|
|
123
|
+
};
|
|
124
124
|
|
|
125
125
|
export type Message = {
|
|
126
126
|
conversation_id: string;
|
|
@@ -130,15 +130,15 @@ export type Message = {
|
|
|
130
130
|
_id?: string;
|
|
131
131
|
message_id?: string;
|
|
132
132
|
receiver?: string;
|
|
133
|
-
favorite?: boolean
|
|
134
|
-
hidden?: boolean
|
|
135
|
-
temp?: boolean
|
|
133
|
+
favorite?: boolean;
|
|
134
|
+
hidden?: boolean;
|
|
135
|
+
temp?: boolean;
|
|
136
136
|
temp_id?: string;
|
|
137
137
|
readAt?: Date;
|
|
138
138
|
sendedAt?: Date;
|
|
139
139
|
sentAt?: Date;
|
|
140
140
|
file?: File;
|
|
141
|
-
}
|
|
141
|
+
};
|
|
142
142
|
|
|
143
143
|
export type MessageDTO = {
|
|
144
144
|
conversation_id?: string;
|
|
@@ -148,9 +148,9 @@ export type MessageDTO = {
|
|
|
148
148
|
receivedAt?: Date;
|
|
149
149
|
temp_id?: string;
|
|
150
150
|
temp?: boolean;
|
|
151
|
-
file?: File
|
|
151
|
+
file?: File;
|
|
152
152
|
_id?: string;
|
|
153
|
-
}
|
|
153
|
+
};
|
|
154
154
|
|
|
155
155
|
export type Meta = {
|
|
156
156
|
page?: number;
|
|
@@ -159,12 +159,12 @@ export type Meta = {
|
|
|
159
159
|
totalDocs?: number;
|
|
160
160
|
type?: string;
|
|
161
161
|
favorite?: boolean;
|
|
162
|
-
}
|
|
162
|
+
};
|
|
163
163
|
|
|
164
164
|
export type Messages = {
|
|
165
165
|
data: Message[];
|
|
166
166
|
meta: Meta;
|
|
167
|
-
}
|
|
167
|
+
};
|
|
168
168
|
export interface State {
|
|
169
169
|
data: {
|
|
170
170
|
isChatListVisible: boolean;
|
|
@@ -186,27 +186,28 @@ export interface State {
|
|
|
186
186
|
isLoading: boolean;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
export const SET_CHAT_LIST_VISIBILITY =
|
|
190
|
-
export const SET_SEARCH_MESSAGE =
|
|
191
|
-
export const SET_MARK_POSITION_ID =
|
|
192
|
-
export const CLEAR_SEARCH_MESSAGE =
|
|
193
|
-
export const OPEN_CONVERSATION =
|
|
194
|
-
export const CLOSE_CONVERSATION =
|
|
195
|
-
export const SUCCESS_CONVERSATIONS =
|
|
196
|
-
export const SUCCESS_CONVERSATION =
|
|
197
|
-
export const SUCCESS_MESSAGES =
|
|
198
|
-
export const ADD_MESSAGE =
|
|
199
|
-
export const UPDATE_CONVERSATION =
|
|
200
|
-
export const UPDATE_USERS =
|
|
201
|
-
export const UPDATE_MESSAGES =
|
|
202
|
-
export const UPDATE_MESSAGE =
|
|
203
|
-
export const UPDATE_MESSAGE_BY_MESSAGE_ID =
|
|
204
|
-
export const UPDATE_GROUP =
|
|
205
|
-
export const UPDATE_COUNT_NOT_READ_CONVERSATION =
|
|
206
|
-
|
|
207
|
-
export const
|
|
208
|
-
export const
|
|
209
|
-
export const
|
|
210
|
-
export const
|
|
211
|
-
export const
|
|
212
|
-
export const
|
|
189
|
+
export const SET_CHAT_LIST_VISIBILITY = "chat/SET_CHAT_LIST_VISIBILITY";
|
|
190
|
+
export const SET_SEARCH_MESSAGE = "chat/SET_SEARCH_MESSAGE";
|
|
191
|
+
export const SET_MARK_POSITION_ID = "chat/SET_MARK_POSITION_ID";
|
|
192
|
+
export const CLEAR_SEARCH_MESSAGE = "chat/CLEAR_SEARCH_MESSAGE";
|
|
193
|
+
export const OPEN_CONVERSATION = "chat/OPEN_CONVERSATION";
|
|
194
|
+
export const CLOSE_CONVERSATION = "chat/CLOSE_CONVERSATION";
|
|
195
|
+
export const SUCCESS_CONVERSATIONS = "chat/SUCCESS_CONVERSATIONS";
|
|
196
|
+
export const SUCCESS_CONVERSATION = "chat/SUCCESS_CONVERSATION";
|
|
197
|
+
export const SUCCESS_MESSAGES = "chat/SUCCESS_MESSAGES";
|
|
198
|
+
export const ADD_MESSAGE = "chat/ADD_MESSAGE";
|
|
199
|
+
export const UPDATE_CONVERSATION = "chat/UPDATE_CONVERSATION";
|
|
200
|
+
export const UPDATE_USERS = "chat/UPDATE_USERS";
|
|
201
|
+
export const UPDATE_MESSAGES = "chat/UPDATE_MESSAGES";
|
|
202
|
+
export const UPDATE_MESSAGE = "chat/UPDATE_MESSAGE";
|
|
203
|
+
export const UPDATE_MESSAGE_BY_MESSAGE_ID = "chat/UPDATE_MESSAGE_BY_MESSAGE_ID";
|
|
204
|
+
export const UPDATE_GROUP = "chat/UPDATE_GROUP";
|
|
205
|
+
export const UPDATE_COUNT_NOT_READ_CONVERSATION =
|
|
206
|
+
"chat/UPDATE_COUNT_NOT_READ_CONVERSATION";
|
|
207
|
+
export const UPDATE_CONVERSATIONS = "chat/UPDATE_CONVERSATIONS";
|
|
208
|
+
export const SET_FILTERS = "chat/SET_FILTERS";
|
|
209
|
+
export const HAS_ERROR = "chat/HAS_ERROR";
|
|
210
|
+
export const IS_LOADING = "chat/IS_LOADING";
|
|
211
|
+
export const LOGOUT = "chat/LOGOUT";
|
|
212
|
+
export const SET_CONTAINER_OPEN = "chat/SET_CONTAINER_OPEN";
|
|
213
|
+
export const SET_CHAT_MODAL_PREVIEW = "chat/SET_CHAT_MODAL_PREVIEW";
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ChatDTO } from "../services";
|
|
2
|
+
import { ChatModel } from "../models";
|
|
3
|
+
import { ChatConstants } from "../constants";
|
|
4
|
+
import _ from "lodash";
|
|
5
|
+
|
|
6
|
+
function getCanSendToSuperiors(
|
|
7
|
+
chat: ChatModel,
|
|
8
|
+
chatPermissions: ChatDTO.IChatPermissions,
|
|
9
|
+
quitedGroup: boolean,
|
|
10
|
+
identification: string,
|
|
11
|
+
userHierarchy: number
|
|
12
|
+
): boolean {
|
|
13
|
+
if (
|
|
14
|
+
quitedGroup ||
|
|
15
|
+
!chatPermissions.canSendToSuperiors ||
|
|
16
|
+
chatPermissions.canSend
|
|
17
|
+
) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (chat.users) {
|
|
22
|
+
for (const user of chat.users) {
|
|
23
|
+
if (
|
|
24
|
+
identification !== user.identification &&
|
|
25
|
+
user.active &&
|
|
26
|
+
!user.deleted &&
|
|
27
|
+
user.isUserActive &&
|
|
28
|
+
user.hierarchyLevel
|
|
29
|
+
) {
|
|
30
|
+
if (userHierarchy && userHierarchy < user.hierarchyLevel) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getIsParentImmediateInChatAndCanSend(
|
|
41
|
+
chat: ChatModel,
|
|
42
|
+
chatPermissions: ChatDTO.IChatPermissions,
|
|
43
|
+
quitedGroup: boolean,
|
|
44
|
+
parentImmediate: string
|
|
45
|
+
): boolean {
|
|
46
|
+
if (
|
|
47
|
+
quitedGroup ||
|
|
48
|
+
!chatPermissions.canSendToParentImmediate ||
|
|
49
|
+
chatPermissions.canSend ||
|
|
50
|
+
!parentImmediate ||
|
|
51
|
+
!chat.users
|
|
52
|
+
) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return chat.users.some(
|
|
57
|
+
(user) =>
|
|
58
|
+
user.identification === parentImmediate &&
|
|
59
|
+
user.active &&
|
|
60
|
+
!user.deleted &&
|
|
61
|
+
user.isUserActive
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function checkNotInGroup(chat: ChatModel, identification: string): boolean {
|
|
66
|
+
const user = chat.users?.find(
|
|
67
|
+
(user) => user.identification === identification
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const quitedGroup =
|
|
71
|
+
chat.type !== ChatConstants.TYPE_CHAT.GROUP
|
|
72
|
+
? false
|
|
73
|
+
: !user?.active || user.deleted;
|
|
74
|
+
|
|
75
|
+
return quitedGroup;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function checkIfUserIsSingleAdmin(
|
|
79
|
+
identification: string,
|
|
80
|
+
group?: ChatModel
|
|
81
|
+
): boolean {
|
|
82
|
+
if (!group || !group.users || group.users.length === 0 || !identification)
|
|
83
|
+
return false;
|
|
84
|
+
|
|
85
|
+
let isAdmin = false;
|
|
86
|
+
let adminCount = 0;
|
|
87
|
+
|
|
88
|
+
for (const user of group.users) {
|
|
89
|
+
if (user.identification === identification) {
|
|
90
|
+
isAdmin = user.admin;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (user.admin) {
|
|
94
|
+
adminCount++;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return isAdmin && adminCount === 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function getChatName(chat: ChatModel): string {
|
|
102
|
+
return chat.type !== ChatConstants.TYPE_CHAT.GROUP
|
|
103
|
+
? _.startCase(chat.name?.toLowerCase())
|
|
104
|
+
: chat.name;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function getPlaceholderMessage(
|
|
108
|
+
canSendMessages: boolean,
|
|
109
|
+
isActive: boolean
|
|
110
|
+
): string {
|
|
111
|
+
if (!isActive) return "inactive_user";
|
|
112
|
+
|
|
113
|
+
if (!canSendMessages) return "chat_type_your_message_no_permission";
|
|
114
|
+
|
|
115
|
+
return "chat_type_your_message";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function generateMessageTempId(): string {
|
|
119
|
+
const timestamp = Date.now().toString(36);
|
|
120
|
+
const randomNum = Math.random().toString(36).substring(2, 8);
|
|
121
|
+
return `${timestamp}-${randomNum}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const ChatUtils = {
|
|
125
|
+
getCanSendToSuperiors,
|
|
126
|
+
getIsParentImmediateInChatAndCanSend,
|
|
127
|
+
checkNotInGroup,
|
|
128
|
+
checkIfUserIsSingleAdmin,
|
|
129
|
+
getChatName,
|
|
130
|
+
getPlaceholderMessage,
|
|
131
|
+
generateMessageTempId,
|
|
132
|
+
};
|
package/src/utils/index.ts
CHANGED