@phonghq/go-chat 1.0.67 → 1.0.69

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.
@@ -103,7 +103,7 @@ const handleExposeInit = (init_data) => {
103
103
  if (init_data?.conversation_id) {
104
104
  chatListRef.value?.initData({
105
105
  conversation_id: data?.conversation_id,
106
- is_unknown: data?.is_unknown || '0'
106
+ is_known: data?.is_known || 1
107
107
  });
108
108
  }
109
109
  else
@@ -215,7 +215,6 @@ defineExpose({
215
215
  await callingRef.value?.answer();
216
216
  },
217
217
  endCall: () => {
218
- console.log('9999999999999999999999999999999');
219
218
  callingRef.value?.endCall();
220
219
  },
221
220
  openSettings,
@@ -9,7 +9,7 @@ type __VLS_ModelProps = {
9
9
  };
10
10
  type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
11
11
  declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
12
- handleReadMessage: () => void;
12
+ handleReadMessage: (receiver_id_request?: number | undefined) => void;
13
13
  listConversationsAll: import("vue").Ref<{
14
14
  id: number;
15
15
  receiver_id: number;
@@ -23,7 +23,7 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
23
23
  unread_count: number;
24
24
  status: number;
25
25
  color: string;
26
- is_unknown: number;
26
+ is_known: number;
27
27
  customer_id?: number | undefined;
28
28
  tenant_id?: number | undefined;
29
29
  }[], IConversation[] | {
@@ -39,7 +39,7 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
39
39
  unread_count: number;
40
40
  status: number;
41
41
  color: string;
42
- is_unknown: number;
42
+ is_known: number;
43
43
  customer_id?: number | undefined;
44
44
  tenant_id?: number | undefined;
45
45
  }[]>;
@@ -56,7 +56,7 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
56
56
  unread_count: number;
57
57
  status: number;
58
58
  color: string;
59
- is_unknown: number;
59
+ is_known: number;
60
60
  customer_id?: number | undefined;
61
61
  tenant_id?: number | undefined;
62
62
  }[], IConversation[] | {
@@ -72,14 +72,14 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
72
72
  unread_count: number;
73
73
  status: number;
74
74
  color: string;
75
- is_unknown: number;
75
+ is_known: number;
76
76
  customer_id?: number | undefined;
77
77
  tenant_id?: number | undefined;
78
78
  }[]>;
79
79
  getCurrentConversation: () => IConversation | undefined;
80
80
  initData: (option?: {
81
81
  conversation_id?: any;
82
- is_unknown?: string | undefined;
82
+ is_known?: string | undefined;
83
83
  } | undefined) => Promise<void>;
84
84
  handleTabChange: (tab: any, option?: {
85
85
  hideCheckHasReceiveId?: boolean | undefined;
@@ -1,6 +1,6 @@
1
1
  import InputSearch from '../../../components/chat/common/input/InputSearch.vue';
2
2
  import IconPlus from '../../../assets/icons/global/IconPlus.vue';
3
- import { computed, onMounted, onUnmounted, ref } from 'vue';
3
+ import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue';
4
4
  import Avatar from '../../../components/chat/customer/Avatar.vue';
5
5
  import { getConversationView } from '../../../utils/chat/store/conversation';
6
6
  import ScrollEvent from '../../../components/chat/ScrollEvent/ScrollEvent.vue';
@@ -44,21 +44,44 @@ dayjs.updateLocale('en', {
44
44
  const props = withDefaults(defineProps(), {});
45
45
  const emit = defineEmits();
46
46
  const TAB_VALUE = {
47
- ALL: 0,
48
- UNKNOWN: 1
47
+ ALL: 1,
48
+ UNKNOWN: 0
49
49
  };
50
50
  const tabs = computed(() => [
51
- { label: 'All', value: TAB_VALUE.ALL, badge: (listConversationsAllUnread.value || '').toString() },
51
+ {
52
+ label: 'All',
53
+ value: TAB_VALUE.ALL,
54
+ badge: (listConversationsAllUnread.value || '').toString()
55
+ },
52
56
  {
53
57
  label: 'Message Requests',
54
58
  value: TAB_VALUE.UNKNOWN,
55
59
  badge: (listConversationsUnknownUnread.value || '').toString()
56
60
  }
57
61
  ]);
62
+ const checkConversationHasCustomer = (data) => {
63
+ const index = listConversationsAll.value.findIndex((item) => item.receiver_id == data.receiver_id);
64
+ const unknown_index = listConversationsUnknown.value.findIndex((item) => item.receiver_id == data.receiver_id);
65
+ if (index > -1) {
66
+ listConversationsAll.value[index].last_message = data.last_message;
67
+ listConversationsAll.value[index].last_message_time = data.last_message_time;
68
+ listConversationsAll.value[index].unread_count = data.unread_count;
69
+ listConversationsAll.value[index].id = data.id;
70
+ return true;
71
+ }
72
+ else if (unknown_index > -1) {
73
+ listConversationsUnknown.value[index].last_message = data.last_message;
74
+ listConversationsUnknown.value[index].last_message_time = data.last_message_time;
75
+ listConversationsUnknown.value[index].unread_count = data.unread_count;
76
+ listConversationsUnknown.value[index].id = data.id;
77
+ return true;
78
+ }
79
+ return false;
80
+ };
58
81
  let topic_customer_update = '';
59
82
  const { digibotData, digibotId } = useDigibot();
60
- const { listConversations: listConversationsAll, getData: getDataAll, params: paramsAll, pageCount: pageCountAll, handleReadMessage: handleReadMessageAll, getDataCache: getDataCacheAll } = useListConversations(TAB_VALUE.ALL, dataProfile.value?.user_type === 'tenant');
61
- const { listConversations: listConversationsUnknown, getData: getDataUnknown, params: paramsUnknown, pageCount: pageCountUnknown, handleReadMessage: handleReadMessageUnknown, getDataCache: getDataCacheUnknown } = useListConversations(TAB_VALUE.UNKNOWN, dataProfile.value?.user_type === 'tenant');
83
+ const { listConversations: listConversationsAll, getData: getDataAll, params: paramsAll, pageCount: pageCountAll, handleReadMessage: handleReadMessageAll, getDataCache: getDataCacheAll } = useListConversations(TAB_VALUE.ALL, dataProfile.value?.user_type === 'tenant', checkConversationHasCustomer);
84
+ const { listConversations: listConversationsUnknown, getData: getDataUnknown, params: paramsUnknown, pageCount: pageCountUnknown, handleReadMessage: handleReadMessageUnknown, getDataCache: getDataCacheUnknown } = useListConversations(TAB_VALUE.UNKNOWN, dataProfile.value?.user_type === 'tenant', checkConversationHasCustomer);
62
85
  onMounted(async () => {
63
86
  try {
64
87
  if (dataProfile.value) {
@@ -86,7 +109,7 @@ const listConversationsUnknownUnread = computed(() => {
86
109
  return (listConversationsUnknown.value.reduce((total, cur) => total + (cur?.unread_count ?? 0), 0) ?? 0);
87
110
  });
88
111
  const listConversationsAllUnread = computed(() => {
89
- return (listConversationsAll.value.reduce((total, cur) => total + (cur?.unread_count ?? 0), 0) ?? 0);
112
+ return listConversationsAll.value.reduce((total, cur) => total + (cur?.unread_count ?? 0), 0) ?? 0;
90
113
  });
91
114
  const keyword = ref('');
92
115
  const activeTabs = ref(TAB_VALUE.ALL);
@@ -134,7 +157,10 @@ const mqttMessageHandler = async (topic, data) => {
134
157
  const idIndex = subParts.findIndex((p) => p === '+');
135
158
  const id = topicParts[idIndex];
136
159
  const customer = await getDetailReceiver(id);
137
- const isAllTab = !!customer.username;
160
+ // console.log(customer,'aaaaaaaaaaa')
161
+ await nextTick();
162
+ await sleep(500);
163
+ const isAllTab = customer.is_known == 1;
138
164
  const correctList = isAllTab ? listConversationsAll.value : listConversationsUnknown.value;
139
165
  const wrongList = isAllTab ? listConversationsUnknown.value : listConversationsAll.value;
140
166
  const updatePayload = {
@@ -142,29 +168,54 @@ const mqttMessageHandler = async (topic, data) => {
142
168
  phone: customer.phone,
143
169
  avatar: customer.avatar,
144
170
  color: customer.color,
145
- local_id: customer.conversation_id
146
171
  };
147
- const correctIndex = correctList.findIndex((conversation) => conversation.id === customer.conversation_id);
172
+ const correctIndex = correctList.findIndex((conversation) => conversation.receiver_id === customer.id);
148
173
  if (correctIndex > -1) {
149
174
  Object.assign(correctList[correctIndex], updatePayload);
150
175
  }
151
- const wrongIndex = wrongList.findIndex((c) => c.id === customer.conversation_id);
176
+ const wrongIndex = wrongList.findIndex((c) => c.receiver_id === customer.id);
177
+ // const hasChatBox = correctList.findIndex((item: any) => item.id === digibotId)
152
178
  if (wrongIndex > -1) {
179
+ // if(!isAllTab) {
180
+ // wrongList.splice(wrongIndex, 1)
181
+ // }
153
182
  const conversation = wrongList[wrongIndex];
154
183
  wrongList.splice(wrongIndex, 1);
155
- const hasChatBox = listConversations.value.findIndex((item) => item.id === digibotId);
156
184
  const data_format = {
157
185
  ...conversation,
158
186
  ...updatePayload
159
187
  };
160
- if (hasChatBox > -1) {
161
- correctList.splice(1, 0, data_format);
188
+ if (correctIndex == -1) {
189
+ if (isAllTab) {
190
+ correctList.splice(1, 0, data_format);
191
+ }
192
+ else {
193
+ correctList.unshift(data_format);
194
+ }
195
+ }
196
+ }
197
+ if (wrongIndex == -1 && correctIndex == -1) {
198
+ const conversation = {
199
+ id: -99,
200
+ last_message: '',
201
+ last_message_time: '',
202
+ unread_count: 0,
203
+ created_at: '',
204
+ updated_at: '',
205
+ receiver_id: Number(customer?.id) ?? 0,
206
+ is_known: customer.is_known,
207
+ status: 1,
208
+ ...updatePayload
209
+ };
210
+ if (isAllTab) {
211
+ correctList.splice(1, 0, conversation);
162
212
  }
163
213
  else {
164
- correctList.unshift(data_format);
214
+ correctList.unshift(conversation);
165
215
  }
166
216
  }
167
217
  };
218
+ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
168
219
  const getAllList = async (tab_value) => {
169
220
  if (tab_value == TAB_VALUE.ALL) {
170
221
  while (paramsAll.value.page < pageCountAll.value && !scrollEventRef.value?.canScroll()) {
@@ -215,15 +266,16 @@ const handleScroll = useDebounce(async () => {
215
266
  }
216
267
  }, 200);
217
268
  const selectUser = (user) => {
218
- handleReadMessage();
269
+ handleReadMessage(user.receiver_id);
219
270
  emit('selectReceiver', user);
220
271
  };
221
- const handleReadMessage = () => {
272
+ const handleReadMessage = (receiver_id_request) => {
273
+ const id = receiver_id_request ?? receiver_id.value;
222
274
  if (activeTabs.value == TAB_VALUE.ALL) {
223
- handleReadMessageAll(receiver_id.value);
275
+ handleReadMessageAll(id);
224
276
  }
225
277
  else if (activeTabs.value == TAB_VALUE.UNKNOWN) {
226
- handleReadMessageUnknown(receiver_id.value);
278
+ handleReadMessageUnknown(id);
227
279
  }
228
280
  };
229
281
  const getTimeFromNow = (data) => {
@@ -245,8 +297,8 @@ const getCurrentConversation = () => {
245
297
  return listConversations.value?.find((user) => user.receiver_id == receiver_id.value);
246
298
  };
247
299
  const initData = async (option) => {
248
- if (option?.is_unknown || option?.is_unknown == '0') {
249
- activeTabs.value = Number(option?.is_unknown);
300
+ if (option?.is_known || option?.is_known == TAB_VALUE.ALL.toString()) {
301
+ activeTabs.value = Number(option?.is_known);
250
302
  }
251
303
  let hideCheckHasReceiveId = false;
252
304
  if (option?.conversation_id) {
@@ -41,8 +41,8 @@ const handleVisibilitychange = () => {
41
41
  const handleConnectMqtt = async () => {
42
42
  try {
43
43
  await connectMqtt();
44
- topic = TOPIC_PLIVO_CALL + infoUser.value?.conversation_id;
45
- topic_plivo_chat = TOPIC_PLIVO_SMS + infoUser.value?.conversation_id;
44
+ topic = TOPIC_PLIVO_CALL + props.conversation?.id;
45
+ topic_plivo_chat = TOPIC_PLIVO_SMS + props.conversation?.id;
46
46
  // subscribeToTopic(topic)
47
47
  subscribeToTopic(topic_plivo_chat);
48
48
  subscribeToTopic(topic);
@@ -183,7 +183,7 @@ const handleSendMessage = async (data) => {
183
183
  chatMessageRef.value?.scrollBottom();
184
184
  const formData = new FormData();
185
185
  formData.append('message', data.message ?? '');
186
- formData.append('receiver_id', infoUser.value?.id ?? '');
186
+ formData.append('receiver_id', infoUser.value?.id.toString() ?? '');
187
187
  if (file_upload?.length) {
188
188
  formData.append('url', file_upload[0]?.url ?? '');
189
189
  }
@@ -213,7 +213,8 @@ const handleSendMessage = async (data) => {
213
213
  message: data?.message ?? '',
214
214
  isSendImg: !!file_upload?.length,
215
215
  infoUser: infoUser.value,
216
- is_unknown: props.conversation?.is_unknown ?? 0
216
+ is_known: props.conversation?.is_known ?? 0,
217
+ conversation_id: props.conversation?.id ?? 0
217
218
  });
218
219
  }
219
220
  catch (error) {
@@ -376,6 +377,7 @@ if (__VLS_ctx.receiverId != __VLS_ctx.digibotId) {
376
377
  ...{ 'onFocus': {} },
377
378
  data: (__VLS_ctx.infoUser),
378
379
  responsive: (__VLS_ctx.responsive),
380
+ conversation: (__VLS_ctx.conversation),
379
381
  ref: "inputChatRef",
380
382
  ...{ class: "p-2 sm:p-6" },
381
383
  }));
@@ -384,6 +386,7 @@ if (__VLS_ctx.receiverId != __VLS_ctx.digibotId) {
384
386
  ...{ 'onFocus': {} },
385
387
  data: (__VLS_ctx.infoUser),
386
388
  responsive: (__VLS_ctx.responsive),
389
+ conversation: (__VLS_ctx.conversation),
387
390
  ref: "inputChatRef",
388
391
  ...{ class: "p-2 sm:p-6" },
389
392
  }, ...__VLS_functionalComponentArgsRest(__VLS_22));
@@ -397,7 +400,7 @@ if (__VLS_ctx.receiverId != __VLS_ctx.digibotId) {
397
400
  return;
398
401
  __VLS_ctx.emit('inputFocus');
399
402
  // @ts-ignore
400
- [infoUser, responsive, emit, handleSendMessage,];
403
+ [infoUser, responsive, emit, conversation, handleSendMessage,];
401
404
  } });
402
405
  /** @type {typeof __VLS_ctx.inputChatRef} */ ;
403
406
  var __VLS_29 = {};
@@ -17,7 +17,7 @@ const emit = defineEmits();
17
17
  const activePlivoSms = ref(dataProfile.value?.is_sms_active == 1);
18
18
  const loading = ref(false);
19
19
  const goToViewUser = () => {
20
- if (props.data?.id == digibotId.toString())
20
+ if (props.data?.id.toString() == digibotId.toString())
21
21
  return;
22
22
  if (dataProfile.value?.user_type == 'tenant') {
23
23
  user.value = props.data;
@@ -127,7 +127,7 @@ __VLS_asFunctionalElement(__VLS_elements.p, __VLS_elements.p)({
127
127
  (__VLS_ctx.data?.username || __VLS_ctx.phoneNumberFormat(__VLS_ctx.data?.phone ?? '') || 'n/a');
128
128
  // @ts-ignore
129
129
  [data, data, phoneNumberFormat,];
130
- if (__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant') {
130
+ if (__VLS_ctx.data?.id && __VLS_ctx.data?.id.toString() != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant') {
131
131
  // @ts-ignore
132
132
  [dataProfile, data, data, digibotId,];
133
133
  /** @type {[typeof ButtonBase, typeof ButtonBase, ]} */ ;
@@ -150,7 +150,7 @@ if (__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() &
150
150
  let __VLS_15;
151
151
  const __VLS_16 = ({ click: {} },
152
152
  { onClick: (...[$event]) => {
153
- if (!(__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant'))
153
+ if (!(__VLS_ctx.data?.id && __VLS_ctx.data?.id.toString() != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant'))
154
154
  return;
155
155
  __VLS_ctx.handleActivePlivoSmsChange(!__VLS_ctx.activePlivoSms);
156
156
  // @ts-ignore
@@ -173,12 +173,12 @@ if (__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() &
173
173
  }
174
174
  var __VLS_13;
175
175
  }
176
- if (__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant') {
176
+ if (__VLS_ctx.data?.id && __VLS_ctx.data?.id.toString() != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant') {
177
177
  // @ts-ignore
178
178
  [dataProfile, data, data, digibotId,];
179
179
  __VLS_asFunctionalElement(__VLS_elements.button, __VLS_elements.button)({
180
180
  ...{ onClick: (...[$event]) => {
181
- if (!(__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant'))
181
+ if (!(__VLS_ctx.data?.id && __VLS_ctx.data?.id.toString() != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant'))
182
182
  return;
183
183
  __VLS_ctx.emit('call');
184
184
  // @ts-ignore
@@ -1,8 +1,10 @@
1
1
  import type { IResMessage, IResUser } from '../../../types/message';
2
2
  import 'vue3-emoji-picker/css';
3
3
  import type { PAGE_RESPONSIVE } from '../../../types/chat/global';
4
+ import type { IConversation } from '../../../types/conversation';
4
5
  type Props = {
5
6
  data: IResUser | null;
7
+ conversation: IConversation | null;
6
8
  responsive: PAGE_RESPONSIVE;
7
9
  };
8
10
  type __VLS_Props = Props;
@@ -9,7 +9,7 @@ import { dataProfile } from '../../../utils/chat/store/auth';
9
9
  import { ref, onMounted, onUnmounted } from 'vue';
10
10
  import PopoverBase from '../../../components/chat/common/popover/PopoverBase.vue';
11
11
  import IconCloseCircle from '../../../assets/icons/global/IconCloseCircle.vue';
12
- import DropZone from '@/chat/page/home/DropZone.vue';
12
+ import DropZone from '../../../chat/page/home/DropZone.vue';
13
13
  const props = withDefaults(defineProps(), {});
14
14
  const emit = defineEmits();
15
15
  const ChatModeOptions = [
@@ -62,7 +62,7 @@ const handleSendMessage = async (type) => {
62
62
  chatId++;
63
63
  const id = props.data?.id.toString() + '-' + chatId + '-' + Date.now();
64
64
  const data = {
65
- conversation_id: props.data?.conversation_id,
65
+ conversation_id: props.conversation?.id,
66
66
  created_at: dayjs().tz(TIME_ZONE_UTC).format(DATE_FORMATS['DATE_FORMAT_FULL']),
67
67
  id,
68
68
  local_id: id,
@@ -46,7 +46,7 @@ const handlePlivoCallBack = (status, data) => {
46
46
  handleMedialPermissionError();
47
47
  }
48
48
  };
49
- const { plivoLogin, plivoCallAnswer, plivoCall, plivoEndCall, plivoCallSwishMute, plivoCallSwishSpeaker, plivoRemoveCallBack, checkTimeLimit, plivoBrowserSdk } = usePlivo(handlePlivoCallBack);
49
+ const { plivoLogin, plivoCallAnswer, plivoCall, plivoEndCall, plivoCallSwishMute, plivoCallSwishSpeaker, plivoRemoveCallBack, checkTimeLimit, isPlivoOn } = usePlivo(handlePlivoCallBack);
50
50
  const STATUS_LABEL = computed(() => {
51
51
  return {
52
52
  [PLIVO_CALL_STATUS.CONNECTING]: 'Connecting...',
@@ -247,7 +247,7 @@ const getUserOffer = async (phone) => {
247
247
  }
248
248
  };
249
249
  const handleTimeLimitError = () => {
250
- if (plivoBrowserSdk == null)
250
+ if (!isPlivoOn.value)
251
251
  return;
252
252
  errorMessage.value = 'Call time limit reached. This call has ended.';
253
253
  endCall();
@@ -6,7 +6,14 @@ const props = withDefaults(defineProps(), {
6
6
  size: 'md',
7
7
  src: ''
8
8
  });
9
- const initials = computed(() => props.name?.[0]?.toUpperCase() ?? '');
9
+ const initials = computed(() => {
10
+ if (!props.name)
11
+ return '';
12
+ const char = props.name
13
+ .trim()
14
+ .match(/[A-Za-z0-9]/)?.[0];
15
+ return char?.toUpperCase() ?? '';
16
+ });
10
17
  const sizeClass = computed(() => {
11
18
  const s = props.size;
12
19
  if (typeof s === 'number')
@@ -13,7 +13,7 @@ export const digibotData = {
13
13
  unread_count: 0,
14
14
  status: 1,
15
15
  color: '#4F46E5',
16
- is_unknown: 0
16
+ is_known: 1
17
17
  };
18
18
  export function useDigibot() {
19
19
  return {
@@ -7,6 +7,6 @@ export declare function useInitData(): {
7
7
  responsive: PAGE_RESPONSIVE;
8
8
  }) => Promise<{
9
9
  conversation_id?: string;
10
- is_unknown?: string;
10
+ is_known?: string;
11
11
  }>;
12
12
  };
@@ -48,15 +48,15 @@ export function useInitData() {
48
48
  }
49
49
  };
50
50
  const checkNotificationParams = () => {
51
- // return {conversation_id: '339', is_unknown: '1'}
51
+ // return {conversation_id: '339', is_known: '1'}
52
52
  const queryString = window.location.search;
53
53
  const urlParams = new URLSearchParams(queryString);
54
54
  const conversation_id = urlParams.get('conversation_id') || '';
55
- const is_unknown = urlParams.get('is_unknown') || '';
56
- if (!conversation_id || !is_unknown)
55
+ const is_known = urlParams.get('is_known') || '';
56
+ if (!conversation_id || !is_known)
57
57
  return {};
58
58
  clearApiParams();
59
- return { conversation_id, is_unknown };
59
+ return { conversation_id, is_known };
60
60
  };
61
61
  const loginApiLink = async () => {
62
62
  try {
@@ -1,5 +1,5 @@
1
1
  import type { IConversation, IParamGetConversation } from '../types/conversation';
2
- export declare const useListConversations: (is_unknown: number, is_tenant: boolean) => {
2
+ export declare const useListConversations: (is_known: number, is_tenant: boolean, checkConversationHasCustomer: (data: IConversation) => boolean) => {
3
3
  listConversations: import("vue").Ref<{
4
4
  id: number;
5
5
  receiver_id: number;
@@ -13,7 +13,7 @@ export declare const useListConversations: (is_unknown: number, is_tenant: boole
13
13
  unread_count: number;
14
14
  status: number;
15
15
  color: string;
16
- is_unknown: number;
16
+ is_known: number;
17
17
  customer_id?: number | undefined;
18
18
  tenant_id?: number | undefined;
19
19
  }[], IConversation[] | {
@@ -29,7 +29,7 @@ export declare const useListConversations: (is_unknown: number, is_tenant: boole
29
29
  unread_count: number;
30
30
  status: number;
31
31
  color: string;
32
- is_unknown: number;
32
+ is_known: number;
33
33
  customer_id?: number | undefined;
34
34
  tenant_id?: number | undefined;
35
35
  }[]>;
@@ -9,7 +9,7 @@ import dayjs from 'dayjs';
9
9
  import { useDigibot } from '../composable/useDigibot';
10
10
  import { getCache, setCache } from '../utils/chat/cache';
11
11
  const { digibotData, digibotId } = useDigibot();
12
- export const useListConversations = (is_unknown, is_tenant) => {
12
+ export const useListConversations = (is_known, is_tenant, checkConversationHasCustomer) => {
13
13
  const STORAGE_KEY = 'chat-conversation-';
14
14
  const pageCount = ref(0);
15
15
  const listConversations = ref([]);
@@ -34,11 +34,11 @@ export const useListConversations = (is_unknown, is_tenant) => {
34
34
  const handleDisconnectMqtt = () => {
35
35
  TOPIC_HOME.forEach((item) => {
36
36
  unsubscribeFromTopic(item + dataProfile.value?.id);
37
- removeHandleMqttMessage('chat-list-' + item + '-' + is_unknown);
37
+ removeHandleMqttMessage('chat-list-' + item + '-' + is_known);
38
38
  });
39
39
  if (dataProfile.value?.user_type == 'tenant') {
40
40
  // unsubscribeFromTopic(TOPIC_STATUS_USER + dataProfile.value?.id)
41
- // removeHandleMqttMessage('chat-list-' + TOPIC_STATUS_USER + '-' + is_unknown)
41
+ // removeHandleMqttMessage('chat-list-' + TOPIC_STATUS_USER + '-' + is_known)
42
42
  }
43
43
  };
44
44
  const handleConnectMqtt = async () => {
@@ -46,10 +46,10 @@ export const useListConversations = (is_unknown, is_tenant) => {
46
46
  if (dataProfile.value) {
47
47
  await connectMqtt();
48
48
  TOPIC_HOME.forEach((item) => {
49
- if (is_unknown == 0) {
49
+ if (is_known == 0) {
50
50
  subscribeToTopic(item + dataProfile.value?.id);
51
51
  }
52
- addHandleMqttMessage('chat-list-' + item + '-' + is_unknown, item + dataProfile.value?.id, mqttMessageHandler);
52
+ addHandleMqttMessage('chat-list-' + item + '-' + is_known, item + dataProfile.value?.id, mqttMessageHandler);
53
53
  });
54
54
  }
55
55
  }
@@ -62,13 +62,13 @@ export const useListConversations = (is_unknown, is_tenant) => {
62
62
  // getData({}, {reset: true})
63
63
  // return
64
64
  // }
65
- if ((data.is_unknown ?? 0) == is_unknown || (!is_tenant && is_unknown == 0)) {
65
+ if ((data.is_known ?? 1) == is_known || (!is_tenant && is_known == 1)) {
66
66
  getDataMqttDebounce();
67
67
  if (topic ===
68
68
  TOPIC_HOME[0] + dataProfile.value?.id
69
69
  || topic === TOPIC_HOME[1] + dataProfile.value?.id) {
70
- const index = listConversations.value.findIndex((item) => item.id === data.id);
71
- const hasChatBox = listConversations.value.findIndex((item) => item.id === digibotId);
70
+ const index = listConversations.value.findIndex(item => item.id === data.id);
71
+ const hasChatBox = listConversations.value.findIndex(item => item.id === digibotId);
72
72
  if (index != -1) {
73
73
  let conversation = listConversations.value[index];
74
74
  data.username = conversation.username;
@@ -78,6 +78,12 @@ export const useListConversations = (is_unknown, is_tenant) => {
78
78
  listConversations.value.splice(index, 1);
79
79
  }
80
80
  else {
81
+ if (is_known == 0) {
82
+ const isHasCustomer = checkConversationHasCustomer(data);
83
+ await nextTick();
84
+ if (isHasCustomer)
85
+ return;
86
+ }
81
87
  const conversation = await getConversationView(data.id);
82
88
  data.username = conversation.username;
83
89
  data.color = conversation.color;
@@ -85,7 +91,7 @@ export const useListConversations = (is_unknown, is_tenant) => {
85
91
  data.phone = conversation.phone;
86
92
  }
87
93
  // data.receiver_id = data.receiver_id != dataProfile.value?.id ? data.receiver_id : data.sender_id
88
- if (hasChatBox > -1) {
94
+ if (is_known == 1) {
89
95
  listConversations.value.splice(1, 0, data);
90
96
  }
91
97
  else {
@@ -93,7 +99,7 @@ export const useListConversations = (is_unknown, is_tenant) => {
93
99
  }
94
100
  }
95
101
  if (topic === TOPIC_HOME[2] + dataProfile.value?.id) {
96
- if (data.is_unknown == is_unknown) {
102
+ if (data.is_known == is_known) {
97
103
  const index = listConversations.value.findIndex((item) => item.id === data.id);
98
104
  if (index != -1) {
99
105
  listConversations.value[index].unread_count = 0;
@@ -118,21 +124,21 @@ export const useListConversations = (is_unknown, is_tenant) => {
118
124
  }, 5000);
119
125
  const getData = async (data, option) => {
120
126
  try {
121
- if (!is_tenant && is_unknown == 1)
127
+ if (!is_tenant && is_known == 1)
122
128
  return;
123
129
  params.value = { ...params.value, ...(data ?? {}) };
124
130
  if (option?.reset) {
125
131
  params.value.page = 1;
126
132
  }
127
- const is_unknown_value = is_tenant ? is_unknown : undefined;
133
+ const is_known_value = is_tenant ? is_known : undefined;
128
134
  const page_request = option?.page ?? params.value.page;
129
135
  const res = await getConversation({
130
136
  ...params.value,
131
- is_unknown: is_unknown_value,
137
+ is_known: is_known_value,
132
138
  page: page_request
133
139
  });
134
140
  if (page_request <= 1 && !params.value?.search) {
135
- setCache(STORAGE_KEY + is_unknown, res.items);
141
+ setCache(STORAGE_KEY + is_known, res.items);
136
142
  }
137
143
  if (option?.is_mqtt) {
138
144
  mergeChats(res?.items);
@@ -140,7 +146,7 @@ export const useListConversations = (is_unknown, is_tenant) => {
140
146
  }
141
147
  if (option?.reset) {
142
148
  listConversations.value = [];
143
- if (is_unknown == 0 && dataProfile.value?.user_type == 'tenant')
149
+ if (is_known == 1 && dataProfile.value?.user_type == 'tenant')
144
150
  listConversations.value.push(digibotData);
145
151
  await nextTick();
146
152
  }
@@ -174,7 +180,7 @@ export const useListConversations = (is_unknown, is_tenant) => {
174
180
  }
175
181
  };
176
182
  const getDataCache = () => {
177
- const cache_data = getCache(STORAGE_KEY + is_unknown);
183
+ const cache_data = getCache(STORAGE_KEY + is_known);
178
184
  if (cache_data.data) {
179
185
  listConversations.value = [];
180
186
  listConversations.value.push(...(cache_data.data ?? []));
@@ -17,7 +17,7 @@ export function useListenEvent(callBackResizeChange) {
17
17
  if (!appChatRef)
18
18
  return;
19
19
  const width = appChatRef?.offsetWidth ?? 0;
20
- if (width >= 1180) {
20
+ if (width >= 1281) {
21
21
  if (responsiveObserver.value != 'window') {
22
22
  if (!is_init)
23
23
  callBackResizeChange?.();
@@ -12,5 +12,5 @@ export declare function usePlivo(callback: (status: PlivoCallStatusType, data?:
12
12
  plivoCallSwishSpeaker: (id: any) => void;
13
13
  plivoRemoveCallBack: () => void;
14
14
  checkTimeLimit: () => Promise<number>;
15
- plivoBrowserSdk: any;
15
+ isPlivoOn: import("vue").Ref<boolean, boolean>;
16
16
  };
@@ -2,6 +2,7 @@ import { PLIVO_CALL_STATUS } from '../types/chat/call';
2
2
  import { createSipAccount } from '../utils/chat/store/call';
3
3
  import { dataProfile } from '../utils/chat/store/auth';
4
4
  import { getPhoneTimeLimit } from '../utils/chat/store/message';
5
+ import { ref } from 'vue';
5
6
  export function usePlivo(callback) {
6
7
  var options = {
7
8
  debug: 'ALL',
@@ -15,6 +16,7 @@ export function usePlivo(callback) {
15
16
  let CallUuid = '';
16
17
  let custom_resolve = null;
17
18
  let custom_reject = null;
19
+ const isPlivoOn = ref(false);
18
20
  const plivoLogin = async (data) => {
19
21
  try {
20
22
  if (!plivoBrowserSdk) {
@@ -41,8 +43,10 @@ export function usePlivo(callback) {
41
43
  // await plivoBrowserSdk?.client?.login(payload.sub , null, token)
42
44
  await plivoBrowserSdk?.client?.loginWithAccessToken(data.token);
43
45
  plivoBrowserSdk?.client?.setRingTone(false);
46
+ isPlivoOn.value = true;
44
47
  // await plivoBrowserSdk?.client?.on?.(payload)
45
48
  // console.log('Registered with token')
49
+ console.log(plivoBrowserSdk);
46
50
  }
47
51
  catch (err) {
48
52
  console.log('Login error: ' + err);
@@ -179,6 +183,7 @@ export function usePlivo(callback) {
179
183
  plivoBrowserSdk?.client?.off?.('onMediaPermission', handleMediaPermission);
180
184
  plivoBrowserSdk?.client?.off?.('onLoginFailed', handleLoginFailed);
181
185
  plivoBrowserSdk = null;
186
+ isPlivoOn.value = false;
182
187
  };
183
188
  const sleep = () => {
184
189
  return new Promise((resolve) => setTimeout(resolve, 2000));
@@ -193,6 +198,6 @@ export function usePlivo(callback) {
193
198
  plivoCallSwishSpeaker,
194
199
  plivoRemoveCallBack,
195
200
  checkTimeLimit,
196
- plivoBrowserSdk
201
+ isPlivoOn
197
202
  };
198
203
  }