@webitel/ui-chats 0.1.47 → 0.1.49
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 +1 -1
- package/src/ui/messaging/composables/useChatScroll.ts +1 -1
- package/src/ui/messaging/composables/useObserveHeightUntilStable.ts +17 -19
- package/src/ui/messaging/modules/message/components/chat-message.vue +1 -1
- package/src/ui/messaging/modules/message/components/details/chat-message-document.vue +3 -2
- package/src/ui/messaging/modules/message/components/details/chat-message-player.vue +1 -1
- package/src/ui/messaging/modules/message/composables/useChatMessage.ts +2 -2
- package/src/ui/messaging/modules/message/composables/useChatMessageFile.ts +2 -2
- package/types/.tsbuildinfo +1 -1
- package/types/ui/messaging/composables/useObserveHeightUntilStable.d.ts +3 -3
- package/types/ui/messaging/modules/message/components/details/chat-message-player.vue.d.ts +1 -1
- package/types/ui/messaging/modules/message/composables/useChatMessageFile.d.ts +1 -1
package/package.json
CHANGED
|
@@ -3,15 +3,17 @@ import { onUnmounted, type Ref } from 'vue';
|
|
|
3
3
|
/**
|
|
4
4
|
* @author PolinaSukhorukova-webitel
|
|
5
5
|
*
|
|
6
|
-
* Fires the callback on every resize and
|
|
7
|
-
*
|
|
6
|
+
* Fires the callback on every resize of the target element and stops
|
|
7
|
+
* either after the given timeout or on unmount.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export const useObserveHeightUntilStable = (
|
|
11
|
-
|
|
11
|
+
target: Ref<HTMLElement | null>,
|
|
12
12
|
callback: () => void,
|
|
13
|
+
timeout?: number,
|
|
13
14
|
) => {
|
|
14
15
|
let observer: ResizeObserver | null = null;
|
|
16
|
+
let stopTimer: ReturnType<typeof setTimeout> | null = null;
|
|
15
17
|
let isViewportTransition = false;
|
|
16
18
|
let viewportTransitionTimer: ReturnType<typeof setTimeout> | null = null;
|
|
17
19
|
|
|
@@ -23,35 +25,31 @@ export const useObserveHeightUntilStable = (
|
|
|
23
25
|
viewportTransitionTimer = setTimeout(() => {
|
|
24
26
|
isViewportTransition = false;
|
|
25
27
|
viewportTransitionTimer = null;
|
|
26
|
-
},
|
|
28
|
+
}, 1000);
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
const stopObserve = () => {
|
|
30
32
|
observer?.disconnect();
|
|
31
33
|
observer = null;
|
|
34
|
+
|
|
35
|
+
if (stopTimer) {
|
|
36
|
+
clearTimeout(stopTimer);
|
|
37
|
+
stopTimer = null;
|
|
38
|
+
}
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
const startObserve = () => {
|
|
35
|
-
if (!
|
|
36
|
-
|
|
37
|
-
let lastClientHeight = chatContainer.value.clientHeight;
|
|
38
|
-
let stableCount = 0;
|
|
42
|
+
if (!target.value) return;
|
|
39
43
|
|
|
40
44
|
observer = new ResizeObserver(() => {
|
|
41
|
-
const currentClientHeight = chatContainer.value?.clientHeight;
|
|
42
|
-
|
|
43
45
|
if (!isViewportTransition) callback();
|
|
44
|
-
|
|
45
|
-
if (currentClientHeight === lastClientHeight) {
|
|
46
|
-
stableCount++;
|
|
47
|
-
if (stableCount >= 2) stopObserve();
|
|
48
|
-
} else {
|
|
49
|
-
stableCount = 0;
|
|
50
|
-
lastClientHeight = currentClientHeight;
|
|
51
|
-
}
|
|
52
46
|
});
|
|
53
47
|
|
|
54
|
-
observer.observe(
|
|
48
|
+
observer.observe(target.value);
|
|
49
|
+
|
|
50
|
+
if (timeout !== undefined) {
|
|
51
|
+
stopTimer = setTimeout(stopObserve, timeout);
|
|
52
|
+
}
|
|
55
53
|
};
|
|
56
54
|
|
|
57
55
|
/**
|
|
@@ -136,7 +136,7 @@ const isTransferAgent = computed(
|
|
|
136
136
|
|
|
137
137
|
const isBot = computed<boolean>(() => props.message.member?.type === 'bot');
|
|
138
138
|
|
|
139
|
-
const getClientUsername = computed<string>(() => {
|
|
139
|
+
const getClientUsername = computed<string | undefined>(() => {
|
|
140
140
|
if (isTransferAgent.value) return props.message.member?.name;
|
|
141
141
|
if (isSelfSide.value) return props?.agentName;
|
|
142
142
|
|
|
@@ -38,11 +38,12 @@ const documentSize = computed(() => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
function downloadDocument() {
|
|
41
|
-
if (!props.file) return;
|
|
41
|
+
if (!props.file?.url) return;
|
|
42
42
|
const a = document.createElement('a');
|
|
43
43
|
a.href = props.file.url;
|
|
44
44
|
a.target = '_blank';
|
|
45
|
-
|
|
45
|
+
// empty `download` lets the browser derive the filename from the URL
|
|
46
|
+
a.download = props.file.name ?? '';
|
|
46
47
|
a.click();
|
|
47
48
|
}
|
|
48
49
|
</script>
|
|
@@ -15,8 +15,8 @@ export const useChatMessages = (
|
|
|
15
15
|
) => {
|
|
16
16
|
function showChatDate(index: number): boolean {
|
|
17
17
|
const { prevMessage, message } = getMessage(index);
|
|
18
|
-
const prevDate =
|
|
19
|
-
const currentDate =
|
|
18
|
+
const prevDate = Number(prevMessage?.createdAt) || 0;
|
|
19
|
+
const currentDate = Number(message?.createdAt) || 0;
|
|
20
20
|
return (
|
|
21
21
|
!!prevMessage &&
|
|
22
22
|
formatDate(prevDate, FormatDateMode.DATE) !==
|
|
@@ -3,7 +3,7 @@ import { computed, type Ref, toRef } from 'vue';
|
|
|
3
3
|
import type { ChatMessageFile } from '../../../types/ChatMessage.types';
|
|
4
4
|
|
|
5
5
|
export function useChatMessageFile(
|
|
6
|
-
file: ChatMessageFile | Ref<ChatMessageFile
|
|
6
|
+
file: ChatMessageFile | Ref<ChatMessageFile | undefined> | undefined,
|
|
7
7
|
) {
|
|
8
8
|
const fileRef = toRef(file);
|
|
9
9
|
|
|
@@ -30,7 +30,7 @@ export function useChatMessageFile(
|
|
|
30
30
|
);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
const isMediaType = (value: string) => {
|
|
33
|
+
const isMediaType = (value: string | undefined) => {
|
|
34
34
|
return !!(value?.includes('audio') || value?.includes('video'));
|
|
35
35
|
};
|
|
36
36
|
|