@meetelise/chat 1.20.98 → 1.20.100
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/public/dist/index.js +29 -18
- package/src/MyPubnub.ts +22 -11
- package/src/WebComponent/pubnub-chat-styles.ts +11 -2
- package/src/WebComponent/pubnub-chat.ts +15 -4
package/src/MyPubnub.ts
CHANGED
|
@@ -23,11 +23,17 @@ interface TokenResponse {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
enum MessageType {
|
|
27
|
+
noReply = "no-reply",
|
|
28
|
+
text = "text",
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
export interface ChatMessage {
|
|
27
32
|
channel: string;
|
|
28
33
|
message: {
|
|
29
34
|
text: string;
|
|
30
35
|
customType: string;
|
|
36
|
+
messageType?: MessageType;
|
|
31
37
|
};
|
|
32
38
|
publisher: string;
|
|
33
39
|
subscription: string;
|
|
@@ -61,16 +67,19 @@ class MyPubnub {
|
|
|
61
67
|
messages: ChatMessage[] = [];
|
|
62
68
|
listenerParams: ListenerParameters = {
|
|
63
69
|
message: (messageEvent: MessageEvent) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
// if the messageEvent is a no-reply, we ignore it and stop loading
|
|
71
|
+
if (messageEvent.message.messageType !== MessageType.noReply) {
|
|
72
|
+
this.messages = [
|
|
73
|
+
...this.messages,
|
|
74
|
+
{
|
|
75
|
+
channel: messageEvent.channel,
|
|
76
|
+
message: messageEvent.message,
|
|
77
|
+
publisher: messageEvent.publisher,
|
|
78
|
+
subscription: messageEvent.subscription,
|
|
79
|
+
timetoken: +messageEvent.timetoken,
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
}
|
|
74
83
|
const isWaitingForEliseResponse = messageEvent.publisher !== "eliseai";
|
|
75
84
|
this.chatListener?.({
|
|
76
85
|
messages: this.messages,
|
|
@@ -271,7 +280,9 @@ class MyPubnub {
|
|
|
271
280
|
});
|
|
272
281
|
}
|
|
273
282
|
});
|
|
274
|
-
this.messages = parsedCurrentChannelMessages
|
|
283
|
+
this.messages = parsedCurrentChannelMessages.filter(
|
|
284
|
+
(m) => m.message.messageType !== MessageType.noReply
|
|
285
|
+
);
|
|
275
286
|
this.chatListener?.({ messages: this.messages, isLoading: false });
|
|
276
287
|
}
|
|
277
288
|
} catch (error) {
|
|
@@ -168,7 +168,8 @@ export const pubnubChatStyles = css`
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
#footer {
|
|
171
|
-
height: 70px;
|
|
171
|
+
min-height: 70px;
|
|
172
|
+
max-height: 200px;
|
|
172
173
|
width: 100%;
|
|
173
174
|
background: black;
|
|
174
175
|
|
|
@@ -181,8 +182,13 @@ export const pubnubChatStyles = css`
|
|
|
181
182
|
z-index: 100001;
|
|
182
183
|
}
|
|
183
184
|
#message-input {
|
|
184
|
-
height: 40px;
|
|
185
185
|
width: 100%;
|
|
186
|
+
height: auto;
|
|
187
|
+
max-height: 100%;
|
|
188
|
+
|
|
189
|
+
resize: none;
|
|
190
|
+
|
|
191
|
+
font-family: inherit;
|
|
186
192
|
box-sizing: border-box;
|
|
187
193
|
font-weight: 300;
|
|
188
194
|
font-size: 14px;
|
|
@@ -190,6 +196,9 @@ export const pubnubChatStyles = css`
|
|
|
190
196
|
border: none;
|
|
191
197
|
color: white;
|
|
192
198
|
background: none;
|
|
199
|
+
|
|
200
|
+
padding-right: 6px; /* width of the scrollbar */
|
|
201
|
+
box-sizing: border-box;
|
|
193
202
|
z-index: 1000000000000000000000000001;
|
|
194
203
|
}
|
|
195
204
|
#message-input:focus {
|
|
@@ -36,7 +36,7 @@ export class PubnubChat extends LitElement {
|
|
|
36
36
|
onMount: () => void = () => ({});
|
|
37
37
|
|
|
38
38
|
@query("#message-input", true)
|
|
39
|
-
messageInput!:
|
|
39
|
+
messageInput!: HTMLTextAreaElement;
|
|
40
40
|
|
|
41
41
|
@query("#conversation-body", true)
|
|
42
42
|
messageBody!: HTMLDivElement;
|
|
@@ -63,6 +63,7 @@ export class PubnubChat extends LitElement {
|
|
|
63
63
|
|
|
64
64
|
sendMessage = async (message: string): Promise<void> => {
|
|
65
65
|
this.messageInput.value = "";
|
|
66
|
+
this.autoResizeMessageInput();
|
|
66
67
|
await this.myPubnub?.sendMessage(message);
|
|
67
68
|
};
|
|
68
69
|
firstUpdated(): void {
|
|
@@ -87,6 +88,11 @@ export class PubnubChat extends LitElement {
|
|
|
87
88
|
this.scrollToChatBottom();
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
autoResizeMessageInput = (): void => {
|
|
92
|
+
this.messageInput.style.height = "auto";
|
|
93
|
+
this.messageInput.style.height = this.messageInput.scrollHeight + "px";
|
|
94
|
+
};
|
|
95
|
+
|
|
90
96
|
render(): TemplateResult {
|
|
91
97
|
if (!this.buildingSlug || !this.building) {
|
|
92
98
|
return html``; // error here
|
|
@@ -167,13 +173,18 @@ export class PubnubChat extends LitElement {
|
|
|
167
173
|
</ul>
|
|
168
174
|
</div>
|
|
169
175
|
<div id="footer">
|
|
170
|
-
<
|
|
176
|
+
<textarea
|
|
171
177
|
id="message-input"
|
|
172
178
|
placeholder="Ask a question..."
|
|
173
179
|
@keydown=${(e: KeyboardEvent) => {
|
|
174
|
-
if (e.key === "Enter")
|
|
180
|
+
if (e.key === "Enter") {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
this.sendMessage(this.messageInput.value);
|
|
183
|
+
}
|
|
175
184
|
}}
|
|
176
|
-
|
|
185
|
+
@input=${() => this.autoResizeMessageInput()}
|
|
186
|
+
rows="1"
|
|
187
|
+
></textarea>
|
|
177
188
|
<button
|
|
178
189
|
id="send-message-bttn"
|
|
179
190
|
@click=${() => this.sendMessage(this.messageInput.value)}
|