@chat-leo/chatleo 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/dist/chatleo/chatleo.esm.js +1 -0
- package/dist/chatleo/index.esm.js +1 -0
- package/dist/chatleo/p-43ada232.entry.js +1 -0
- package/dist/chatleo/p-4485e141.entry.js +1 -0
- package/dist/chatleo/p-BnCPdbII.js +1 -0
- package/dist/chatleo/p-C-l90Wre.js +1 -0
- package/dist/chatleo/p-DQuL1Twl.js +1 -0
- package/dist/chatleo/p-DmL518NK.js +3 -0
- package/dist/chatleo/p-aed60255.entry.js +1 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
- package/dist/cjs/chatleo-avatar_13.cjs.entry.js +2986 -0
- package/dist/cjs/chatleo-call-adapter-B2OfC0VZ.js +35 -0
- package/dist/cjs/chatleo-chat-input.cjs.entry.js +67 -0
- package/dist/cjs/chatleo.cjs.js +25 -0
- package/dist/cjs/index-DkSDLR0y.js +56 -0
- package/dist/cjs/index-Dxw4YCA_.js +1741 -0
- package/dist/cjs/index.cjs.js +7 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/cjs/my-component.cjs.entry.js +33 -0
- package/dist/collection/__mocks__/stencil-core.js +26 -0
- package/dist/collection/collection-manifest.json +27 -0
- package/dist/collection/components/chatleo-avatar/chatleo-avatar.css +40 -0
- package/dist/collection/components/chatleo-avatar/chatleo-avatar.js +116 -0
- package/dist/collection/components/chatleo-chat/chatleo-chat.css +108 -0
- package/dist/collection/components/chatleo-chat/chatleo-chat.js +459 -0
- package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.css +22 -0
- package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.js +105 -0
- package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.css +84 -0
- package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.js +141 -0
- package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.css +149 -0
- package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.js +259 -0
- package/dist/collection/components/chatleo-component/chatleo-component.css +271 -0
- package/dist/collection/components/chatleo-component/chatleo-component.js +1366 -0
- package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.css +96 -0
- package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.js +231 -0
- package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.css +352 -0
- package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.js +976 -0
- package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.css +169 -0
- package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.js +400 -0
- package/dist/collection/components/chatleo-room-list/chatleo-room-list.css +111 -0
- package/dist/collection/components/chatleo-room-list/chatleo-room-list.js +180 -0
- package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.css +110 -0
- package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.js +241 -0
- package/dist/collection/components/chatleo-room-view/chatleo-room-view.css +93 -0
- package/dist/collection/components/chatleo-room-view/chatleo-room-view.js +593 -0
- package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.css +284 -0
- package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.js +391 -0
- package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.css +56 -0
- package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.js +149 -0
- package/dist/collection/components/my-component/my-component.css +4 -0
- package/dist/collection/components/my-component/my-component.js +95 -0
- package/dist/collection/index.js +10 -0
- package/dist/collection/utils/call-entry.js +34 -0
- package/dist/collection/utils/delivery.js +7 -0
- package/dist/collection/utils/utils.js +51 -0
- package/dist/components/chatleo-avatar.d.ts +11 -0
- package/dist/components/chatleo-avatar.js +1 -0
- package/dist/components/chatleo-chat-header.d.ts +11 -0
- package/dist/components/chatleo-chat-header.js +1 -0
- package/dist/components/chatleo-chat-input.d.ts +11 -0
- package/dist/components/chatleo-chat-input.js +1 -0
- package/dist/components/chatleo-chat-message.d.ts +11 -0
- package/dist/components/chatleo-chat-message.js +1 -0
- package/dist/components/chatleo-chat.d.ts +11 -0
- package/dist/components/chatleo-chat.js +1 -0
- package/dist/components/chatleo-component.d.ts +11 -0
- package/dist/components/chatleo-component.js +1 -0
- package/dist/components/chatleo-new-message-selector.d.ts +11 -0
- package/dist/components/chatleo-new-message-selector.js +1 -0
- package/dist/components/chatleo-rich-input.d.ts +11 -0
- package/dist/components/chatleo-rich-input.js +1 -0
- package/dist/components/chatleo-rich-message-renderer.d.ts +11 -0
- package/dist/components/chatleo-rich-message-renderer.js +1 -0
- package/dist/components/chatleo-room-list.d.ts +11 -0
- package/dist/components/chatleo-room-list.js +1 -0
- package/dist/components/chatleo-room-tile-component.d.ts +11 -0
- package/dist/components/chatleo-room-tile-component.js +1 -0
- package/dist/components/chatleo-room-view.d.ts +11 -0
- package/dist/components/chatleo-room-view.js +1 -0
- package/dist/components/chatleo-tray-component.d.ts +11 -0
- package/dist/components/chatleo-tray-component.js +1 -0
- package/dist/components/chatleo-user-tile.d.ts +11 -0
- package/dist/components/chatleo-user-tile.js +1 -0
- package/dist/components/index.d.ts +35 -0
- package/dist/components/index.js +1 -0
- package/dist/components/my-component.d.ts +11 -0
- package/dist/components/my-component.js +1 -0
- package/dist/components/p-8kvQ-Uh-.js +1 -0
- package/dist/components/p-B7cdqAgv.js +1 -0
- package/dist/components/p-BdiOcOYZ.js +1 -0
- package/dist/components/p-BlbDSb7D.js +1 -0
- package/dist/components/p-BnCPdbII.js +1 -0
- package/dist/components/p-C-v19aUJ.js +1 -0
- package/dist/components/p-C1mF0s8g.js +1 -0
- package/dist/components/p-CRtBdzP3.js +1 -0
- package/dist/components/p-CfayCm9O.js +1 -0
- package/dist/components/p-DGjAxoQy.js +1 -0
- package/dist/components/p-Exj_2-yI.js +1 -0
- package/dist/components/p-XlwGxsqT.js +1 -0
- package/dist/components/p-fjMaTJam.js +1 -0
- package/dist/components/p-xt4kzz3B.js +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +3 -0
- package/dist/esm/chatleo-avatar_13.entry.js +2972 -0
- package/dist/esm/chatleo-call-adapter-BnCPdbII.js +33 -0
- package/dist/esm/chatleo-chat-input.entry.js +65 -0
- package/dist/esm/chatleo.js +21 -0
- package/dist/esm/index-C-l90Wre.js +53 -0
- package/dist/esm/index-DmL518NK.js +1733 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/my-component.entry.js +31 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/__mocks__/stencil-core.d.ts +24 -0
- package/dist/types/components/chatleo-avatar/chatleo-avatar.d.ts +27 -0
- package/dist/types/components/chatleo-chat/chatleo-chat.d.ts +75 -0
- package/dist/types/components/chatleo-chat-header/chatleo-chat-header.d.ts +27 -0
- package/dist/types/components/chatleo-chat-input/chatleo-chat-input.d.ts +31 -0
- package/dist/types/components/chatleo-chat-message/chatleo-chat-message.d.ts +22 -0
- package/dist/types/components/chatleo-component/chatleo-component.d.ts +278 -0
- package/dist/types/components/chatleo-new-message-selector/chatleo-new-message-selector.d.ts +68 -0
- package/dist/types/components/chatleo-rich-input/chatleo-rich-input.d.ts +216 -0
- package/dist/types/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.d.ts +77 -0
- package/dist/types/components/chatleo-room-list/chatleo-room-list.d.ts +52 -0
- package/dist/types/components/chatleo-room-tile-component/chatleo-room-tile-component.d.ts +59 -0
- package/dist/types/components/chatleo-room-view/chatleo-room-view.d.ts +91 -0
- package/dist/types/components/chatleo-tray-component/chatleo-tray-component.d.ts +112 -0
- package/dist/types/components/chatleo-user-tile/chatleo-user-tile.d.ts +36 -0
- package/dist/types/components/my-component/my-component.d.ts +16 -0
- package/dist/types/components.d.ts +1593 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/stencil-public-runtime.d.ts +1879 -0
- package/dist/types/utils/call-entry.d.ts +9 -0
- package/dist/types/utils/delivery.d.ts +7 -0
- package/dist/types/utils/utils.d.ts +24 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +70 -3
- package/readme.md +111 -0
- package/README.md +0 -3
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import { h } from "@stencil/core";
|
|
2
|
+
import { groupMessagesByDate } from "../../utils/utils";
|
|
3
|
+
/**
|
|
4
|
+
* @component ChatleoRoomView
|
|
5
|
+
* @description This component displays a single chat room view without the room list. It shows the chat header, message display, and input area for a specific room. It communicates directly with the ChatStore to load and display messages.
|
|
6
|
+
* @property {ChatStore} chatStore - An instance of the `ChatStore` class, which manages the application's state, including rooms, messages, and user profiles.
|
|
7
|
+
* @property {string} roomId - The ID of the room to display. When this changes, the component will load messages for the new room.
|
|
8
|
+
* @property {boolean} isOnline - Indicates the current user's online status.
|
|
9
|
+
* @property {boolean} pending - If `true`, the component will display a loading state instead of the message list.
|
|
10
|
+
* @fires messageChatSent - This event is emitted when a user sends a message. The event detail contains the message payload, including the room ID, content, and sender information.
|
|
11
|
+
*/
|
|
12
|
+
export class ChatleoRoomView {
|
|
13
|
+
/**
|
|
14
|
+
* An instance of the `ChatStore` class, which manages the application's state, including rooms, messages, and user profiles.
|
|
15
|
+
*/
|
|
16
|
+
chatStore;
|
|
17
|
+
/**
|
|
18
|
+
* The ID of the room to display.
|
|
19
|
+
*/
|
|
20
|
+
roomId;
|
|
21
|
+
/**
|
|
22
|
+
* Indicates the current user's online status.
|
|
23
|
+
*/
|
|
24
|
+
isOnline = false;
|
|
25
|
+
/**
|
|
26
|
+
* If `true`, the component will display a loading state instead of the message list.
|
|
27
|
+
*/
|
|
28
|
+
pending = false;
|
|
29
|
+
/** True when the server advertises calls and the host did not disable them. */
|
|
30
|
+
callsAvailable = false;
|
|
31
|
+
/** True while this client is in the room's call (keeps the banner from showing). */
|
|
32
|
+
inCall = false;
|
|
33
|
+
callRequested;
|
|
34
|
+
_version = 0;
|
|
35
|
+
// Reference to the scroll container for messages
|
|
36
|
+
messagesContainerRef;
|
|
37
|
+
richInputRef;
|
|
38
|
+
resizeObserver;
|
|
39
|
+
stickToBottom = true;
|
|
40
|
+
// Track the last message count of the currently selected room to detect appends
|
|
41
|
+
lastMessageCount = -1;
|
|
42
|
+
// Bound event handlers for cleanup
|
|
43
|
+
boundRoomAddedHandler;
|
|
44
|
+
boundRoomMessageAddedHandler;
|
|
45
|
+
boundRoomMessageChangedHandler;
|
|
46
|
+
boundPresenceChangedHandler;
|
|
47
|
+
// Scroll-back state
|
|
48
|
+
loadingOlder = false;
|
|
49
|
+
olderExhausted = false;
|
|
50
|
+
previousScrollHeight = 0;
|
|
51
|
+
previousScrollTop = 0;
|
|
52
|
+
restoreScrollAfterRender = false;
|
|
53
|
+
/**
|
|
54
|
+
* @function onChatStoreChange
|
|
55
|
+
* @description This watcher is triggered whenever the `chatStore` prop changes. It is responsible for setting up event listeners on the new store to update the component when data changes, such as when a new room is added or a message is received.
|
|
56
|
+
* @param {ChatStore} newStore - The new `ChatStore` instance.
|
|
57
|
+
* @param {ChatStore} oldStore - The previous `ChatStore` instance.
|
|
58
|
+
*/
|
|
59
|
+
onChatStoreChange(newStore, oldStore) {
|
|
60
|
+
console.debug('ChatleoRoomView.onChatStoreChange', newStore, oldStore);
|
|
61
|
+
// Unbind old store listeners
|
|
62
|
+
if (oldStore) {
|
|
63
|
+
if (this.boundRoomAddedHandler) {
|
|
64
|
+
oldStore.removeEventListener('roomAdded', this.boundRoomAddedHandler);
|
|
65
|
+
}
|
|
66
|
+
if (this.boundRoomMessageAddedHandler) {
|
|
67
|
+
oldStore.removeEventListener('roomMessageAdded', this.boundRoomMessageAddedHandler);
|
|
68
|
+
}
|
|
69
|
+
if (this.boundRoomMessageChangedHandler) {
|
|
70
|
+
oldStore.removeEventListener('roomMessageUpdated', this.boundRoomMessageChangedHandler);
|
|
71
|
+
oldStore.removeEventListener('roomMessageRemoved', this.boundRoomMessageChangedHandler);
|
|
72
|
+
}
|
|
73
|
+
if (this.boundPresenceChangedHandler) {
|
|
74
|
+
oldStore.removeEventListener('presenceChanged', this.boundPresenceChangedHandler);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (newStore) {
|
|
78
|
+
// Create bound handlers
|
|
79
|
+
this.boundRoomAddedHandler = (r) => {
|
|
80
|
+
console.debug('roomAdded', r);
|
|
81
|
+
this._version++;
|
|
82
|
+
};
|
|
83
|
+
this.boundRoomMessageAddedHandler = (e) => {
|
|
84
|
+
console.debug('roomMessageAdded', e);
|
|
85
|
+
this._version++;
|
|
86
|
+
};
|
|
87
|
+
this.boundRoomMessageChangedHandler = (e) => {
|
|
88
|
+
console.debug('roomMessageChanged', e);
|
|
89
|
+
this._version++;
|
|
90
|
+
};
|
|
91
|
+
this.boundPresenceChangedHandler = (e) => {
|
|
92
|
+
console.debug('onPresenceChange', e);
|
|
93
|
+
this._version++;
|
|
94
|
+
};
|
|
95
|
+
// Bind to new store
|
|
96
|
+
newStore.addEventListener('roomAdded', this.boundRoomAddedHandler);
|
|
97
|
+
newStore.addEventListener('roomMessageAdded', this.boundRoomMessageAddedHandler);
|
|
98
|
+
newStore.addEventListener('roomMessageUpdated', this.boundRoomMessageChangedHandler);
|
|
99
|
+
newStore.addEventListener('roomMessageRemoved', this.boundRoomMessageChangedHandler);
|
|
100
|
+
newStore.addEventListener('presenceChanged', this.boundPresenceChangedHandler);
|
|
101
|
+
if (this.roomId) {
|
|
102
|
+
newStore.setActiveRoomId(this.roomId);
|
|
103
|
+
newStore.markRoomAsRead(this.roomId);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
disconnectedCallback() {
|
|
108
|
+
this.resizeObserver?.disconnect();
|
|
109
|
+
this.resizeObserver = undefined;
|
|
110
|
+
if (this.chatStore) {
|
|
111
|
+
if (this.boundRoomAddedHandler) {
|
|
112
|
+
this.chatStore.removeEventListener('roomAdded', this.boundRoomAddedHandler);
|
|
113
|
+
}
|
|
114
|
+
if (this.boundRoomMessageAddedHandler) {
|
|
115
|
+
this.chatStore.removeEventListener('roomMessageAdded', this.boundRoomMessageAddedHandler);
|
|
116
|
+
}
|
|
117
|
+
if (this.boundRoomMessageChangedHandler) {
|
|
118
|
+
this.chatStore.removeEventListener('roomMessageUpdated', this.boundRoomMessageChangedHandler);
|
|
119
|
+
this.chatStore.removeEventListener('roomMessageRemoved', this.boundRoomMessageChangedHandler);
|
|
120
|
+
}
|
|
121
|
+
if (this.boundPresenceChangedHandler) {
|
|
122
|
+
this.chatStore.removeEventListener('presenceChanged', this.boundPresenceChangedHandler);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Reset scroll tracking when switching rooms and report the new room as active/read. */
|
|
127
|
+
onRoomIdChanged() {
|
|
128
|
+
this.lastMessageCount = -1;
|
|
129
|
+
this.olderExhausted = false;
|
|
130
|
+
this.loadingOlder = false;
|
|
131
|
+
this.restoreScrollAfterRender = false;
|
|
132
|
+
if (this.roomId) {
|
|
133
|
+
this.chatStore?.setActiveRoomId(this.roomId);
|
|
134
|
+
this.chatStore?.markRoomAsRead(this.roomId);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
componentDidLoad() {
|
|
138
|
+
if (this.roomId) {
|
|
139
|
+
this.chatStore?.setActiveRoomId(this.roomId);
|
|
140
|
+
this.chatStore?.markRoomAsRead(this.roomId);
|
|
141
|
+
}
|
|
142
|
+
// Keep the newest message in view when the visual viewport shrinks (on-screen keyboard).
|
|
143
|
+
if (typeof ResizeObserver !== 'undefined' && this.messagesContainerRef && !this.resizeObserver) {
|
|
144
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
145
|
+
if (this.stickToBottom)
|
|
146
|
+
this.scrollToBottom();
|
|
147
|
+
});
|
|
148
|
+
this.resizeObserver.observe(this.messagesContainerRef);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// --- Host API (used by the app shell for drafts, deep links and shares) ---
|
|
152
|
+
async getDraft() {
|
|
153
|
+
return (await this.richInputRef?.getText?.()) ?? '';
|
|
154
|
+
}
|
|
155
|
+
async setDraft(text) {
|
|
156
|
+
await this.richInputRef?.setText?.(text ?? '');
|
|
157
|
+
}
|
|
158
|
+
async addFiles(files) {
|
|
159
|
+
await this.richInputRef?.addFiles?.(files ?? []);
|
|
160
|
+
}
|
|
161
|
+
async focusComposer() {
|
|
162
|
+
await this.richInputRef?.focusEditor?.();
|
|
163
|
+
}
|
|
164
|
+
messageRetryHandler(event) {
|
|
165
|
+
if (this.roomId && event.detail)
|
|
166
|
+
this.chatStore?.retryMessage(this.roomId, event.detail);
|
|
167
|
+
}
|
|
168
|
+
requestCall() {
|
|
169
|
+
if (!this.roomId)
|
|
170
|
+
return;
|
|
171
|
+
const active = this.chatStore?.activeCall(this.roomId);
|
|
172
|
+
this.callRequested.emit({ roomId: this.roomId, callId: active?.id });
|
|
173
|
+
}
|
|
174
|
+
messageDiscardHandler(event) {
|
|
175
|
+
if (this.roomId && event.detail)
|
|
176
|
+
this.chatStore?.discardMessage(this.roomId, event.detail);
|
|
177
|
+
}
|
|
178
|
+
messageChatSent;
|
|
179
|
+
// new
|
|
180
|
+
/**
|
|
181
|
+
* @function messageSendHandler
|
|
182
|
+
* @description This listener handles the `messageSend` event from the `chatleo-rich-input` component. It processes the rich content payload, sanitizing it by removing base64 image previews from attachments to reduce payload size. It then constructs a `ChatMessageSent` object and emits it.
|
|
183
|
+
* @param {CustomEvent<any>} event - The custom event containing the structured message content.
|
|
184
|
+
*/
|
|
185
|
+
messageSendHandler(event) {
|
|
186
|
+
// Guard: don't send if roomId is not set
|
|
187
|
+
if (!this.roomId) {
|
|
188
|
+
console.warn('ChatleoRoomView: Cannot send message without roomId');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Stop event propagation to prevent duplicate handling by parent components
|
|
192
|
+
event.stopPropagation();
|
|
193
|
+
console.log('Received the messageSend event: ', JSON.stringify(event.detail));
|
|
194
|
+
// Sanitize blocks: remove preview from each attachment object
|
|
195
|
+
const inputBlocks = event.detail?.blocks ?? [];
|
|
196
|
+
const sanitizedBlocks = inputBlocks.map((block) => {
|
|
197
|
+
if (block?.type === 'attachment' && Array.isArray(block.attachments)) {
|
|
198
|
+
const sanitizedAttachments = block.attachments.map((att) => {
|
|
199
|
+
const { preview, ...rest } = att ?? {};
|
|
200
|
+
return rest;
|
|
201
|
+
});
|
|
202
|
+
return { ...block, attachments: sanitizedAttachments };
|
|
203
|
+
}
|
|
204
|
+
return block;
|
|
205
|
+
});
|
|
206
|
+
this.messageChatSent.emit({
|
|
207
|
+
room_id: this.roomId,
|
|
208
|
+
// TODO: change to ChatMessageSent type
|
|
209
|
+
content: { blocks: sanitizedBlocks, version: event.detail.version },
|
|
210
|
+
content_type: 'application/json+blocks',
|
|
211
|
+
sender: this.chatStore?.profile?.id,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/** Scroll helpers */
|
|
215
|
+
scrollToBottom() {
|
|
216
|
+
if (!this.messagesContainerRef)
|
|
217
|
+
return;
|
|
218
|
+
try {
|
|
219
|
+
this.messagesContainerRef.scrollTop = this.messagesContainerRef.scrollHeight;
|
|
220
|
+
this.stickToBottom = true;
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
// best-effort only
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
scrollToBottomNextTick() {
|
|
227
|
+
requestAnimationFrame(() => this.scrollToBottom());
|
|
228
|
+
}
|
|
229
|
+
/** Load an older page when the user scrolls near the top, keeping the viewport stable. */
|
|
230
|
+
async onMessagesScroll() {
|
|
231
|
+
if (!this.roomId || !this.chatStore || !this.messagesContainerRef)
|
|
232
|
+
return;
|
|
233
|
+
const container = this.messagesContainerRef;
|
|
234
|
+
this.stickToBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - 24;
|
|
235
|
+
if (this.loadingOlder || this.olderExhausted)
|
|
236
|
+
return;
|
|
237
|
+
if (container.scrollTop > 40)
|
|
238
|
+
return;
|
|
239
|
+
this.loadingOlder = true;
|
|
240
|
+
this.previousScrollHeight = this.messagesContainerRef.scrollHeight;
|
|
241
|
+
this.previousScrollTop = this.messagesContainerRef.scrollTop;
|
|
242
|
+
const before = this.chatStore.roomMessages(this.roomId).length;
|
|
243
|
+
try {
|
|
244
|
+
const hasMore = await this.chatStore.loadOlderMessages(this.roomId);
|
|
245
|
+
const after = this.chatStore.roomMessages(this.roomId).length;
|
|
246
|
+
if (after > before)
|
|
247
|
+
this.restoreScrollAfterRender = true;
|
|
248
|
+
if (!hasMore && after === before)
|
|
249
|
+
this.olderExhausted = true;
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
this.loadingOlder = false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** After every render, if messages for the selected room changed, scroll to bottom */
|
|
256
|
+
componentDidRender() {
|
|
257
|
+
if (this.pending)
|
|
258
|
+
return;
|
|
259
|
+
if (!this.roomId)
|
|
260
|
+
return;
|
|
261
|
+
const msgs = this.chatStore?.roomMessages(this.roomId) ?? [];
|
|
262
|
+
const currentCount = msgs.length;
|
|
263
|
+
if (this.restoreScrollAfterRender && this.messagesContainerRef) {
|
|
264
|
+
const added = this.messagesContainerRef.scrollHeight - this.previousScrollHeight;
|
|
265
|
+
this.messagesContainerRef.scrollTop = this.previousScrollTop + Math.max(0, added);
|
|
266
|
+
this.restoreScrollAfterRender = false;
|
|
267
|
+
this.lastMessageCount = currentCount;
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (currentCount !== this.lastMessageCount) {
|
|
271
|
+
this.scrollToBottomNextTick();
|
|
272
|
+
this.lastMessageCount = currentCount;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @function render
|
|
277
|
+
* @description The render method for the `ChatleoRoomView` component. It displays the chat header, a list of messages grouped by date, and the chat input for a single room.
|
|
278
|
+
* @returns {any} A VNode representing the component's UI.
|
|
279
|
+
*/
|
|
280
|
+
render() {
|
|
281
|
+
const groupedMessages = groupMessagesByDate(this.chatStore?.roomMessages(this.roomId) ?? []);
|
|
282
|
+
const currentRoom = this.chatStore?.rooms.find(r => r.id === this.roomId);
|
|
283
|
+
const isReadOnly = currentRoom?.isReadOnly ?? false;
|
|
284
|
+
console.debug('ChatleoRoomView.render', groupedMessages);
|
|
285
|
+
return (h("div", { key: '3eb9ef978132245f3f6d41299123021f4a32d55b', class: "chat-container-chat" }, h("div", { key: '6bbc3f4dbdd677fcc227550627eb939af7ec17b8', class: "chat-container-header-container" }, h("chatleo-chat-header", { key: '1a17709cc4e699fdb3fcd40e39bad9d8f105fef9', name: this.chatStore?.profile?.display_name, avatar: this.chatStore?.profile?.profile_picture_url ?? undefined, isOnline: this.isOnline })), this.callsAvailable && this.roomId && (h("div", { key: 'a9696dd64448fcee1d47ea7559dd80a7993e33d0', class: "call-bar" }, this.chatStore?.activeCall(this.roomId) && !this.inCall ? (h("span", { class: "call-banner" }, this.chatStore?.activeCall(this.roomId)?.mode === 'direct' ? 'Call in progress' : 'Group call in progress')) : null, h("button", { key: '40cf2f4c7d7d1dfd9e1ebe57a9e315e1ff884d22', type: "button", class: "call-button", onClick: () => this.requestCall() }, this.inCall
|
|
286
|
+
? 'Call running'
|
|
287
|
+
: this.chatStore?.activeCall(this.roomId)
|
|
288
|
+
? 'Join call'
|
|
289
|
+
: this.chatStore?.rooms.find(room => room.id === this.roomId)?.type === 'DirectMessage'
|
|
290
|
+
? 'Call'
|
|
291
|
+
: 'Start call'))), this.pending ? (h("div", { class: "messages-container" }, h("div", null, "Loading chat..."))) : (h("div", { class: "messages-container", ref: el => (this.messagesContainerRef = el), onScroll: () => this.onMessagesScroll() }, Object.entries(groupedMessages)
|
|
292
|
+
.sort(([dateA], [dateB]) => new Date(dateA).getTime() - new Date(dateB).getTime())
|
|
293
|
+
.map(([date, messages]) => (h("div", { class: "message-group" }, h("div", { class: "date-separator" }, date), messages.map(message => (h("chatleo-chat-message", { message: message, sender: this.chatStore?.usernameResolver(message.sender_id), senderIsOnline: message.sender_id === this.chatStore?.profile.id ? this.chatStore?.isConnected : this.chatStore?.isOnline(message.sender_id), isOwnMessage: message.sender_id === this.chatStore?.profile.id, translations: { you: this.chatStore?.usernameResolver(message.sender_id)?.display_name } })))))))), !isReadOnly && (h("div", { key: '42592e707c67d41114596fdcf654631c2f39ee6e', class: "rich-input-container-wrapper" }, h("chatleo-rich-input", { key: '2a4fd69962ca7c2ac3c0ded1f5b46088855d9cea', ref: el => (this.richInputRef = el), disabled: !this.roomId, placeholder: 'Nachricht schreiben' })))));
|
|
294
|
+
}
|
|
295
|
+
static get is() { return "chatleo-room-view"; }
|
|
296
|
+
static get encapsulation() { return "shadow"; }
|
|
297
|
+
static get originalStyleUrls() {
|
|
298
|
+
return {
|
|
299
|
+
"$": ["chatleo-room-view.css"]
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
static get styleUrls() {
|
|
303
|
+
return {
|
|
304
|
+
"$": ["chatleo-room-view.css"]
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
static get properties() {
|
|
308
|
+
return {
|
|
309
|
+
"chatStore": {
|
|
310
|
+
"type": "unknown",
|
|
311
|
+
"mutable": false,
|
|
312
|
+
"complexType": {
|
|
313
|
+
"original": "ChatStore",
|
|
314
|
+
"resolved": "ChatStore",
|
|
315
|
+
"references": {
|
|
316
|
+
"ChatStore": {
|
|
317
|
+
"location": "import",
|
|
318
|
+
"path": "@chat-leo/chatleolib",
|
|
319
|
+
"id": "../chatleolib/dist/ChatStore.d.ts::ChatStore",
|
|
320
|
+
"referenceLocation": "ChatStore"
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
"required": false,
|
|
325
|
+
"optional": true,
|
|
326
|
+
"docs": {
|
|
327
|
+
"tags": [],
|
|
328
|
+
"text": "An instance of the `ChatStore` class, which manages the application's state, including rooms, messages, and user profiles."
|
|
329
|
+
},
|
|
330
|
+
"getter": false,
|
|
331
|
+
"setter": false
|
|
332
|
+
},
|
|
333
|
+
"roomId": {
|
|
334
|
+
"type": "string",
|
|
335
|
+
"mutable": false,
|
|
336
|
+
"complexType": {
|
|
337
|
+
"original": "string",
|
|
338
|
+
"resolved": "string",
|
|
339
|
+
"references": {}
|
|
340
|
+
},
|
|
341
|
+
"required": false,
|
|
342
|
+
"optional": true,
|
|
343
|
+
"docs": {
|
|
344
|
+
"tags": [],
|
|
345
|
+
"text": "The ID of the room to display."
|
|
346
|
+
},
|
|
347
|
+
"getter": false,
|
|
348
|
+
"setter": false,
|
|
349
|
+
"reflect": false,
|
|
350
|
+
"attribute": "room-id"
|
|
351
|
+
},
|
|
352
|
+
"isOnline": {
|
|
353
|
+
"type": "boolean",
|
|
354
|
+
"mutable": false,
|
|
355
|
+
"complexType": {
|
|
356
|
+
"original": "boolean",
|
|
357
|
+
"resolved": "boolean",
|
|
358
|
+
"references": {}
|
|
359
|
+
},
|
|
360
|
+
"required": false,
|
|
361
|
+
"optional": false,
|
|
362
|
+
"docs": {
|
|
363
|
+
"tags": [],
|
|
364
|
+
"text": "Indicates the current user's online status."
|
|
365
|
+
},
|
|
366
|
+
"getter": false,
|
|
367
|
+
"setter": false,
|
|
368
|
+
"reflect": false,
|
|
369
|
+
"attribute": "is-online",
|
|
370
|
+
"defaultValue": "false"
|
|
371
|
+
},
|
|
372
|
+
"pending": {
|
|
373
|
+
"type": "boolean",
|
|
374
|
+
"mutable": false,
|
|
375
|
+
"complexType": {
|
|
376
|
+
"original": "boolean",
|
|
377
|
+
"resolved": "boolean",
|
|
378
|
+
"references": {}
|
|
379
|
+
},
|
|
380
|
+
"required": false,
|
|
381
|
+
"optional": true,
|
|
382
|
+
"docs": {
|
|
383
|
+
"tags": [],
|
|
384
|
+
"text": "If `true`, the component will display a loading state instead of the message list."
|
|
385
|
+
},
|
|
386
|
+
"getter": false,
|
|
387
|
+
"setter": false,
|
|
388
|
+
"reflect": false,
|
|
389
|
+
"attribute": "pending",
|
|
390
|
+
"defaultValue": "false"
|
|
391
|
+
},
|
|
392
|
+
"callsAvailable": {
|
|
393
|
+
"type": "boolean",
|
|
394
|
+
"mutable": false,
|
|
395
|
+
"complexType": {
|
|
396
|
+
"original": "boolean",
|
|
397
|
+
"resolved": "boolean",
|
|
398
|
+
"references": {}
|
|
399
|
+
},
|
|
400
|
+
"required": false,
|
|
401
|
+
"optional": false,
|
|
402
|
+
"docs": {
|
|
403
|
+
"tags": [],
|
|
404
|
+
"text": "True when the server advertises calls and the host did not disable them."
|
|
405
|
+
},
|
|
406
|
+
"getter": false,
|
|
407
|
+
"setter": false,
|
|
408
|
+
"reflect": false,
|
|
409
|
+
"attribute": "calls-available",
|
|
410
|
+
"defaultValue": "false"
|
|
411
|
+
},
|
|
412
|
+
"inCall": {
|
|
413
|
+
"type": "boolean",
|
|
414
|
+
"mutable": false,
|
|
415
|
+
"complexType": {
|
|
416
|
+
"original": "boolean",
|
|
417
|
+
"resolved": "boolean",
|
|
418
|
+
"references": {}
|
|
419
|
+
},
|
|
420
|
+
"required": false,
|
|
421
|
+
"optional": false,
|
|
422
|
+
"docs": {
|
|
423
|
+
"tags": [],
|
|
424
|
+
"text": "True while this client is in the room's call (keeps the banner from showing)."
|
|
425
|
+
},
|
|
426
|
+
"getter": false,
|
|
427
|
+
"setter": false,
|
|
428
|
+
"reflect": false,
|
|
429
|
+
"attribute": "in-call",
|
|
430
|
+
"defaultValue": "false"
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
static get states() {
|
|
435
|
+
return {
|
|
436
|
+
"_version": {}
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
static get events() {
|
|
440
|
+
return [{
|
|
441
|
+
"method": "callRequested",
|
|
442
|
+
"name": "callRequested",
|
|
443
|
+
"bubbles": true,
|
|
444
|
+
"cancelable": true,
|
|
445
|
+
"composed": true,
|
|
446
|
+
"docs": {
|
|
447
|
+
"tags": [],
|
|
448
|
+
"text": ""
|
|
449
|
+
},
|
|
450
|
+
"complexType": {
|
|
451
|
+
"original": "{ roomId: string; callId?: string }",
|
|
452
|
+
"resolved": "{ roomId: string; callId?: string; }",
|
|
453
|
+
"references": {}
|
|
454
|
+
}
|
|
455
|
+
}, {
|
|
456
|
+
"method": "messageChatSent",
|
|
457
|
+
"name": "messageChatSent",
|
|
458
|
+
"bubbles": true,
|
|
459
|
+
"cancelable": true,
|
|
460
|
+
"composed": true,
|
|
461
|
+
"docs": {
|
|
462
|
+
"tags": [],
|
|
463
|
+
"text": ""
|
|
464
|
+
},
|
|
465
|
+
"complexType": {
|
|
466
|
+
"original": "ChatMessageSent",
|
|
467
|
+
"resolved": "{ room_id: string; content: any; content_type: string; sender: string; }",
|
|
468
|
+
"references": {
|
|
469
|
+
"ChatMessageSent": {
|
|
470
|
+
"location": "import",
|
|
471
|
+
"path": "@chat-leo/chatleolib",
|
|
472
|
+
"id": "../chatleolib/dist/index.d.ts::ChatMessageSent",
|
|
473
|
+
"referenceLocation": "ChatMessageSent"
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}];
|
|
478
|
+
}
|
|
479
|
+
static get methods() {
|
|
480
|
+
return {
|
|
481
|
+
"getDraft": {
|
|
482
|
+
"complexType": {
|
|
483
|
+
"signature": "() => Promise<string>",
|
|
484
|
+
"parameters": [],
|
|
485
|
+
"references": {
|
|
486
|
+
"Promise": {
|
|
487
|
+
"location": "global",
|
|
488
|
+
"id": "global::Promise"
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
"return": "Promise<string>"
|
|
492
|
+
},
|
|
493
|
+
"docs": {
|
|
494
|
+
"text": "",
|
|
495
|
+
"tags": []
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
"setDraft": {
|
|
499
|
+
"complexType": {
|
|
500
|
+
"signature": "(text: string) => Promise<void>",
|
|
501
|
+
"parameters": [{
|
|
502
|
+
"name": "text",
|
|
503
|
+
"type": "string",
|
|
504
|
+
"docs": ""
|
|
505
|
+
}],
|
|
506
|
+
"references": {
|
|
507
|
+
"Promise": {
|
|
508
|
+
"location": "global",
|
|
509
|
+
"id": "global::Promise"
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
"return": "Promise<void>"
|
|
513
|
+
},
|
|
514
|
+
"docs": {
|
|
515
|
+
"text": "",
|
|
516
|
+
"tags": []
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
"addFiles": {
|
|
520
|
+
"complexType": {
|
|
521
|
+
"signature": "(files: File[]) => Promise<void>",
|
|
522
|
+
"parameters": [{
|
|
523
|
+
"name": "files",
|
|
524
|
+
"type": "File[]",
|
|
525
|
+
"docs": ""
|
|
526
|
+
}],
|
|
527
|
+
"references": {
|
|
528
|
+
"Promise": {
|
|
529
|
+
"location": "global",
|
|
530
|
+
"id": "global::Promise"
|
|
531
|
+
},
|
|
532
|
+
"File": {
|
|
533
|
+
"location": "global",
|
|
534
|
+
"id": "global::File"
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
"return": "Promise<void>"
|
|
538
|
+
},
|
|
539
|
+
"docs": {
|
|
540
|
+
"text": "",
|
|
541
|
+
"tags": []
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
"focusComposer": {
|
|
545
|
+
"complexType": {
|
|
546
|
+
"signature": "() => Promise<void>",
|
|
547
|
+
"parameters": [],
|
|
548
|
+
"references": {
|
|
549
|
+
"Promise": {
|
|
550
|
+
"location": "global",
|
|
551
|
+
"id": "global::Promise"
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
"return": "Promise<void>"
|
|
555
|
+
},
|
|
556
|
+
"docs": {
|
|
557
|
+
"text": "",
|
|
558
|
+
"tags": []
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
static get watchers() {
|
|
564
|
+
return [{
|
|
565
|
+
"propName": "chatStore",
|
|
566
|
+
"methodName": "onChatStoreChange"
|
|
567
|
+
}, {
|
|
568
|
+
"propName": "roomId",
|
|
569
|
+
"methodName": "onRoomIdChanged"
|
|
570
|
+
}];
|
|
571
|
+
}
|
|
572
|
+
static get listeners() {
|
|
573
|
+
return [{
|
|
574
|
+
"name": "messageRetry",
|
|
575
|
+
"method": "messageRetryHandler",
|
|
576
|
+
"target": undefined,
|
|
577
|
+
"capture": false,
|
|
578
|
+
"passive": false
|
|
579
|
+
}, {
|
|
580
|
+
"name": "messageDiscard",
|
|
581
|
+
"method": "messageDiscardHandler",
|
|
582
|
+
"target": undefined,
|
|
583
|
+
"capture": false,
|
|
584
|
+
"passive": false
|
|
585
|
+
}, {
|
|
586
|
+
"name": "messageSend",
|
|
587
|
+
"method": "messageSendHandler",
|
|
588
|
+
"target": undefined,
|
|
589
|
+
"capture": false,
|
|
590
|
+
"passive": false
|
|
591
|
+
}];
|
|
592
|
+
}
|
|
593
|
+
}
|