@phonghq/go-chat 1.0.36 → 1.0.38

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.
@@ -39,6 +39,35 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
39
39
  color: string;
40
40
  is_unknown: number;
41
41
  }[]>;
42
+ listConversationsUnknown: import("vue").Ref<{
43
+ id: number;
44
+ receiver_id: number;
45
+ username: string | null;
46
+ phone: string;
47
+ avatar: string | null;
48
+ last_message: string;
49
+ last_message_time: string;
50
+ created_at: string;
51
+ updated_at: string;
52
+ unread_count: number;
53
+ status: number;
54
+ color: string;
55
+ is_unknown: number;
56
+ }[], IConversation[] | {
57
+ id: number;
58
+ receiver_id: number;
59
+ username: string | null;
60
+ phone: string;
61
+ avatar: string | null;
62
+ last_message: string;
63
+ last_message_time: string;
64
+ created_at: string;
65
+ updated_at: string;
66
+ unread_count: number;
67
+ status: number;
68
+ color: string;
69
+ is_unknown: number;
70
+ }[]>;
42
71
  getCurrentConversation: () => IConversation | undefined;
43
72
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
44
73
  "update:receiverId": (value: any) => any;
@@ -1,5 +1,5 @@
1
1
  export declare const TOPIC_DETAIL_CHAT = "chat/message/";
2
2
  export declare const TOPIC_DETAIL_CALL = "call/message/";
3
- export declare const TOPIC_HOME: string[];
4
3
  export declare const TOPIC_PLIVO_SMS = "sms-inbound/";
5
4
  export declare const TOPIC_STATUS_USER: string;
5
+ export declare const TOPIC_HOME: string[];
@@ -17,7 +17,6 @@ import MobileFooter from '../components/chat/layout/mobile/Footer.vue';
17
17
  import '../style/index.scss';
18
18
  import { useDebounce } from '../utils/debounce';
19
19
  import { defineRootColor } from '../constant/color';
20
- import { publicTopicConversationUpdate } from '../utils/chat/conversation';
21
20
  import IconCloseCircle from '../assets/icons/IconCloseCircle.vue';
22
21
  import Setting from '../chat/page/setting/Setting.vue';
23
22
  import SettingSuccess from '../chat/page/setting/SettingSuccess.vue';
@@ -111,8 +110,10 @@ const currentPageConfig = computed(() => {
111
110
  const responsiveRender = computed(() => {
112
111
  return props.response == 'mobile' ? props.response : responsiveObserver.value;
113
112
  });
114
- const list = computed(() => chatListRef.value?.listConversationsAll ?? []);
115
- const unreadCount = computed(() => list.value?.reduce((total, cur) => total + (cur?.unread_count ?? 0), 0) ?? 0);
113
+ const unreadCount = computed(() => {
114
+ return ((chatListRef.value?.listConversationsAll?.reduce((total, cur) => total + (cur?.unread_count ?? 0), 0) ?? 0) +
115
+ (chatListRef.value?.listConversationsUnknown?.reduce((total, cur) => total + (cur?.unread_count ?? 0), 0) ?? 0));
116
+ });
116
117
  const callStatus = computed(() => callingRef.value?.callStatus ?? null);
117
118
  const responsiveObserver = ref('tablet');
118
119
  const appChatRef = ref();
@@ -161,14 +162,15 @@ const getResponsiveObserverDebounce = useDebounce(() => {
161
162
  }, 50);
162
163
  const handleInitPage = async () => {
163
164
  await initPage({ props: props, response: responsiveRender.value });
165
+ console.log(dataProfile.value, '55555555555555555');
164
166
  if (!dataProfile.value?.tenant_phone && dataProfile.value?.user_type == 'tenant') {
165
- if (dataProfile.value?.has_business_tenant_phone) {
166
- routerPush(PAGE.REGISTER_SUCCESS);
167
- }
168
- else {
169
- // emit('error:noPhoneTenant')
170
- routerPush(PAGE.REGISTER_TENANT);
171
- }
167
+ emit('error:noPhoneTenant');
168
+ // if (dataProfile.value?.has_business_tenant_phone) {
169
+ // routerPush(PAGE.REGISTER_SUCCESS)
170
+ // } else {
171
+ // // emit('error:noPhoneTenant')
172
+ // routerPush(PAGE.REGISTER_TENANT)
173
+ // }
172
174
  }
173
175
  };
174
176
  const handleEndCall = (data, type) => {
@@ -176,10 +178,10 @@ const handleEndCall = (data, type) => {
176
178
  if (data?.phone && homeComponentRef.value?.infoUser?.phone == data?.phone) {
177
179
  homeComponentRef.value?.handleGetMessage({ resetList: true });
178
180
  }
179
- publicTopicConversationUpdate({
180
- infoUser: homeComponentRef.value?.infoUser ?? null,
181
- isCall: type
182
- });
181
+ // publicTopicConversationUpdate({
182
+ // infoUser: homeComponentRef.value?.infoUser ?? null,
183
+ // isCall: type
184
+ // })
183
185
  }, 2000);
184
186
  };
185
187
  const openSettings = () => {
@@ -218,6 +220,7 @@ const askMedialPermission = async () => {
218
220
  handleMedialPermissionError();
219
221
  };
220
222
  const reload = () => {
223
+ ;
221
224
  window.location.reload();
222
225
  };
223
226
  let __VLS_exposed;
@@ -300,7 +303,7 @@ else if (__VLS_ctx.currentPage == __VLS_ctx.PAGE.REGISTER_SUCCESS) {
300
303
  }
301
304
  else {
302
305
  __VLS_asFunctionalElement(__VLS_elements.div, __VLS_elements.div)({
303
- ...{ class: "w-full h-full flex flex-col overflow-hidden relative" },
306
+ ...{ class: "w-full h-full flex flex-col overflow-hidden relative" },
304
307
  });
305
308
  if (__VLS_ctx.goChatError) {
306
309
  // @ts-ignore
@@ -439,6 +442,9 @@ else {
439
442
  // @ts-ignore
440
443
  [currentPageConfig,];
441
444
  }
445
+ else {
446
+ __VLS_asFunctionalElement(__VLS_elements.span, __VLS_elements.span)({});
447
+ }
442
448
  if (props.isLib) {
443
449
  __VLS_asFunctionalElement(__VLS_elements.button, __VLS_elements.button)({
444
450
  ...{ onClick: (...[$event]) => {
@@ -61,12 +61,13 @@ const scrollEventRef = ref(null);
61
61
  const isLoadingSearch = ref(false);
62
62
  const getData = async (data, option) => {
63
63
  try {
64
+ const tab_value = option?.tab ?? activeTabs.value;
64
65
  if (!option?.hideLoading)
65
66
  isLoadingSearch.value = true;
66
- if (activeTabs.value == TAB_VALUE.ALL) {
67
+ if (tab_value == TAB_VALUE.ALL) {
67
68
  await getDataAll(data, option);
68
69
  }
69
- else if (activeTabs.value == TAB_VALUE.UNKNOWN) {
70
+ else if (tab_value == TAB_VALUE.UNKNOWN) {
70
71
  await getDataUnknown(data, option);
71
72
  }
72
73
  checkHasReceiveId();
@@ -148,19 +149,19 @@ const getTimeFromNow = (data) => {
148
149
  };
149
150
  const handleTabChange = async (tab) => {
150
151
  if (tab == TAB_VALUE.ALL && !listConversationsAll.value?.length) {
151
- await getData({}, { reset: true });
152
+ await getData({}, { reset: true, tab });
152
153
  }
153
154
  else if (tab == TAB_VALUE.UNKNOWN && !listConversationsUnknown.value?.length) {
154
- await getData({}, { reset: true });
155
+ await getData({}, { reset: true, tab });
155
156
  }
156
157
  checkHasReceiveId();
157
158
  };
158
159
  const getCurrentConversation = () => {
159
160
  return listConversations.value?.find(user => user.receiver_id == receiver_id.value);
160
161
  };
161
- // getData({}, { reset: true })
162
162
  handleTabChange(TAB_VALUE.ALL);
163
- const __VLS_exposed = { handleReadMessage, listConversationsAll, getCurrentConversation };
163
+ handleTabChange(TAB_VALUE.UNKNOWN);
164
+ const __VLS_exposed = { handleReadMessage, listConversationsAll, listConversationsUnknown, getCurrentConversation };
164
165
  defineExpose(__VLS_exposed);
165
166
  debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
166
167
  const __VLS_modelEmit = defineEmits();
@@ -32,8 +32,6 @@ const handleConnectMqtt = async () => {
32
32
  topic_plivo_chat = TOPIC_PLIVO_SMS + infoUser.value?.conversation_id;
33
33
  subscribeToTopic(topic);
34
34
  subscribeToTopic(topic_plivo_chat);
35
- // console.log(topic)
36
- // console.log(topic_plivo_chat)
37
35
  addHandleMqttMessage('chat-home', topic, mqttMessageHandler);
38
36
  addHandleMqttMessage('chat-home-1', topic_plivo_chat, mqttMessageHandler);
39
37
  }
@@ -48,7 +46,8 @@ const handleDisconnectMqtt = async () => {
48
46
  removeHandleMqttMessage('chat-home-1');
49
47
  };
50
48
  const mqttMessageHandler = (topic, message) => {
51
- if ((infoUser.value?.id && message?.sender_id?.toString() == infoUser.value?.id?.toString())) {
49
+ if ((infoUser.value?.id && message?.sender_id?.toString() == infoUser.value?.id?.toString())
50
+ || (infoUser.value?.id && message?.receiver_id?.toString() == infoUser.value?.id?.toString())) {
52
51
  const index = listMessage.value.findIndex((item) => item.id === message?.id);
53
52
  if (index < 0) {
54
53
  listMessage.value.unshift(message);
@@ -7,6 +7,7 @@ import { user } from '../../../utils/chat/user';
7
7
  import { dataProfile } from '../../../utils/chat/auth';
8
8
  import { digibotId } from '../../../composable/useDigibot';
9
9
  import IconArrowLeft from '../../../assets/icons/IconArrowLeft.vue';
10
+ import { phoneNumberFormat } from '../../../utils/string-helper';
10
11
  import IconSms from '../../../assets/icons/IconSms.vue';
11
12
  import { activePlivoMode } from '../../..//utils/chat/message';
12
13
  import { ref } from 'vue';
@@ -120,9 +121,9 @@ __VLS_asFunctionalElement(__VLS_elements.div, __VLS_elements.div)({
120
121
  __VLS_asFunctionalElement(__VLS_elements.p, __VLS_elements.p)({
121
122
  ...{ class: "font-semibold truncate" },
122
123
  });
123
- (__VLS_ctx.data?.username ?? 'n/a');
124
+ (__VLS_ctx.data?.username || __VLS_ctx.phoneNumberFormat(__VLS_ctx.data?.phone ?? '') || 'n/a');
124
125
  // @ts-ignore
125
- [data,];
126
+ [data, data, phoneNumberFormat,];
126
127
  if (__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant') {
127
128
  // @ts-ignore
128
129
  [dataProfile, data, data, digibotId,];
@@ -155,12 +156,16 @@ if (__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() &
155
156
  // @ts-ignore
156
157
  const __VLS_18 = __VLS_asFunctionalComponent(IconSms, new IconSms({}));
157
158
  const __VLS_19 = __VLS_18({}, ...__VLS_functionalComponentArgsRest(__VLS_18));
158
- __VLS_asFunctionalElement(__VLS_elements.span, __VLS_elements.span)({
159
- ...{ class: "hidden md:block" },
160
- });
161
- (__VLS_ctx.activePlivoSms ? 'ON' : 'OFF');
162
- // @ts-ignore
163
- [activePlivoSms,];
159
+ if (__VLS_ctx.responsive != 'mobile') {
160
+ // @ts-ignore
161
+ [responsive,];
162
+ __VLS_asFunctionalElement(__VLS_elements.span, __VLS_elements.span)({
163
+ ...{ class: "hidden md:block" },
164
+ });
165
+ (__VLS_ctx.activePlivoSms ? 'ON' : 'OFF');
166
+ // @ts-ignore
167
+ [activePlivoSms,];
168
+ }
164
169
  var __VLS_13;
165
170
  }
166
171
  if (__VLS_ctx.data?.id && __VLS_ctx.data?.id != __VLS_ctx.digibotId.toString() && __VLS_ctx.dataProfile?.user_type == 'tenant') {
@@ -1,5 +1,6 @@
1
1
  /// <reference types="C:/phonghq/go-chat-v2/node_modules/.vue-global-types/vue_3.5_0.d.ts" />
2
2
  import Avatar from '../../../components/chat/customer/Avatar.vue';
3
+ import { phoneNumberFormat } from '../../../utils/string-helper';
3
4
  const props = withDefaults(defineProps(), {});
4
5
  debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
5
6
  const __VLS_defaults = {};
@@ -41,9 +42,9 @@ __VLS_asFunctionalElement(__VLS_elements.div, __VLS_elements.div)({
41
42
  __VLS_asFunctionalElement(__VLS_elements.h2, __VLS_elements.h2)({
42
43
  ...{ class: "text-2xl font-semibold" },
43
44
  });
44
- (__VLS_ctx.data?.username ?? 'n/a');
45
+ (__VLS_ctx.data?.username || __VLS_ctx.phoneNumberFormat(__VLS_ctx.data?.phone ?? '') || 'n/a');
45
46
  // @ts-ignore
46
- [data,];
47
+ [data, data, phoneNumberFormat,];
47
48
  __VLS_asFunctionalElement(__VLS_elements.img)({
48
49
  src: "../../../assets/images/icons/new-customer.png",
49
50
  });
@@ -13,6 +13,7 @@ import { usePlivo } from '../../../composable/usePlivo';
13
13
  import { PLIVO_CALL_STATUS } from '../../../types/chat/call';
14
14
  import IconMic from '../../../assets/icons/call/IconMic.vue';
15
15
  import { useError } from '../../../composable/useError';
16
+ import { useDebounce } from '../../../utils/debounce';
16
17
  const props = withDefaults(defineProps(), {});
17
18
  const emit = defineEmits();
18
19
  // const {
@@ -117,6 +118,9 @@ function endCall(option) {
117
118
  drawerVisible.value = false;
118
119
  drawerVisibleRef.value?.close();
119
120
  }
121
+ else {
122
+ handleEmitEndCall(userRemoter.value, callType);
123
+ }
120
124
  plivoEndCall(callStatus.value);
121
125
  callStatus.value = PLIVO_CALL_STATUS.CALL_END;
122
126
  clearInterval(timer);
@@ -127,9 +131,11 @@ function endCall(option) {
127
131
  clearInterval(timer);
128
132
  if (timeOut)
129
133
  clearTimeout(timeOut);
130
- emit('endCall', userRemoter.value, callType);
131
134
  callType = '';
132
135
  }
136
+ const handleEmitEndCall = useDebounce((data, type) => {
137
+ emit('endCall', data, type);
138
+ }, 500);
133
139
  const refreshToken = async () => {
134
140
  try {
135
141
  console.log('refreshToken: ');
@@ -147,7 +153,7 @@ const refreshToken = async () => {
147
153
  refreshTokenCount = refreshTokenCount + 1;
148
154
  console.log(refreshTokenCount);
149
155
  if (refreshTokenCount < 3) {
150
- setTimeout(() => refreshToken(), 2 * 60 * 1000);
156
+ setTimeout(() => refreshToken(), 60 * 1000);
151
157
  }
152
158
  else {
153
159
  showError('We’re having trouble connecting the call. Please try again in a moment');
@@ -36,6 +36,7 @@ export const useListConversations = (is_unknown) => {
36
36
  if (dataProfile.value) {
37
37
  await connectMqtt();
38
38
  TOPIC_HOME.forEach((item) => {
39
+ console.log(item + dataProfile.value?.id);
39
40
  subscribeToTopic(item + dataProfile.value?.id);
40
41
  addHandleMqttMessage('chat-list-' + item + '-' + is_unknown, item + dataProfile.value?.id, mqttMessageHandler);
41
42
  });
@@ -51,7 +52,8 @@ export const useListConversations = (is_unknown) => {
51
52
  if ((data.is_unknown ?? 0) != is_unknown)
52
53
  return;
53
54
  getDataMqtt();
54
- if (topic === TOPIC_HOME[0] + dataProfile.value?.id || topic === TOPIC_HOME[3] + dataProfile.value?.id) {
55
+ if ((topic === TOPIC_HOME[0] + dataProfile.value?.id) || topic === (TOPIC_HOME[3] + dataProfile.value?.id)) {
56
+ console.log(data);
55
57
  const index = listConversations.value.findIndex((item) => item.id === data.id);
56
58
  const hasChatBox = listConversations.value.findIndex((item) => item.id === digibotId);
57
59
  if (index != -1) {
@@ -79,6 +81,7 @@ export const useListConversations = (is_unknown) => {
79
81
  listConversations.value[index].status = data.is_online ? 1 : 0;
80
82
  }
81
83
  }
84
+ console.log(listConversations.value, is_unknown);
82
85
  };
83
86
  const getDataMqtt = useDebounce(() => {
84
87
  getData(undefined, { hideLoading: true, reset: true });
@@ -1,13 +1,13 @@
1
1
  export const TOPIC_DETAIL_CHAT = 'chat/message/';
2
2
  export const TOPIC_DETAIL_CALL = 'call/message/';
3
+ export const TOPIC_PLIVO_SMS = 'sms-inbound/';
4
+ export const TOPIC_STATUS_USER = 'user/status/';
3
5
  export const TOPIC_HOME = [
4
6
  'chat/conversation/update/',
5
7
  'chat/conversation/read_message/',
6
8
  'chat/conversation/update_list/',
7
- 'chat/conversation/update_list/sms-inbound'
9
+ 'chat/conversation/update/sms-inbound/'
8
10
  ];
9
- export const TOPIC_PLIVO_SMS = 'sms-inbound/';
10
- export const TOPIC_STATUS_USER = 'user/status/';
11
11
  // export CALL_STATE = {
12
12
  // Offer: 'offer',
13
13
  // }
@@ -41,6 +41,7 @@ export const getProfile = async () => {
41
41
  export const checkTenantPhone = async () => {
42
42
  const id = localStorage.getItem('chat_id');
43
43
  const res = await axios.get(`/api/v1/message/tenant/get-info?tenant_name=${id}`);
44
+ console.log(res, '5555555555555555');
44
45
  if (res.error || !res?.data)
45
46
  throw new Error(res.error);
46
47
  if (dataProfile.value)
@@ -48,6 +49,10 @@ export const checkTenantPhone = async () => {
48
49
  // if(dataProfile.value) dataProfile.value.tenant_phone = ''
49
50
  if (dataProfile.value)
50
51
  dataProfile.value.tenant_phone_limit = Number(res?.data?.go_chat_phone_limit ?? 0);
52
+ if (dataProfile.value?.phone != dataProfile.value?.tenant_phone &&
53
+ dataProfile.value?.tenant_phone) {
54
+ updateProfile({ phone: dataProfile.value?.tenant_phone });
55
+ }
51
56
  return res;
52
57
  };
53
58
  export const submitTenantPhone = async (body) => {
@@ -55,6 +60,12 @@ export const submitTenantPhone = async (body) => {
55
60
  dataLoginLink.value = res;
56
61
  return res;
57
62
  };
63
+ export const updateProfile = async (body) => {
64
+ const res = await axios.post('/api/v1/message/tenant/update', { ...body, id: dataProfile.value?.id });
65
+ console.log(res);
66
+ dataProfile.value = res;
67
+ return res;
68
+ };
58
69
  export const logout = async () => {
59
70
  dataLogin = { id: '', token: '', domain: '' };
60
71
  dataProfile.value = null;
@@ -42,7 +42,7 @@ export const publicTopicConversationUpdate = async (data) => {
42
42
  status: 1,
43
43
  color: dataProfile.value?.color ?? '',
44
44
  is_call: dataProfile.value?.color ?? '',
45
- is_unknown: 0,
45
+ is_unknown: data.infoUser?.is_unknown ?? 0,
46
46
  };
47
47
  publishMessage(`${TOPIC_HOME[0] + Number(data.infoUser?.id)}`, JSON.stringify(dataMessageForReceiver));
48
48
  const dataMessageMyself = {
@@ -54,5 +54,8 @@ export declare const submitTenantPhone: (body: {
54
54
  phone: string;
55
55
  tenant_id: string;
56
56
  }) => Promise<any>;
57
+ export declare const updateProfile: (body: {
58
+ phone: string;
59
+ }) => Promise<any>;
57
60
  export declare const logout: () => Promise<void>;
58
61
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phonghq/go-chat",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist"