Compare commits
No commits in common. "35786703d56e2e7ebb6261a658aaed22daf5e4c7" and "10eec5fd6d909582d5b127255009fac36c01e2be" have entirely different histories.
35786703d5
...
10eec5fd6d
@ -17,8 +17,6 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
_value = ""
|
_value = ""
|
||||||
lastUpdateEvent = null
|
lastUpdateEvent = null
|
||||||
expiryTimer = null;
|
expiryTimer = null;
|
||||||
queuedMessage = null;
|
|
||||||
lastMessagePromise = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -40,11 +38,11 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
return Object.assign({}, this.autoCompletions, this.hiddenCompletions)
|
return Object.assign({}, this.autoCompletions, this.hiddenCompletions)
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveAutoComplete(input) {
|
resolveAutoComplete() {
|
||||||
let value = null;
|
let value = null;
|
||||||
|
|
||||||
for (const key of Object.keys(this.allAutoCompletions)) {
|
for (const key of Object.keys(this.allAutoCompletions)) {
|
||||||
if (key.startsWith(input.split(" ", 1)[0])) {
|
if (key.startsWith(this.value.split(" ", 1)[0])) {
|
||||||
if (value) {
|
if (value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -195,7 +193,7 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.finalizeMessage(this.messageUid)
|
this.finalizeMessage()
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -205,25 +203,19 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
|
|
||||||
this.textarea.addEventListener("keydown", (e) => {
|
this.textarea.addEventListener("keydown", (e) => {
|
||||||
this.value = e.target.value;
|
this.value = e.target.value;
|
||||||
|
|
||||||
let autoCompletion = null;
|
let autoCompletion = null;
|
||||||
if (e.key === "Tab") {
|
if (e.key === "Tab") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
autoCompletion = this.resolveAutoComplete(this.value);
|
autoCompletion = this.resolveAutoComplete();
|
||||||
if (autoCompletion) {
|
if (autoCompletion) {
|
||||||
e.target.value = autoCompletion;
|
e.target.value = autoCompletion;
|
||||||
this.value = autoCompletion;
|
this.value = autoCompletion;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key === "Enter" && !e.shiftKey) {
|
if (e.key === "Enter" && !e.shiftKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.repeat) {
|
|
||||||
this.updateFromInput(e.target.value);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addEventListener("upload", (e) => {
|
this.addEventListener("upload", (e) => {
|
||||||
@ -264,28 +256,17 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finalizeMessage(messageUid) {
|
finalizeMessage() {
|
||||||
if (!messageUid) {
|
if (!this.messageUid) {
|
||||||
if (this.value.trim() === "") {
|
if (this.value.trim() === "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.sendMessage(this.channelUid, this.replaceMentionsWithAuthors(this.value), !this.liveType);
|
this.sendMessage(this.channelUid, this.replaceMentionsWithAuthors(this.value), !this.liveType);
|
||||||
} else if (messageUid.startsWith("?")) {
|
|
||||||
const lastQueuedMessage = this.queuedMessage;
|
|
||||||
|
|
||||||
this.lastMessagePromise?.then((uid) => {
|
|
||||||
const updatePromise = lastQueuedMessage ? app.rpc.updateMessageText(uid, lastQueuedMessage) : Promise.resolve();
|
|
||||||
return updatePromise.finally(() => {
|
|
||||||
return app.rpc.finalizeMessage(uid);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
app.rpc.finalizeMessage(messageUid)
|
app.rpc.finalizeMessage(this.messageUid)
|
||||||
}
|
}
|
||||||
this.value = "";
|
this.value = "";
|
||||||
this.messageUid = null;
|
this.messageUid = null;
|
||||||
this.queuedMessage = null;
|
|
||||||
this.lastMessagePromise = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFromInput(value) {
|
updateFromInput(value) {
|
||||||
@ -300,33 +281,18 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
|
|
||||||
if (this.liveType && value[0] !== "/") {
|
if (this.liveType && value[0] !== "/") {
|
||||||
this.expiryTimer = setTimeout(() => {
|
this.expiryTimer = setTimeout(() => {
|
||||||
this.finalizeMessage(this.messageUid)
|
this.finalizeMessage()
|
||||||
}, this.liveTypeInterval * 1000);
|
}, this.liveTypeInterval * 1000);
|
||||||
|
|
||||||
|
if (this.messageUid === "?") {
|
||||||
const messageText = this.replaceMentionsWithAuthors(value);
|
|
||||||
if (this.messageUid?.startsWith("?")) {
|
|
||||||
this.queuedMessage = messageText;
|
|
||||||
} else if (this.messageUid) {
|
} else if (this.messageUid) {
|
||||||
app.rpc.updateMessageText(this.messageUid, messageText).then((d) => {
|
app.rpc.updateMessageText(this.messageUid, this.replaceMentionsWithAuthors(this.value));
|
||||||
if (!d.success) {
|
|
||||||
this.messageUid = null
|
|
||||||
this.updateFromInput(value)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const placeHolderId = "?" + crypto.randomUUID();
|
this.messageUid = "?"; // Indicate that a message is being sent
|
||||||
this.messageUid = placeHolderId;
|
this.sendMessage(this.channelUid, this.replaceMentionsWithAuthors(value), !this.liveType).then((uid) => {
|
||||||
|
if (this.liveType) {
|
||||||
this.lastMessagePromise = this.sendMessage(this.channelUid, messageText, !this.liveType).then(async (uid) => {
|
|
||||||
if (this.liveType && this.messageUid === placeHolderId) {
|
|
||||||
if (this.queuedMessage && this.queuedMessage !== messageText) {
|
|
||||||
await app.rpc.updateMessageText(uid, this.queuedMessage)
|
|
||||||
}
|
|
||||||
this.messageUid = uid;
|
this.messageUid = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return uid
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user