@bcc-code/vue-bcc-chat-ui 3.0.0-alpha.9 → 3.1.2
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
|
@@ -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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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:
|
|
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);
|
|
@@ -38,13 +37,19 @@ watch([loggedIn, ()=>props.chatUid, chat.initialized], async ([_loggedIn, _chatU
|
|
|
38
37
|
}
|
|
39
38
|
}, { immediate: true });
|
|
40
39
|
|
|
41
|
-
watch(chat.onlineStatus,
|
|
42
|
-
|
|
40
|
+
watch(chat.onlineStatus, () => {
|
|
41
|
+
tryConnect(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
watch(chat.onlineMode, () => {
|
|
45
|
+
if (chat.onlineMode.value == 'online'){
|
|
46
|
+
tryConnect(true);
|
|
47
|
+
}
|
|
43
48
|
});
|
|
44
49
|
|
|
45
50
|
const showChat = ref(false);
|
|
46
|
-
|
|
47
|
-
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')){
|
|
48
53
|
showChat.value = true;
|
|
49
54
|
} else {
|
|
50
55
|
// This line is a trade-off.
|
|
@@ -55,12 +60,17 @@ watchEffect(() => {
|
|
|
55
60
|
// wouldn't be lost...
|
|
56
61
|
showChat.value = false;
|
|
57
62
|
}
|
|
58
|
-
})
|
|
63
|
+
}, { immediate: true });
|
|
59
64
|
|
|
65
|
+
let _connecting = false;
|
|
60
66
|
async function tryConnect(force: boolean) {
|
|
61
|
-
console.log('CONNECTING::::');
|
|
62
67
|
if (chat.onlineStatus.value === "online" || force) {
|
|
63
|
-
|
|
68
|
+
if (!_connecting){
|
|
69
|
+
try {
|
|
70
|
+
await connect(componentId.value);
|
|
71
|
+
} catch { }
|
|
72
|
+
_connecting = false;
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
76
|
|
|
@@ -119,26 +129,20 @@ onUnmounted(async () => {
|
|
|
119
129
|
await disconnect(componentId.value);
|
|
120
130
|
});
|
|
121
131
|
|
|
122
|
-
const cometChatStatus = ref('');
|
|
123
|
-
function getCometChatStatus(){
|
|
124
|
-
cometChatStatus.value = new Date().getTime() + CometChat.getConnectionStatus();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
132
|
</script>
|
|
128
133
|
|
|
129
134
|
<template>
|
|
130
135
|
<div class="bcc-chat-message-list-wrapper">
|
|
131
|
-
<div>
|
|
136
|
+
<!-- <div>
|
|
132
137
|
<div>Connecting... <button @click="tryConnect(true)">[retry]</button></div>
|
|
133
138
|
<div>Online status: {{chat.onlineStatus}}</div>
|
|
134
139
|
<div>Online mode: {{chat.onlineMode}}</div>
|
|
135
140
|
<div>Connected: {{chat.connected.value}}</div>
|
|
136
141
|
<div>Connecting: {{chat.connecting.value}}</div>
|
|
137
142
|
<div>CometChat: {{cometChatStatus}} <button @click="getCometChatStatus()">[refresh]</button></div>
|
|
138
|
-
</div>
|
|
143
|
+
</div> -->
|
|
139
144
|
<div v-if="showChat" class="bcc-chat-message-list">
|
|
140
|
-
|
|
141
|
-
<CometChatMessages
|
|
145
|
+
<CometChatMessages
|
|
142
146
|
:hideMessageHeader="true"
|
|
143
147
|
:disableSoundForMessages="true"
|
|
144
148
|
:messageComposerConfiguration="messageComposerConfiguration"
|
|
@@ -155,7 +159,7 @@ function getCometChatStatus(){
|
|
|
155
159
|
</div>
|
|
156
160
|
</div>
|
|
157
161
|
<div v-else-if="!chat.connected.value" class="bcc-chat-message-list-offline">
|
|
158
|
-
<span>Connecting
|
|
162
|
+
<span>Connecting...</span>
|
|
159
163
|
</div>
|
|
160
164
|
<div v-else-if="!chatGroup" class="bcc-chat-message-list-offline">
|
|
161
165
|
<span>Loading chat...</span>
|
|
@@ -263,7 +267,8 @@ accent900: text in avatar
|
|
|
263
267
|
top: -96px;
|
|
264
268
|
height: 96px;
|
|
265
269
|
width: 100%;
|
|
266
|
-
|
|
270
|
+
backdrop-filter: blur(4px);
|
|
271
|
+
color: var(--cc__text-color);
|
|
267
272
|
font: 700 1rem sans-serif;
|
|
268
273
|
|
|
269
274
|
/* 2.1 Text of Messages Composer offline view */
|
|
@@ -273,7 +278,6 @@ accent900: text in avatar
|
|
|
273
278
|
display: flex;
|
|
274
279
|
justify-content: center;
|
|
275
280
|
align-items: center;
|
|
276
|
-
background: rgba(255, 255, 255, 0.75);
|
|
277
281
|
border-radius: 8px 8px 0 0;
|
|
278
282
|
}
|
|
279
283
|
}
|