@bcc-code/vue-bcc-chat-ui 3.41.0 → 4.0.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": "3.41.0",
5
+ "version": "4.0.1",
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,46 +54,63 @@ 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)
83
93
  }
84
94
 
85
95
  if (chatGroup.value) {
96
+
97
+ let isChannel = (chatGroup.value.getMetadata() as any).isChannel;
98
+
86
99
  watchAndApplyStyle(".bcc-chat-message-list-wrapper", [
87
100
  {
88
101
  selector: ".cc-messagebubble-wrapper__container",
89
102
  style: {
90
- "max-width": (chatGroup.value.getMetadata() as any).isChannel ? "95%" : "80%"
103
+ "max-width": isChannel ? "95%" : "80%"
91
104
  }
92
105
  }
93
106
  ])
94
107
 
95
- getGroupMembersInfo(_chatUid).then((participants) => groupMembers.value = participants);
108
+ if (!isChannel) {
109
+ getGroupMembersInfo(_chatUid).then((participants) => groupMembers.value = participants);
110
+ } else {
111
+ groupMembers.value = [];
112
+ }
113
+
96
114
  }
97
115
 
98
116
  await chat.clearGroupChatCount(props.chatUid);
@@ -211,9 +229,15 @@ function closeScheduledMessage() {
211
229
  <BccScheduledMessages v-else-if="chatGroup && chatInstance.showScheduledMessagesChat"
212
230
  class="bcc-scheduled-message-list" :chatGroup="chatInstance.scheduledMessageChat!"
213
231
  :originalChatUid="props.chatUid" @close="closeScheduledMessage()"></BccScheduledMessages>
232
+ <div v-else-if="chat.onlineStatus.value === 'offline'" class="bcc-chat-message-list-offline">
233
+ <span>Waiting for network...</span>
234
+ </div>
214
235
  <div v-else-if="!chat.connected.value" class="bcc-chat-message-list-offline">
215
236
  <span>Connecting...</span>
216
237
  </div>
238
+ <div v-else-if="chatGroupNotFound" class="bcc-chat-message-list-offline">
239
+ <span>Chat not found...</span>
240
+ </div>
217
241
  <div v-else-if="!chatGroup" class="bcc-chat-message-list-offline">
218
242
  <span>Loading chat...</span>
219
243
  </div>
@@ -290,6 +314,8 @@ accent900: text in avatar
290
314
  --cc__link-color: #cfeac8;
291
315
  }
292
316
 
317
+
318
+
293
319
  .bcc-chat-message-list {
294
320
  height: 100%;
295
321
 
@@ -345,26 +371,35 @@ accent900: text in avatar
345
371
  }
346
372
  }
347
373
 
374
+
348
375
  /* 2. Message for Messages Composer when offline */
349
376
  .bcc-chat-message-composer-offline {
350
377
  position: relative;
351
- top: -96px;
352
- height: 96px;
378
+ bottom: 38px;
379
+ text-align: center;
380
+ //height: 96px;
353
381
  width: 100%;
354
- backdrop-filter: blur(4px);
382
+ //backdrop-filter: blur(4px);
355
383
  color: var(--cc__text-color);
356
- font: 700 1rem sans-serif;
384
+ font: 500 11px sans-serif;
357
385
 
358
386
  /* 2.1 Text of Messages Composer offline view */
359
387
  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;
388
+ width: 150px;
389
+ display: inline;
390
+ padding: 5px;
391
+ background-color: #eee;
392
+ border-radius: 8px;
366
393
  }
367
394
  }
395
+
396
+ /* Hide send button when offline */
397
+ &.offline .messageinput__primaryactions,
398
+ &.offline .messageinput__auxiliaryactions,
399
+ &.offline .messageinput__secondaryactions {
400
+ opacity: 0.2;
401
+ }
402
+
368
403
  }
369
404
 
370
405
  .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 {};