@bcc-code/vue-bcc-chat-ui 1.6.3 → 2.0.0

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.6.3",
5
+ "version": "2.0.0",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -22,7 +22,6 @@
22
22
  "vue": "^3.0.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/lodash-es": "^4.17.12",
26
25
  "@types/node": "^20.11.25",
27
26
  "@vitejs/plugin-vue": "^4.6.2",
28
27
  "path": "^0.12.7",
@@ -37,8 +36,7 @@
37
36
  "@cometchat/chat-uikit-vue": "^4.2.1",
38
37
  "@cometchat/uikit-resources": "^4.2.2",
39
38
  "@cometchat/uikit-shared": "^4.2.2",
40
- "jwt-decode": "^4.0.0",
41
- "lodash-es": "^4.17.21"
39
+ "jwt-decode": "^4.0.0"
42
40
  },
43
41
  "scripts": {
44
42
  "dev": "vite",
@@ -1,23 +1,12 @@
1
1
  <script setup lang="ts">
2
- import { onBeforeMount, onMounted, onUnmounted, ref, nextTick, watch, Ref } from "vue";
2
+ import { onBeforeMount, onMounted, onUnmounted, ref, watchEffect } from "vue";
3
3
  import chat from "../chat";
4
- import { connect, disconnect, connected } from "../chat/connection";
4
+ import { connect, disconnect } from "../chat/connection";
5
5
  import { loggedIn } from "../chat/login";
6
-
7
- import {
8
- CometChatMessages,
9
- CometChatMessageTemplate,
10
- CometChatUIKit,
11
- ImageBubbleStyle,
12
- MessageBubbleAlignment,
13
- } 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 { watchAndApplyStyle } from "../chat/mobileView";
6
+ import { CometChatMessages } from "@cometchat/chat-uikit-vue";
7
+ import { Group } from "@cometchat/chat-sdk-javascript";
8
+ import { watchAndApplyStyle } from "../chat/styleFix";
9
+ import { messageComposerConfiguration, messageListConfiguration } from "../chat/uiKit";
21
10
 
22
11
  const props = defineProps({
23
12
  chatUid: { type: String, required: true },
@@ -26,176 +15,61 @@ const props = defineProps({
26
15
  const componentId = ref(
27
16
  `component-${Math.random().toString(36).substring(2, 11)}`
28
17
  );
29
- const chatGroup = ref<Group | null>(null);
30
-
31
- watch(chatGroup, (exists: null) => {
32
- if (!exists) return;
33
-
34
- nextTick(() => {
35
- watchAndApplyStyle(
36
- ".bcc-chat-message-list",
37
- [{
38
- selector: '.cc__imageviewer__close-button',
39
- style: { "padding-top": "env(safe-area-inset-top)" },
40
- shadowDomSelector: 'cometchat-full-screen-viewer'
41
- }, {
42
- selector: '.cc__text',
43
- style: { color: 'var(--cc__text-color)' },
44
- shadowDomSelector: 'cometchat-text-bubble'
45
- }, {
46
- selector: '.cc__linkpreview-title',
47
- style: { color: 'var(--cc__text-color)' },
48
- shadowDomSelector: 'link-preview'
49
- }]
50
- );
51
- });
18
+ const chatGroup = ref<Group>();
19
+
20
+ onMounted(() => {
21
+ watchAndApplyStyle(
22
+ ".bcc-chat-message-list-wrapper",
23
+ [{
24
+ selector: '.cc__imageviewer__close-button',
25
+ style: { "padding-top": "env(safe-area-inset-top)" },
26
+ shadowDomSelector: 'cometchat-full-screen-viewer'
27
+ }, {
28
+ selector: '.cc__text',
29
+ style: { color: 'var(--cc__text-color)' },
30
+ shadowDomSelector: 'cometchat-text-bubble'
31
+ }, {
32
+ selector: '.cc__linkpreview-title',
33
+ style: { color: 'var(--cc__text-color)' },
34
+ shadowDomSelector: 'link-preview'
35
+ }]
36
+ );
52
37
  })
53
38
 
54
39
  onBeforeMount(async () => {
55
40
  await connect(componentId.value);
56
- await loadData();
57
41
  });
58
42
 
59
43
  onUnmounted(async () => {
60
44
  await disconnect(componentId.value);
61
45
  });
62
46
 
63
- watch(
64
- [loggedIn, connected, chat.initialized, () => props.chatUid],
65
- () => {
66
- loadData();
67
- }
68
- );
69
-
70
- // Loads data if logged in
71
- const loadData = async () => {
72
- if (
73
- loggedIn.value &&
74
- chat.initialized.value
75
- ) {
76
- initTemplates();
77
- if (props.chatUid) {
78
- // Retreive group
79
- chatGroup.value = await chat.data.getGroup(props.chatUid);
80
-
81
- // Clear group chat count - assume user is viewing chat
82
- if (chatGroup.value) {
83
- await chat.data.clearGroupChatCount(props.chatUid);
84
- }
85
- } else {
86
- chatGroup.value = null;
87
- }
47
+ watchEffect(async () => {
48
+ if (loggedIn.value && props.chatUid && chat.initialized.value) {
49
+ chatGroup.value = await chat.getGroup(props.chatUid) ?? undefined;
50
+ await chat.clearGroupChatCount(props.chatUid);
88
51
  } else {
89
- if (!loggedIn.value) {
90
- chatGroup.value = null;
91
- }
92
- }
93
- };
94
-
95
- const messageComposerConfiguration = new MessageComposerConfiguration({
96
- hideLiveReaction: true,
97
- hideVoiceRecording: true,
98
- });
99
- const messageListConfiguration: Ref<any> = ref(null);
100
-
101
- // Templates cannot be initialized before CometChat is initiazlied
102
- // CometChatUIKit.getDataSource().getAllMessageTemplates() will return null before cometchat is initialized
103
- // So we postpone overriding the templates until cometchat is logged in
104
- let templatesInitialized = false;
105
- const initTemplates = () => {
106
- if (templatesInitialized) {
107
- return;
108
- }
109
- templatesInitialized = true;
110
- messageListConfiguration.value = getMessageListConfiguration();
111
- };
112
-
113
- // Override message list configuration
114
- function getMessageListConfiguration(): MessageListConfiguration {
115
- let templates = CometChatUIKit.getDataSource()
116
- .getAllMessageTemplates()
117
- .map((template: CometChatMessageTemplate) => {
118
- // Override options
119
- template.options = (
120
- loggedInUser: User,
121
- message: BaseMessage,
122
- theme: CometChatTheme,
123
- group: Group | undefined
124
- ) => {
125
- return getOptionsView(loggedInUser, message, theme, group);
126
- };
127
-
128
- // Override image styling
129
- if (template.category === "message" && template.type === "image") {
130
- template.contentView = getImageMessageContentView;
131
- }
132
- return template;
133
- });
134
-
135
- function getImageMessageContentView(
136
- message: CometChat.BaseMessage,
137
- _alignment: MessageBubbleAlignment
138
- ) {
139
- if (message.getDeletedAt()) {
140
- return CometChatUIKit.getDataSource().getDeleteMessageBubble(
141
- message,
142
- new CometChatTheme({})
143
- );
144
- }
145
- return {
146
- componentName: "CometChatImageBubble",
147
- props: {
148
- src: message.getData().url,
149
- imageStyle: new ImageBubbleStyle({
150
- // you can adjust image styles here
151
- width: "100%",
152
- height: "100%",
153
- }),
154
- },
155
- };
52
+ chatGroup.value = undefined;
156
53
  }
54
+ })
157
55
 
158
- const getOptionsView = (
159
- loggedInUser: User,
160
- message: BaseMessage,
161
- theme: any,
162
- group: Group | undefined
163
- ) => {
164
- const optionsData = CometChatUIKit.getDataSource().getMessageOptions(
165
- loggedInUser,
166
- message,
167
- theme,
168
- group
169
- );
170
- const customOptionsView = optionsData.filter(
171
- (ele) => ele.id !== "sendMessagePrivately"
172
- );
173
- return customOptionsView;
174
- };
175
-
176
- return new MessageListConfiguration({
177
- scrollToBottomOnNewMessages: true,
178
- templates: templates,
179
- });
180
- }
181
56
  </script>
182
57
 
183
58
  <template>
184
- <div v-if="chatGroup" class="bcc-chat-message-list">
185
- <CometChatMessages
186
- :hideMessageHeader="true"
187
- :disableSoundForMessages="true"
188
- :messageComposerConfiguration="messageComposerConfiguration"
189
- :messageListConfiguration="messageListConfiguration"
190
- :hideMessageComposer="false"
191
- :hideDetails="true"
192
- :group="chatGroup"
193
- />
194
- <div v-if="!connected" class="bcc-chat-message-composer-offline">
195
- <span>Offline</span>
59
+ <div class="bcc-chat-message-list-wrapper">
60
+ <div v-if="chatGroup" class="bcc-chat-message-list">
61
+ <CometChatMessages
62
+ :hideMessageHeader="true"
63
+ :disableSoundForMessages="true"
64
+ :messageComposerConfiguration="messageComposerConfiguration"
65
+ :messageListConfiguration="messageListConfiguration"
66
+ :hideMessageComposer="false"
67
+ :hideDetails="true"
68
+ :group="chatGroup"
69
+ />
196
70
  </div>
71
+ <div class="bcc-chat-message-list-offline"><span>Waiting for connection...</span></div>
197
72
  </div>
198
- <div class="bcc-chat-message-list-offline"><span>Waiting for connection...</span></div>
199
73
  </template>
200
74
 
201
75
  <style lang="scss">
@@ -209,6 +83,11 @@ body {
209
83
  }
210
84
  }
211
85
 
86
+ .bcc-chat-message-list-wrapper {
87
+ position: relative;
88
+ height: 100%;
89
+ }
90
+
212
91
  /*
213
92
  primary: my bubble
214
93
  accent: message bar text