@webitel/ui-sdk 24.8.31 → 24.8.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-sdk",
3
- "version": "24.8.31",
3
+ "version": "24.8.33",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -1,9 +1,12 @@
1
1
  import {
2
- getDefaultInstance, getDefaultOpenAPIConfig,
2
+ getDefaultInstance,
3
+ getDefaultOpenAPIConfig,
4
+ getDefaultGetListResponse,
3
5
  } from '../defaults/index.js';
4
6
  import applyTransform, {
5
7
  notify,
6
8
  snakeToCamel,
9
+ merge,
7
10
  } from '../transformers/index.js';
8
11
  import { ContactsChatCatalogApiFactory } from 'webitel-sdk';
9
12
 
@@ -12,8 +15,8 @@ const configuration = getDefaultOpenAPIConfig();
12
15
 
13
16
  const contactChatService = new ContactsChatCatalogApiFactory(configuration, '', instance);
14
17
 
15
- const getList = async ({ contactId, chatId }) => {
16
- const mergeChatMessagesData = ({ peers, messages }) => {
18
+ const getChat = async ({ contactId, chatId }) => {
19
+ const mergeChatMessagesData = ({ messages, peers }) => {
17
20
  return messages.map(({ from, ...message }) => {
18
21
  return {
19
22
  ...message,
@@ -24,11 +27,11 @@ const getList = async ({ contactId, chatId }) => {
24
27
 
25
28
  try {
26
29
  const response = await contactChatService.getContactChatHistory(contactId, chatId);
27
- const { peers, messages } = applyTransform(response.data, [
30
+ const { messages, peers } = applyTransform(response.data, [
28
31
  snakeToCamel(),
29
32
  ]);
30
33
  return {
31
- items: applyTransform({ peers, messages }, [
34
+ items: applyTransform({ messages, peers }, [
32
35
  mergeChatMessagesData,
33
36
  ]).reverse(),
34
37
  };
@@ -39,6 +42,39 @@ const getList = async ({ contactId, chatId }) => {
39
42
  }
40
43
  };
41
44
 
45
+ // all messages from all contacts chats
46
+ const getAllMessages = async ({ id }) => {
47
+ const mergeMessagesData = ({ messages, peers, chats }) => {
48
+ return messages.map(({ from, chat, ...message }) => {
49
+ return {
50
+ ...message,
51
+ peer: peers[from.id - 1],
52
+ chat: chats[chat.id - 1],
53
+ };
54
+ });
55
+ };
56
+
57
+ try {
58
+ const response = await contactChatService.getContactChatHistory2(id);
59
+ const { messages, peers, chats, next } = applyTransform(response.data, [
60
+ snakeToCamel(),
61
+ merge(getDefaultGetListResponse()),
62
+ ]);
63
+ return {
64
+ items: applyTransform({ messages, peers, chats }, [
65
+ mergeMessagesData,
66
+ ]).reverse(),
67
+ next,
68
+ };
69
+ } catch (err) {
70
+ throw applyTransform(err, [
71
+ notify,
72
+ ]);
73
+ }
74
+
75
+ };
76
+
42
77
  export default {
43
- getList,
78
+ getChat,
79
+ getAllMessages,
44
80
  };