@bcc-code/vue-bcc-chat-ui 1.4.0 → 1.4.2

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.4.0",
5
+ "version": "1.4.2",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -22,13 +22,12 @@
22
22
  "vue": "^3.0.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/lodash-es": "^4.17.12",
26
- "@types/node": "^20.11.25",
25
+ "@types/node": "^20.11.24",
27
26
  "@vitejs/plugin-vue": "^4.6.2",
28
27
  "path": "^0.12.7",
29
28
  "sass": "^1.71.1",
30
- "typescript": "^5.4.2",
31
- "vite": "^5.1.5",
29
+ "typescript": "^5.3.3",
30
+ "vite": "^5.1.4",
32
31
  "vite-plugin-dts": "^3.7.3",
33
32
  "vue": "^3.4.21"
34
33
  },
@@ -1,83 +1,91 @@
1
1
  <script setup lang="ts">
2
- import { onBeforeMount, onUnmounted, ref } from "vue";
3
- import chat from "../chat";
4
- import { connect, disconnect } from "../chat/connection";
5
- import { loggedIn } from "../chat/login";
6
-
7
- import {
2
+ import { onBeforeMount, onMounted, onUnmounted, ref, nextTick, watch, Ref } from "vue";
3
+ import chat from '../chat';
4
+ import {
8
5
  CometChatMessages,
9
6
  CometChatMessageTemplate,
10
7
  CometChatUIKit,
11
8
  ImageBubbleStyle,
12
9
  MessageBubbleAlignment,
13
10
  } from "@cometchat/chat-uikit-vue";
14
- import {
15
- MessageListConfiguration,
16
- MessageComposerConfiguration,
17
- } from "@cometchat/uikit-shared";
18
- import { CometChatTheme } from "@cometchat/uikit-resources";
19
- import { BaseMessage, Group, User } from "@cometchat/chat-sdk-javascript";
20
- import { watch, Ref } from "vue";
11
+ import { MessageListConfiguration, MessageComposerConfiguration } from "@cometchat/uikit-shared";
12
+ import { CometChatTheme } from '@cometchat/uikit-resources'
13
+ import { BaseMessage, Group, User } from '@cometchat/chat-sdk-javascript';
14
+ import { watchAndApplyStyle } from "../chat/mobileView";
21
15
 
22
16
  //import { ThreadedMessagesStyle } from '@cometchat/uikit-shared';
23
17
 
24
18
  const props = defineProps({
25
- chatUid: { type: String, required: true },
19
+ chatUid: {type: String, required: true},
20
+ })
21
+
22
+ const componentId = ref(`component-${Math.random().toString(36).substring(2, 11)}`);
23
+ const chatGroup = ref<Group>();
24
+
25
+ watch(chatGroup, (exists: any) => {
26
+ if (!exists) return;
27
+ nextTick(() => {
28
+ watchAndApplyStyle(
29
+ ".bcc-chat-message-list",
30
+ ".cc__imageviewer__close-button",
31
+ { "padding-top": "env(safe-area-inset-top)" },
32
+ 'cometchat-full-screen-viewer'
33
+ );
34
+ });
35
+ })
36
+
37
+ onBeforeMount(async() => {
38
+ try {
39
+ await connect();
40
+ await loadData();
41
+ } catch (error) {
42
+ console.error('Failed to connect when mounting chat component', error);
43
+ }
26
44
  });
27
45
 
28
- const componentId = ref(
29
- `component-${Math.random().toString(36).substring(2, 11)}`
30
- );
31
- const chatGroup = ref<Group | null>(null);
46
+ watch(chat.connection.connected, async () => {
47
+ if (chat.connection.connected.value) {
48
+ await loadData();
49
+ }
50
+ });
32
51
 
33
- onBeforeMount(async () => {
34
- await connect(componentId.value);
35
- await loadData();
52
+ watch(() => props.chatUid, async () => {
53
+ if (chat.connection.connected.value) {
54
+ await loadData();
55
+ }
36
56
  });
37
57
 
38
58
  onUnmounted(async () => {
39
- await disconnect(componentId.value);
59
+ await disconnect();
40
60
  });
41
61
 
42
- watch(
43
- [loggedIn, chat.connection.connected, chat.initialized, () => props.chatUid],
44
- () => {
45
- loadData();
46
- }
47
- );
62
+ // Disconnects from chat server
63
+ const disconnect = async () => {
64
+ await chat.connection.disconnect(componentId.value);
65
+ };
66
+
67
+ // Connect to chat server
68
+ const connect = async() => {
69
+ await chat.connection.connect(componentId.value);
70
+ };
48
71
 
49
72
  // Loads data if chat is connected
50
- const loadData = async () => {
51
- if (
52
- loggedIn.value &&
53
- chat.initialized.value &&
54
- chat.connection.connected.value
55
- ) {
56
- initTemplates();
57
- if (props.chatUid) {
58
- // Retreive group
73
+ const loadData = async () => {
74
+ if (chat.connection.connected.value && props.chatUid) {
75
+ initTemplates();
59
76
  chatGroup.value = await chat.data.getGroup(props.chatUid);
60
-
61
- // Clear group chat count - assume user is viewing chat
62
- if (chatGroup.value) {
63
- await chat.data.clearGroupChatCount(props.chatUid);
64
- }
77
+ await chat.data.clearGroupChatCount(props.chatUid);
65
78
  } else {
66
- chatGroup.value = null;
79
+ chatGroup.value = undefined;
67
80
  }
68
- } else {
69
- if (!loggedIn.value) {
70
- chatGroup.value = null;
71
- }
72
- }
73
81
  };
74
82
 
75
83
  const messageComposerConfiguration = new MessageComposerConfiguration({
76
84
  hideLiveReaction: true,
77
- hideVoiceRecording: true,
85
+ hideVoiceRecording: true
78
86
  });
79
- const messageListConfiguration: Ref<any> = ref(null);
80
-
87
+ const messageListConfiguration:Ref<any> = ref(null);
88
+
81
89
  // Templates cannot be initialized before CometChat is initiazlied
82
90
  // CometChatUIKit.getDataSource().getAllMessageTemplates() will return null before cometchat is initialized
83
91
  // So we postpone overriding the templates until cometchat is connected
@@ -92,25 +100,16 @@ const initTemplates = () => {
92
100
 
93
101
  // Override message list configuration
94
102
  function getMessageListConfiguration(): MessageListConfiguration {
95
- let templates = CometChatUIKit.getDataSource()
96
- .getAllMessageTemplates()
97
- .map((template: CometChatMessageTemplate) => {
98
- // Override options
99
- template.options = (
100
- loggedInUser: User,
101
- message: BaseMessage,
102
- theme: CometChatTheme,
103
- group: Group | undefined
104
- ) => {
105
- return getOptionsView(loggedInUser, message, theme, group);
106
- };
107
-
108
- // Override image styling
109
- if (template.category === "message" && template.type === "image") {
110
- template.contentView = getImageMessageContentView;
111
- }
112
- return template;
113
- });
103
+ let templates = CometChatUIKit.getDataSource().getAllMessageTemplates().map((template: CometChatMessageTemplate) => {
104
+ // Override options
105
+ template.options = (loggedInUser: User, message: BaseMessage, theme: CometChatTheme, group: Group|undefined) => { return getOptionsView(loggedInUser, message, theme, group); };
106
+
107
+ // Override image styling
108
+ if (template.category === "message" && template.type === "image") {
109
+ template.contentView = getImageMessageContentView
110
+ }
111
+ return template;
112
+ });
114
113
 
115
114
  function getImageMessageContentView(
116
115
  message: CometChat.BaseMessage,
@@ -133,49 +132,40 @@ function getMessageListConfiguration(): MessageListConfiguration {
133
132
  }),
134
133
  },
135
134
  };
136
- }
135
+ };
137
136
 
138
- const getOptionsView = (
139
- loggedInUser: User,
140
- message: BaseMessage,
141
- theme: any,
142
- group: Group | undefined
143
- ) => {
144
- const optionsData = CometChatUIKit.getDataSource().getMessageOptions(
145
- loggedInUser,
146
- message,
147
- theme,
148
- group
149
- );
150
- const customOptionsView = optionsData.filter(
151
- (ele) => ele.id !== "sendMessagePrivately"
152
- );
137
+ const getOptionsView = (loggedInUser: User, message: BaseMessage, theme: any, group: Group|undefined) => {
138
+ const optionsData = CometChatUIKit.getDataSource().getMessageOptions(loggedInUser, message, theme, group);
139
+ const customOptionsView = optionsData.filter(ele => ele.id !== "sendMessagePrivately");
153
140
  return customOptionsView;
154
- };
141
+ }
142
+
155
143
 
156
144
  return new MessageListConfiguration({
157
145
  scrollToBottomOnNewMessages: true,
158
- templates: templates,
146
+ templates: templates
159
147
  });
160
148
  }
149
+
150
+
161
151
  </script>
162
152
 
163
153
  <template>
164
154
  <div v-if="chatGroup" class="bcc-chat-message-list">
165
- <CometChatMessages
166
- v-if="chatGroup"
167
- :hideMessageHeader="true"
168
- :disableSoundForMessages="true"
169
- :messageComposerConfiguration="messageComposerConfiguration"
170
- :messageListConfiguration="messageListConfiguration"
171
- :hideMessageComposer="false"
172
- :hideDetails="true"
173
- :group="chatGroup"
174
- />
155
+ <CometChatMessages
156
+ :hideMessageHeader="true"
157
+ :disableSoundForMessages="true"
158
+ :messageComposerConfiguration="messageComposerConfiguration"
159
+ :messageListConfiguration="messageListConfiguration"
160
+ :hideMessageComposer="false"
161
+ :hideDetails="true"
162
+ :group="chatGroup"
163
+ />
175
164
  </div>
176
165
  </template>
177
166
 
178
- <style lang="scss">
167
+ <style lang="scss" >
168
+
179
169
  .bcc-chat-message-list {
180
170
  height: 100%;
181
171
  /* 1. Wrapper for Messages component */
@@ -190,14 +180,13 @@ function getMessageListConfiguration(): MessageListConfiguration {
190
180
  }
191
181
  }
192
182
 
193
- .cc-messagecomposer__emojikeyboard {
194
- display: none;
183
+ .cc-messagecomposer__emojikeyboard {
184
+ display: none;
195
185
  }
196
186
 
197
187
  // Hide emoji keyboard
198
- .cc-messagecomposer__emojikeyboard {
199
- display: none;
200
- }
188
+ .cc-messagecomposer__emojikeyboard { display: none; }
189
+
201
190
 
202
191
  .cc-threadedmessages-wrapper__bubbleview::-webkit-scrollbar,
203
192
  .cc__message-list::-webkit-scrollbar {
@@ -210,4 +199,5 @@ function getMessageListConfiguration(): MessageListConfiguration {
210
199
  background: rgb(232, 229, 229);
211
200
  border-radius: 8px;
212
201
  }
213
- </style>
202
+
203
+ </style>
@@ -1,9 +0,0 @@
1
- export declare const loggedIn: import("vue").Ref<boolean>;
2
- export declare const login: (accessToken?: string | null | undefined) => Promise<boolean | undefined>;
3
- export declare const logout: () => Promise<boolean>;
4
- declare const _default: {
5
- loggedIn: import("vue").Ref<boolean>;
6
- login: (accessToken?: string | null | undefined) => Promise<boolean | undefined>;
7
- logout: () => Promise<boolean>;
8
- };
9
- export default _default;