@bcc-code/vue-bcc-chat-ui 3.13.0 → 3.14.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.13.0",
5
+ "version": "3.14.1",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -11,7 +11,6 @@ import {
11
11
  inject,
12
12
  Ref,
13
13
  onBeforeUnmount,
14
- onBeforeMount,
15
14
  onMounted,
16
15
  } from "vue";
17
16
  import { ChatInstance } from "../chat/types";
@@ -25,6 +24,7 @@ const props = defineProps({
25
24
 
26
25
  const chatInstance = inject<Ref<ChatInstance>>("chatInstance");
27
26
  const vueInstance: any = getCurrentInstance();
27
+ const msgComposerData = vueInstance?.parent?.type?.name === "CometChatMessageComposer" && vueInstance?.parent?.setupState;
28
28
 
29
29
  const { theme } = inject("theme", { theme: ref(new CometChatTheme({})) });
30
30
 
@@ -50,8 +50,16 @@ const onMessageSend = CometChatMessageEvents.ccMessageSent.subscribe(
50
50
  }
51
51
  );
52
52
 
53
- onBeforeMount(() => {
54
- vueInstance?.parent?.setupState?.closePreview();
53
+ onMounted(() => {
54
+ if (msgComposerData) {
55
+ msgComposerData.inputRef.querySelector(".messageinput-input").focus()
56
+ if (msgComposerData.messageToBeEdited) {
57
+ msgComposerData.messageToBeEdited = null;
58
+ msgComposerData.messageText = "";
59
+ msgComposerData.textRef = "";
60
+ msgComposerData.inputRef?.emptyInputField();
61
+ }
62
+ }
55
63
  });
56
64
 
57
65
  onBeforeUnmount(() => {
@@ -59,14 +67,6 @@ onBeforeUnmount(() => {
59
67
  onMessageSend.unsubscribe();
60
68
  });
61
69
 
62
- onMounted(() => {
63
- let inputField = document.querySelector(".messageinput-input");
64
-
65
- if (inputField) {
66
- inputField.innerHTML = props?.captionedAttachment?.caption ?? "";
67
- }
68
- })
69
-
70
70
  const closeBtnIconStyle = () => {
71
71
  return {
72
72
  buttonIconTint: theme.value.palette.getAccent500(),
@@ -14,7 +14,7 @@ import chat from "../chat";
14
14
  import { connect, disconnect } from "../chat/connection";
15
15
  import { loggedIn } from "../chat/login";
16
16
  import { CometChatMessages } from "../chat/cometChatPatches";
17
- import { BaseMessage, Group, CometChat } from "@cometchat/chat-sdk-javascript";
17
+ import { Group } from "@cometchat/chat-sdk-javascript";
18
18
  import { watchAndApplyStyle } from "../chat/styleFix";
19
19
  import {
20
20
  getMessageComposerConfiguration,
@@ -62,17 +62,6 @@ const onMessageSend = CometChatMessageEvents.ccMessageSent.subscribe(({ message,
62
62
  }
63
63
 
64
64
  (message as any)?.setMetadata(metadata);
65
-
66
- if (chatInstance.value?.captionedAttachment?.caption && message instanceof CometChat.MediaMessage) {
67
- message.setCaption(chatInstance.value.captionedAttachment.caption);
68
- let inputField = document.querySelector(".messageinput-input");
69
-
70
- if (inputField) {
71
- inputField.innerHTML = "";
72
- }
73
- chatInstance.value.captionedAttachment = null;
74
- messageComposerConfiguration.value.text = '';
75
- }
76
65
  }
77
66
  });
78
67
 
@@ -104,14 +93,7 @@ watchEffect(() => {
104
93
  }
105
94
 
106
95
  messageComposerConfiguration.value.sendButtonView = {
107
- componentName: BccChatSendButton,
108
- props: {
109
- msgComposerConfig: messageComposerConfiguration.value,
110
- fileObject: chatInstance.value.captionedAttachment.fileObject,
111
- receiverId: chatGroup.value?.getGuid(),
112
- receiverType: "group",
113
- messageType: "image"
114
- }
96
+ componentName: BccChatSendButton
115
97
  };
116
98
  }
117
99
  });
@@ -1,16 +1,9 @@
1
1
  <script setup lang="ts">
2
2
  import { localize } from "@cometchat/uikit-resources";
3
3
  import { SendIcon } from "@cometchat/chat-uikit-vue";
4
- import { MessageComposerConfiguration } from "@cometchat/uikit-shared";
5
4
  import { sendMediaMessage } from "../chat/captionedAttachment";
6
-
7
- const props = defineProps({
8
- msgComposerConfig: { type: MessageComposerConfiguration, required: true },
9
- fileObject: { type: File, required: true },
10
- receiverId: { type: String, required: true },
11
- receiverType: { type: String, required: true },
12
- messageType: { type: String, required: true }
13
- });
5
+ import { ChatInstance } from "../chat/types";
6
+ import { getCurrentInstance, inject, onBeforeUnmount, onMounted, Ref } from "vue";
14
7
 
15
8
  const sendButtonIconURL = SendIcon;
16
9
  const sendButtonStyle = {
@@ -22,16 +15,71 @@ const sendButtonStyle = {
22
15
  background: "transparent"
23
16
  }
24
17
 
25
- function sendMessageWithoutCaption() {
26
- sendMediaMessage(props.msgComposerConfig, props.fileObject, props.receiverId, props.receiverType, props.messageType);
18
+ const chatInstance = inject<Ref<ChatInstance>>("chatInstance");
19
+ const vueInstance: any = getCurrentInstance();
20
+ const msgComposerData = vueInstance?.parent?.type?.name === "CometChatMessageComposer" && vueInstance?.parent?.setupState;
21
+ const msgComposerProps = vueInstance?.parent?.type?.name === "CometChatMessageComposer" && vueInstance?.parent?.props;
22
+
23
+ function sendMessage() {
24
+ if (!msgComposerData) return false;
25
+ if (!chatInstance?.value.captionedAttachment?.fileObject) return false;
26
+ if (!msgComposerProps?.group && !msgComposerProps?.user) return false;
27
+
28
+ const receiverId = msgComposerProps?.group?.getGuid() || msgComposerProps?.user?.getUid();
29
+ const receiverType = msgComposerProps?.group ? "group" : "user";
30
+ const fileObject = chatInstance.value.captionedAttachment.fileObject;
31
+ const caption = msgComposerData.messageText;
32
+
33
+ const sendMessageResult = sendMediaMessage(msgComposerProps, fileObject, receiverId, receiverType, "image", caption);
34
+ if (sendMessageResult) {
35
+ msgComposerData.showSendButton = false;
36
+ // Clear text input
37
+ msgComposerData.messageText = "";
38
+ msgComposerData.textRef = "";
39
+ msgComposerData.inputRef?.emptyInputField();
40
+ return true;
41
+ }
42
+ return false;
43
+ }
44
+
45
+ function sendMessageOnEnter(textEnteredEvent: CustomEventInit) {
46
+ if (!msgComposerData) return;
47
+ msgComposerData.messageText = textEnteredEvent.detail.value;
48
+ if (sendMessage()) {
49
+ msgComposerData.showMentionsCountWarning = false;
50
+ msgComposerData.showListForMentions = false;
51
+ }
52
+ }
53
+
54
+ // The following will send the message when **enter is pressed** in the input box and the input box **is not empty**.
55
+ const originalSendMessageOnEnter = msgComposerData?.sendMessageOnEnter;
56
+ onMounted(() => {
57
+ if (!msgComposerData) return;
58
+ msgComposerData.sendMessageOnEnter = sendMessageOnEnter;
59
+ });
60
+ onBeforeUnmount(() => {
61
+ msgComposerData.sendMessageOnEnter = originalSendMessageOnEnter;
62
+ });
63
+
64
+ if (chatInstance) {
65
+ // Here we add an additional onKeyDown event on the input field that sends our image when pressing Enter if the input field **is empty**.
66
+ // 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.
67
+ const ccTextInputs = document.querySelectorAll(`.${chatInstance.value.componentId} cometchat-text-input .messageinput-input`);
68
+ const ccTextInput = ccTextInputs[ccTextInputs.length - 1];
69
+ (ccTextInput as Element & {onkeydown: Function}).onkeydown = (function(onkeydown){
70
+ return function(this: any, e: KeyboardEvent) {
71
+ if (chatInstance.value.captionedAttachment?.caption?.trim() == "" && e.keyCode === 13 && !e.shiftKey) sendMessage();
72
+ else if (onkeydown) return onkeydown.bind(this)(e);
73
+ }
74
+ })((ccTextInput as Element & {onkeydown: Function}).onkeydown);
27
75
  }
28
76
 
29
77
  </script>
30
78
 
31
79
  <template>
32
- <div class="cc-messagecomposer-wrapper__sendbutton" ref="sendButton">
80
+ <div class="cc-messagecomposer-wrapper__sendbutton" ref="sendButton" :style="{ 'background': !msgComposerData || !msgComposerProps ? '#f00' : 'unset'}">
33
81
  <cometchat-button :iconURL="sendButtonIconURL" :buttonStyle="sendButtonStyle"
34
- :hoverText="localize('SEND_MESSAGE')" @click=sendMessageWithoutCaption() />
82
+ :hoverText="localize('SEND_MESSAGE')" @click=sendMessage() />
35
83
  </div>
36
84
  </template>
37
85
 
@@ -11,7 +11,7 @@ import {
11
11
  inject,
12
12
  Ref,
13
13
  onBeforeUnmount,
14
- onBeforeMount,
14
+ onMounted,
15
15
  } from "vue";
16
16
  import { ChatInstance } from "../chat/types";
17
17
  import { ReplyPreviewStyle } from "../chat/replyStyle";
@@ -27,6 +27,7 @@ const props = defineProps({
27
27
 
28
28
  const chatInstance = inject<Ref<ChatInstance>>("chatInstance");
29
29
  const vueInstance: any = getCurrentInstance();
30
+ const msgComposerData = vueInstance?.parent?.type?.name === "CometChatMessageComposer" && vueInstance?.parent?.setupState;
30
31
 
31
32
  const { theme } = inject("theme", { theme: ref(new CometChatTheme({})) });
32
33
  const previewStyle = new ReplyPreviewStyle(props.previewStyle, theme.value);
@@ -53,11 +54,21 @@ const onMessageSend = CometChatMessageEvents.ccMessageSent.subscribe(
53
54
  }
54
55
  );
55
56
 
56
- onBeforeMount(() => {
57
- vueInstance?.parent?.setupState?.closePreview();
57
+ onMounted(() => {
58
+ if (msgComposerData) {
59
+ msgComposerData.actionSheetRef.style.display="none";
60
+ msgComposerData.inputRef.querySelector(".messageinput-input").focus()
61
+ if (msgComposerData.messageToBeEdited) {
62
+ msgComposerData.messageToBeEdited = null;
63
+ msgComposerData.messageText = "";
64
+ msgComposerData.textRef = "";
65
+ msgComposerData.inputRef?.emptyInputField();
66
+ }
67
+ }
58
68
  });
59
69
 
60
70
  onBeforeUnmount(() => {
71
+ msgComposerData.actionSheetRef.style.removeProperty("display");
61
72
  onMessageEditStart.unsubscribe();
62
73
  onMessageSend.unsubscribe();
63
74
  });