@bcc-code/vue-bcc-chat-ui 3.1.0 → 3.2.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.1.0",
5
+ "version": "3.2.0",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -1,28 +1,27 @@
1
1
  <script setup lang="ts">
2
2
  import MarkdownIt from 'markdown-it'
3
+ import { User } from '@cometchat/chat-sdk-javascript'
3
4
 
4
- defineProps<{
5
+ const props = defineProps<{
5
6
  text: string,
6
7
  metadata: Record<string, any>,
8
+ mentionedUsers: User[],
7
9
  }>()
8
10
 
9
11
  function toMarkdownHtml(str: string) {
10
- // Regex to match URLs that may or may not start with "www." and are not already part of a Markdown link
11
- const urlRegex = /([^\]]\(|[^\(]|^\(?)((?:https?|ftp):\/\/[^\s\]\)]*|www\.[^\s\]\)]+)(?=[\s\]\)](?!\()|$)/g;
12
-
13
- // Function to format a URL into a Markdown link
14
- const formatUrlToMarkdown = (_match: string, group1: string, group2: string) => {
15
- let url = group2;
16
- // Prepend "http://" to URLs starting with "www."
17
- if (url.startsWith('www.')) {
18
- url = 'http://' + url;
19
- }
20
- const hostname = new URL(url).hostname;
21
- return `${group1}[${hostname}](${url})`;
22
- };
12
+ // Regex to match URLs that may or may not start with "www." and are not already part of a Markdown link
13
+ const urlRegex = /([^\]]\(|[^\(]|^\(?)((?:https?|ftp):\/\/[^\s\]\)]*|www\.[^\s\]\)]+)(?=[\s\]\)](?!\()|$)/g;
23
14
 
24
15
  // Replacing URLs in the string with Markdown links
25
- const outStr = str.replace(urlRegex, formatUrlToMarkdown);
16
+ let outStr = str.replace(urlRegex, formatUrlToMarkdown);
17
+
18
+ outStr = formatMentionsInText(outStr);
19
+
20
+ outStr = cleanUpHTML(outStr);
21
+ if (outStr.includes('<div>')) {
22
+ console.log('outStr', outStr);
23
+ }
24
+
26
25
  const md = new MarkdownIt({
27
26
  breaks: true,
28
27
  typographer: true,
@@ -30,6 +29,43 @@ function toMarkdownHtml(str: string) {
30
29
 
31
30
  return md.render(outStr);
32
31
  }
32
+
33
+ // Function to format a URL into a Markdown link
34
+ function formatUrlToMarkdown(_match: string, group1: string, group2: string) {
35
+ let url = group2;
36
+ // Prepend "http://" to URLs starting with "www."
37
+ if (url.startsWith('www.')) {
38
+ url = 'http://' + url;
39
+ }
40
+ const hostname = new URL(url).hostname;
41
+ return `${group1}[${hostname}](${url})`;
42
+ };
43
+
44
+ function formatMentionsInText(text: string) {
45
+ return text.replace(/<@uid:(.*?)>/g, (_match: string, uid: string) => {
46
+ const user = (props.mentionedUsers || []).find((user) => user.getUid() === uid);
47
+ // Check if a userName exists for the given uid; if not, keep the original match
48
+ if (user) {
49
+ return `**${user.getName()}**`;
50
+ } else {
51
+ return `**@unknown**`;
52
+ }
53
+ });
54
+ }
55
+
56
+ // Due to how mobile adds line breaks we need to remove them
57
+ function cleanUpHTML(input: string) {
58
+ // Step 1: Replace <div><br></div> with <br>
59
+ let cleaned = input.replace(/<div><br><\/div>/g, '\n');
60
+
61
+ // Step 2: Replace opening <div> that follows any content or at the start with <br>
62
+ cleaned = cleaned.replace(/(^|<\/div>)(<div>)/g, '$1\n');
63
+
64
+ // Step 3: Remove all remaining <div> and </div> tags
65
+ cleaned = cleaned.replace(/<\/?div>/g, '');
66
+
67
+ return cleaned;
68
+ }
33
69
  </script>
34
70
 
35
71
  <template>
@@ -58,7 +94,7 @@ function toMarkdownHtml(str: string) {
58
94
  line-height: 1.2;
59
95
  word-break: break-word;
60
96
  text-align: left;
61
- white-space: pre-line;
97
+ white-space: normal;
62
98
  margin: 8px 0;
63
99
  }
64
100
 
@@ -13,7 +13,6 @@ import { loggedIn } from "../chat/login";
13
13
  import { CometChatMessages } from "@cometchat/chat-uikit-vue";
14
14
  import { Group } from "@cometchat/chat-sdk-javascript";
15
15
  import { watchAndApplyStyle } from "../chat/styleFix";
16
- //import { CometChat } from "@cometchat/chat-sdk-javascript";
17
16
  import {
18
17
  messageComposerConfiguration,
19
18
  messageListConfiguration,
@@ -29,7 +28,7 @@ const componentId = ref(
29
28
  );
30
29
  const chatGroup = ref<Group>();
31
30
 
32
- watch([loggedIn, ()=>props.chatUid, chat.initialized], async ([_loggedIn, _chatUid, _initialized]) => {
31
+ watch([loggedIn, ()=> props.chatUid, chat.initialized], async ([_loggedIn, _chatUid, _initialized]) => {
33
32
  if (_loggedIn && _chatUid && _initialized) {
34
33
  chatGroup.value = (await chat.getGroup(props.chatUid)) ?? undefined;
35
34
  await chat.clearGroupChatCount(props.chatUid);
@@ -49,8 +48,8 @@ watch(chat.onlineMode, () => {
49
48
  });
50
49
 
51
50
  const showChat = ref(false);
52
- watchEffect(() => {
53
- if (chatGroup && (chat.connected.value || chat.onlineStatus.value == 'offline')){
51
+ watch([chat.connected, chat.onlineStatus], () => {
52
+ if (chatGroup.value && (chat.connected.value || chat.onlineStatus.value == 'offline')){
54
53
  showChat.value = true;
55
54
  } else {
56
55
  // This line is a trade-off.
@@ -61,7 +60,7 @@ watchEffect(() => {
61
60
  // wouldn't be lost...
62
61
  showChat.value = false;
63
62
  }
64
- })
63
+ }, { immediate: true });
65
64
 
66
65
  let _connecting = false;
67
66
  async function tryConnect(force: boolean) {
@@ -130,11 +129,6 @@ onUnmounted(async () => {
130
129
  await disconnect(componentId.value);
131
130
  });
132
131
 
133
- // const cometChatStatus = ref('');
134
- // function getCometChatStatus(){
135
- // cometChatStatus.value = new Date().getTime() + CometChat.getConnectionStatus();
136
- // }
137
-
138
132
  </script>
139
133
 
140
134
  <template>
@@ -148,8 +142,7 @@ onUnmounted(async () => {
148
142
  <div>CometChat: {{cometChatStatus}} <button @click="getCometChatStatus()">[refresh]</button></div>
149
143
  </div> -->
150
144
  <div v-if="showChat" class="bcc-chat-message-list">
151
-
152
- <CometChatMessages
145
+ <CometChatMessages
153
146
  :hideMessageHeader="true"
154
147
  :disableSoundForMessages="true"
155
148
  :messageComposerConfiguration="messageComposerConfiguration"
@@ -274,7 +267,8 @@ accent900: text in avatar
274
267
  top: -96px;
275
268
  height: 96px;
276
269
  width: 100%;
277
- color: rgb(176, 176, 176);
270
+ backdrop-filter: blur(4px);
271
+ color: var(--cc__text-color);
278
272
  font: 700 1rem sans-serif;
279
273
 
280
274
  /* 2.1 Text of Messages Composer offline view */
@@ -284,7 +278,6 @@ accent900: text in avatar
284
278
  display: flex;
285
279
  justify-content: center;
286
280
  align-items: center;
287
- background: rgba(255, 255, 255, 0.75);
288
281
  border-radius: 8px 8px 0 0;
289
282
  }
290
283
  }