@bcc-code/vue-bcc-chat-ui 3.41.0 → 4.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": "3.41.0",
5
+ "version": "4.0.0",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -34,6 +34,7 @@ const componentId = ref(
34
34
  `component-${Math.random().toString(36).substring(2, 11)}`
35
35
  );
36
36
  const chatGroup = ref<Group>();
37
+ const chatGroupNotFound = ref(false);
37
38
 
38
39
  const emit = defineEmits(['groupMembersFetched']);
39
40
  const groupMembers = ref<ParticipantInfo[]>();
@@ -53,30 +54,39 @@ const chatInstance: Ref<ChatInstance> = ref({
53
54
  provide("chatInstance", chatInstance);
54
55
 
55
56
  const onMessageSend = CometChatMessageEvents.ccMessageSent.subscribe(({ message, status }) => {
56
- if (status === MessageStatus.inprogress) {
57
- let metadata: any = (message as any)?.getMetadata() || {};
58
- let scope: string | undefined = chatGroup.value?.getScope();
57
+ if (status !== MessageStatus.inprogress) {
58
+ return
59
+ }
59
60
 
60
- if (chatInstance.value.replyToMessage) {
61
- metadata.replyToMessageId = chatInstance.value.replyToMessage?.getId();
62
- chatInstance.value.replyToMessage = null;
63
- }
61
+ let metadata: any = (message as any)?.getMetadata() || {};
62
+ let scope: string | undefined = chatGroup.value?.getScope();
64
63
 
65
- if (props.senderDisplayName && scope == "moderator") {
66
- metadata.senderDisplayName = props.senderDisplayName
67
- }
64
+ if (chatInstance.value.replyToMessage) {
65
+ metadata.replyToMessageId = chatInstance.value.replyToMessage?.getId();
66
+ chatInstance.value.replyToMessage = null;
67
+ }
68
68
 
69
- (message as any)?.setMetadata(metadata);
69
+ if (props.senderDisplayName && scope == "moderator") {
70
+ metadata.senderDisplayName = props.senderDisplayName
70
71
  }
72
+
73
+ const muid = window.crypto.randomUUID();
74
+ message.setMuid(muid);
75
+ const tags = (message as any).getTags() ?? [];
76
+ tags.push(muid);
77
+ (message as any).setTags(tags);
78
+ (message as any).setMetadata(metadata);
71
79
  });
72
80
 
73
- watch([loggedIn, () => props.chatUid, chat.initialized, () => props.groupMessageGetter], async ([_loggedIn, _chatUid, _initialized, _groupMessageGetter]) => {
81
+ watch([loggedIn, chat.onlineStatus, () => props.chatUid, chat.initialized, () => props.groupMessageGetter], async ([_loggedIn, _online, _chatUid, _initialized, _groupMessageGetter]) => {
74
82
  if (_loggedIn && _chatUid && _initialized) {
83
+ chatGroupNotFound.value = false;
75
84
  const [_, group] = await Promise.all([
76
85
  connect(componentId.value),
77
86
  chat.getGroup(props.chatUid)
78
87
  ])
79
88
  chatGroup.value = group ?? undefined;
89
+ chatGroupNotFound.value = group === undefined;
80
90
 
81
91
  if (_groupMessageGetter && !chatGroup.value?.getHasJoined()) {
82
92
  chat.updateGetGroupMessages(_groupMessageGetter)
@@ -211,9 +221,15 @@ function closeScheduledMessage() {
211
221
  <BccScheduledMessages v-else-if="chatGroup && chatInstance.showScheduledMessagesChat"
212
222
  class="bcc-scheduled-message-list" :chatGroup="chatInstance.scheduledMessageChat!"
213
223
  :originalChatUid="props.chatUid" @close="closeScheduledMessage()"></BccScheduledMessages>
224
+ <div v-else-if="chat.onlineStatus.value === 'offline'" class="bcc-chat-message-list-offline">
225
+ <span>Waiting for network...</span>
226
+ </div>
214
227
  <div v-else-if="!chat.connected.value" class="bcc-chat-message-list-offline">
215
228
  <span>Connecting...</span>
216
229
  </div>
230
+ <div v-else-if="chatGroupNotFound" class="bcc-chat-message-list-offline">
231
+ <span>Chat not found...</span>
232
+ </div>
217
233
  <div v-else-if="!chatGroup" class="bcc-chat-message-list-offline">
218
234
  <span>Loading chat...</span>
219
235
  </div>
@@ -290,6 +306,8 @@ accent900: text in avatar
290
306
  --cc__link-color: #cfeac8;
291
307
  }
292
308
 
309
+
310
+
293
311
  .bcc-chat-message-list {
294
312
  height: 100%;
295
313
 
@@ -345,26 +363,35 @@ accent900: text in avatar
345
363
  }
346
364
  }
347
365
 
366
+
348
367
  /* 2. Message for Messages Composer when offline */
349
368
  .bcc-chat-message-composer-offline {
350
369
  position: relative;
351
- top: -96px;
352
- height: 96px;
370
+ bottom: 38px;
371
+ text-align: center;
372
+ //height: 96px;
353
373
  width: 100%;
354
- backdrop-filter: blur(4px);
374
+ //backdrop-filter: blur(4px);
355
375
  color: var(--cc__text-color);
356
- font: 700 1rem sans-serif;
376
+ font: 500 11px sans-serif;
357
377
 
358
378
  /* 2.1 Text of Messages Composer offline view */
359
379
  span {
360
- width: 100%;
361
- height: 100%;
362
- display: flex;
363
- justify-content: center;
364
- align-items: center;
365
- border-radius: 8px 8px 0 0;
380
+ width: 150px;
381
+ display: inline;
382
+ padding: 5px;
383
+ background-color: #eee;
384
+ border-radius: 8px;
366
385
  }
367
386
  }
387
+
388
+ /* Hide send button when offline */
389
+ &.offline .messageinput__primaryactions,
390
+ &.offline .messageinput__auxiliaryactions,
391
+ &.offline .messageinput__secondaryactions {
392
+ opacity: 0.2;
393
+ }
394
+
368
395
  }
369
396
 
370
397
  .bcc-chat-message-list-offline {
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import chat from "../chat";
3
3
  import { Group } from "@cometchat/chat-sdk-javascript";
4
- import { inject, nextTick, onMounted, Ref, ref, watch, watchEffect } from 'vue';
4
+ import { computed, inject, nextTick, onMounted, Ref, ref, watch, watchEffect } from 'vue';
5
5
  import { ChatInstance } from '../chat/types';
6
6
  import BccAttachmentBox from "./BccAttachmentBox.vue";
7
7
  import BccChatSendButton from "./BccChatSendButton.vue";
@@ -15,6 +15,8 @@ const props = defineProps({
15
15
  hideDeletedMessages: { type: Boolean, required: false, default: false }
16
16
  })
17
17
 
18
+ const isOffline = computed(() => chat.onlineStatus.value === 'offline');
19
+
18
20
  const chatGroup = ref<Group>();
19
21
 
20
22
  const chatInstance = inject<Ref<ChatInstance>>("chatInstance");
@@ -185,16 +187,16 @@ function isParticipant(): boolean {
185
187
  </script>
186
188
 
187
189
  <template>
188
- <div class="bcc-chat-message-list">
190
+ <div :class="'bcc-chat-message-list' + (isOffline ? ' offline' : '')">
189
191
  <CometChatMessages :hideMessageHeader="true" :disableSoundForMessages="true"
190
192
  :messageComposerConfiguration="messageComposerConfiguration"
191
193
  :messageListConfiguration="messageListConfiguration"
192
194
  :threadedMessagesConfiguration="threadedMessagesConfiguration"
193
- :hideMessageComposer="isParticipant() && isChannel()" :hideDetails="true" :group="chatGroup" />
195
+ :hideMessageComposer="(isParticipant() && isChannel())" :hideDetails="true" :group="chatGroup" />
194
196
  <div v-if="chat.onlineStatus.value === 'offline' || !chat.connected.value"
195
197
  class="bcc-chat-message-composer-offline">
196
- <span v-if="chat.onlineStatus.value === 'offline'">Waiting for network...</span>
197
- <span v-else>Connecting...</span>
198
+ <span v-if="isOffline">Waiting for network...</span>
199
+ <span v-else>Connecting... </span>
198
200
  </div>
199
201
  <!-- <BccScheduledMessageModal v-if="showModal" @close="closeModal()" @send="scheduleMessage">
200
202
  </BccScheduledMessageModal>
@@ -4,6 +4,7 @@ import { SendIcon } from "@cometchat/chat-uikit-vue";
4
4
  import { sendMediaMessage } from "../chat/captionedAttachment";
5
5
  import { ChatInstance } from "../chat/types";
6
6
  import { getCurrentInstance, inject, onBeforeUnmount, onMounted, Ref } from "vue";
7
+ import chat from "../chat";
7
8
 
8
9
  const sendButtonIconURL = SendIcon;
9
10
  const sendButtonStyle = {
@@ -21,6 +22,8 @@ const msgComposerData = vueInstance?.parent?.type?.name === "CometChatMessageCom
21
22
  const msgComposerProps = vueInstance?.parent?.type?.name === "CometChatMessageComposer" && vueInstance?.parent?.props;
22
23
 
23
24
  function sendMessage() {
25
+ debugger;
26
+ if (chat.onlineStatus.value === "offline") return;
24
27
  if (!msgComposerData) return false;
25
28
  if (!chatInstance?.value.captionedAttachment?.fileObject) return false;
26
29
  if (!msgComposerProps?.group && !msgComposerProps?.user) return false;
@@ -44,6 +47,8 @@ function sendMessage() {
44
47
  }
45
48
 
46
49
  function sendMessageOnEnter(textEnteredEvent: CustomEventInit) {
50
+ debugger;
51
+ if (chat.onlineStatus.value === "offline") return;
47
52
  if (!msgComposerData) return;
48
53
  msgComposerData.messageText = textEnteredEvent.detail.value;
49
54
  if (sendMessage()) {
@@ -66,7 +71,7 @@ if (chatInstance) {
66
71
  // Here we add an additional onKeyDown event on the input field that sends our image when pressing Enter if the input field **is empty**.
67
72
  // We need this in addition to hooking into the "cc-text-input-entered" event because that event isn't triggered if the input field is empty.
68
73
  const ccTextInput = msgComposerData.inputRef.querySelector(".messageinput-input");
69
- ccTextInput.addEventListener("keydown", function(event: KeyboardEvent) {
74
+ ccTextInput.addEventListener("keydown", function (event: KeyboardEvent) {
70
75
  if (msgComposerData.messageText?.trim() == "" && event.keyCode === 13 && !event.shiftKey) sendMessage();
71
76
  });
72
77
  }
@@ -74,7 +79,8 @@ if (chatInstance) {
74
79
  </script>
75
80
 
76
81
  <template>
77
- <div class="cc-messagecomposer-wrapper__sendbutton" ref="sendButton" :style="{ 'background': !msgComposerData || !msgComposerProps ? '#f00' : 'unset'}">
82
+ <div class="cc-messagecomposer-wrapper__sendbutton" ref="sendButton"
83
+ :style="{ 'background': !msgComposerData || !msgComposerProps ? '#f00' : 'unset' }">
78
84
  <cometchat-button :iconURL="sendButtonIconURL" :buttonStyle="sendButtonStyle"
79
85
  :hoverText="localize('SEND_MESSAGE')" @click=sendMessage() />
80
86
  </div>
@@ -85,7 +85,7 @@ onUnmounted(() => {
85
85
  <div v-if="chat.onlineStatus.value === 'offline' || !chat.connected.value"
86
86
  class="bcc-chat-message-composer-offline">
87
87
  <span v-if="chat.onlineStatus.value === 'offline'">Waiting for network...</span>
88
- <span v-else>Connecting...</span>
88
+ <span v-else>Connecting... </span>
89
89
  </div>
90
90
  <BccAlert class="absolute top-0 w-[97%] mx-2 mt-11" icon closeButton context="danger"
91
91
  :open="chatInstance!.showAlert" @close="chatInstance!.showAlert = false">
@@ -1,10 +0,0 @@
1
- interface ChatToken {
2
- sub: string;
3
- token: string;
4
- time: number;
5
- authToken: string;
6
- }
7
- export declare const retrieveCcToken: () => ChatToken | null;
8
- export declare const clearToken: () => Promise<void>;
9
- export declare const getToken: (authToken: string, chatApiBaseUrl: string) => Promise<string | null>;
10
- export {};