@bcc-code/vue-bcc-chat-ui 1.1.0 → 1.1.1

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
@@ -2,7 +2,7 @@
2
2
  "name": "@bcc-code/vue-bcc-chat-ui",
3
3
  "author": "bcc-code",
4
4
  "license": "Apache-2.0",
5
- "version": "1.1.0",
5
+ "version": "1.1.1",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -1,38 +1,54 @@
1
1
  <script setup lang="ts">
2
- import { onUnmounted, ref, watchEffect } from 'vue'
2
+ import { onBeforeMount, onUnmounted, ref } from 'vue'
3
3
  import chat from '../chat';
4
4
  import { CometChatMessages } from '@cometchat/chat-uikit-vue'
5
5
  import { Group } from '@cometchat/chat-sdk-javascript';
6
+ import { watch } from 'vue';
6
7
  //import { ThreadedMessagesStyle } from '@cometchat/uikit-shared';
7
8
 
8
9
  const props = defineProps({
9
- accessToken: {type: String, required: true},
10
10
  chatUid: {type: String, required: true},
11
11
  })
12
12
 
13
- const connected = ref(false);
13
+ const componentId = ref(`component-${Math.random().toString(36).substring(2, 11)}`);
14
14
  const chatGroup = ref<Group>();
15
- const user = ref();
16
15
 
17
- watchEffect(async () => {
18
- if (props.accessToken) {
19
- user.value = await chat.connection.connect(props.accessToken);
20
- chatGroup.value = await chat.data.getGroup(props.chatUid);
21
- connected.value = true
22
- }
23
- })
16
+ onBeforeMount(async() => {
17
+ await connnect();
18
+ await loadData();
19
+ });
20
+
21
+ watch(chat.connection.connected, async () => {
22
+ await loadData();
23
+ });
24
24
 
25
25
  onUnmounted(async () => {
26
- if (connected.value){
27
- await chat.connection.disconnect();
28
- connected.value = false;
26
+ await disconnect();
27
+ });
28
+
29
+ // Disconnects from chat server
30
+ const disconnect = async () => {
31
+ await chat.connection.disconnect(componentId.value);
32
+ };
33
+
34
+ // Connect to chat server
35
+ const connnect = async() => {
36
+ await chat.connection.connect(componentId.value);
37
+ };
38
+
39
+ // Loads data if chat is connected
40
+ const loadData = async () => {
41
+ if (chat.connection.connected.value && props.chatUid) {
42
+ chatGroup.value = await chat.data.getGroup(props.chatUid);
43
+ } else {
44
+ chatGroup.value = undefined;
29
45
  }
30
- })
46
+ };
31
47
 
32
48
  </script>
33
49
 
34
50
  <template>
35
- <div v-if="connected" class="bcc-chat-message-list">
51
+ <div v-if="chatGroup" class="bcc-chat-message-list">
36
52
  <CometChatMessages :hideMessageHeader="true" :hideMessageComposer="false" :hideDetails="true" :group="chatGroup"></CometChatMessages>
37
53
  </div>
38
54
  </template>