Made live typing default.

This commit is contained in:
retoor 2025-05-28 11:38:16 +02:00
parent 35aaf8824f
commit e48b2258e0
7 changed files with 51 additions and 27 deletions

View File

@ -13,7 +13,7 @@ class ChatService(BaseService):
channel["last_message_on"] = now()
await self.services.channel.save(channel)
await self.services.socket.broadcast(
channel_uid,
channel['uid'],
{
"message": channel_message["message"],
"html": channel_message["html"],

View File

@ -160,11 +160,15 @@ export class App extends EventHandler {
typeLock = null;
typeListener = null;
typeEventChannelUid = null;
async set_typing(channel_uid) {
_debug = false
async set_typing(channel_uid) {
this.typeEventChannel_uid = channel_uid;
}
async ping(...args) {
debug() {
this._debug = !this._debug;
this.ws._debug = this._debug;
}
async ping(...args) {
if (this.is_pinging) return false;
this.is_pinging = true;
await this.rpc.ping(...args);
@ -202,8 +206,10 @@ export class App extends EventHandler {
this.ws.addEventListener("channel-message", (data) => {
me.emit("channel-message", data);
});
this.ws.addEventListener("event", (data) => {
console.info("aaaa");
this.ws.addEventListener("data", (data) => {
if(this._debug){
console.debug(data)
}
});
this.rpc.getUser(null).then((user) => {
me.user = user;

View File

@ -179,9 +179,6 @@ levenshteinDistance(a, b) {
if (e.key === "Enter" && !e.shiftKey) {
this.value = "";
e.target.value = "";
if(this.messageUid){
app.rpc.finalizeMessage(this.messageUid)
}
return;
}
this.value = e.target.value;
@ -220,7 +217,7 @@ levenshteinDistance(a, b) {
}
this.updateMessage()
app.rpc.finalizeMessage(this.messageUid)
this.value = "";
this.previousValue = "";
this.messageUid = null;

View File

@ -51,8 +51,6 @@ class MessageList extends HTMLElement {
return this.isElementVisible(this.querySelector(".message-list-bottom"));
}
scrollToBottom(force) {
console.info("Scrolling down")
// if (force) {
this.scrollTop = this.scrollHeight;
this.querySelector(".message-list-bottom").scrollIntoView();
@ -61,7 +59,6 @@ class MessageList extends HTMLElement {
this.scrollTop = this.scrollHeight;
this.querySelector(".message-list-bottom").scrollIntoView();
},200)
// }
}
updateMessageText(uid, message) {
const messageDiv = this.querySelector('div[data-uid="' + uid + '"]');
@ -69,12 +66,15 @@ class MessageList extends HTMLElement {
if (!messageDiv) {
return;
}
const scrollToBottom = this.isScrolledToBottom();
const receivedHtml = document.createElement("div");
receivedHtml.innerHTML = message.html;
const html = receivedHtml.querySelector(".text").innerHTML;
const textElement = messageDiv.querySelector(".text");
textElement.innerHTML = html;
textElement.style.display = message.text == "" ? "none" : "block";
if(scrollToBottom)
this.scrollToBottom(true)
}
triggerGlow(uid,color) {
app.starField.glowColor(color)

View File

@ -17,6 +17,8 @@ export class Socket extends EventHandler {
shouldReconnect = true;
_debug = false;
get isConnected() {
return this.ws && this.ws.readyState === WebSocket.OPEN;
}
@ -112,7 +114,12 @@ export class Socket extends EventHandler {
get(_, prop) {
return (...args) => {
const functionName = me._camelToSnake(prop);
return me.call(functionName, ...args);
if(me._debug){
const call = {}
call[functionName] = args
console.debug(call)
}
return me.call(functionName, ...args);
};
},
},

View File

@ -13,7 +13,7 @@
{% endfor %}
<div class="message-list-bottom"></div>
</message-list>
<chat-input live-type="false" channel="{{ channel.uid.value }}"></chat-input>
<chat-input live-type="true" channel="{{ channel.uid.value }}"></chat-input>
</section>
{% include "dialog_help.html" %}
{% include "dialog_online.html" %}
@ -167,24 +167,35 @@ app.ws.addEventListener("starfield.render_word", (data) => {
// --- Channel message event ---
app.addEventListener("channel-message", (data) => {
let display = data.text && data.text.trim() ? 'block' : 'none';
if (data.channel_uid !== channelUid) {
if (!isMentionForSomeoneElse(data.message)) {
channelSidebar.notify(data);
app.playSound("messageOtherChannel");
if(data.is_final){
if (data.channel_uid !== channelUid) {
if (!isMentionForSomeoneElse(data.message)) {
channelSidebar.notify(data);
app.playSound("messageOtherChannel");
}
return;
}
return;
}
if (data.username !== username) {
if (isMentionToMe(data.message)) {
app.playSound("mention");
} else if (!isMentionForSomeoneElse(data.message)) {
app.playSound("message");
if (data.username !== username) {
if (isMentionToMe(data.message)) {
app.playSound("mention");
} else if (!isMentionForSomeoneElse(data.message)) {
app.playSound("message");
}
}
}
const lastElement = messagesContainer.querySelector(".message-list-bottom");
const doScrollDown = messagesContainer.isScrolledToBottom();
const oldMessage = messagesContainer.querySelector(`.message[data-uid="${data.uid}"]`);
if (oldMessage) {
oldMessage.remove();
}
const message = document.createElement("div");
message.innerHTML = data.html;
message.style.display = display;
messagesContainer.insertBefore(message.firstChild, lastElement);

View File

@ -196,6 +196,9 @@ class RPCView(BaseView):
async def finalize_message(self, message_uid):
self._require_login()
message = await self.services.channel_message.get(message_uid)
if not message:
return False
if message["user_uid"] != self.user_uid:
raise Exception("Not allowed")
@ -203,7 +206,7 @@ class RPCView(BaseView):
if not message['is_final']:
await self.services.chat.finalize(message['uid'])
return {"success": True}
return True
async def update_message_text(self,message_uid, text):
self._require_login()