Compare commits

..

No commits in common. "e48b2258e0f5c98a200d4a0da6605979f4b70172" and "76c69ca3ecf9092143f20d8a74507243df90cbad" have entirely different histories.

8 changed files with 28 additions and 52 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

@ -45,7 +45,7 @@ async def start_ssh_server(app,host,port):
logger.info("Starting SFTP server setup")
host_key_path = Path("drive") / ".ssh" / "sftp_server_key"
host_key_path.parent.mkdir(exist_ok=True, parents=True)
host_key_path.parent.mkdir(exist_ok=True)
try:
if not host_key_path.exists():
logger.info(f"Generating new host key at {host_key_path}")

View File

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

View File

@ -179,6 +179,9 @@ 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;
@ -217,7 +220,7 @@ levenshteinDistance(a, b) {
}
this.updateMessage()
app.rpc.finalizeMessage(this.messageUid)
this.value = "";
this.previousValue = "";
this.messageUid = null;

View File

@ -51,6 +51,8 @@ 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();
@ -59,6 +61,7 @@ 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 + '"]');
@ -66,15 +69,12 @@ 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,8 +17,6 @@ export class Socket extends EventHandler {
shouldReconnect = true;
_debug = false;
get isConnected() {
return this.ws && this.ws.readyState === WebSocket.OPEN;
}
@ -114,11 +112,6 @@ export class Socket extends EventHandler {
get(_, prop) {
return (...args) => {
const functionName = me._camelToSnake(prop);
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="true" channel="{{ channel.uid.value }}"></chat-input>
<chat-input live-type="false" channel="{{ channel.uid.value }}"></chat-input>
</section>
{% include "dialog_help.html" %}
{% include "dialog_online.html" %}
@ -167,9 +167,7 @@ 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.is_final){
if (data.channel_uid !== channelUid) {
if (!isMentionForSomeoneElse(data.message)) {
channelSidebar.notify(data);
@ -184,18 +182,9 @@ app.addEventListener("channel-message", (data) => {
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,9 +196,6 @@ 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")
@ -206,7 +203,7 @@ class RPCView(BaseView):
if not message['is_final']:
await self.services.chat.finalize(message['uid'])
return True
return {"success": True}
async def update_message_text(self,message_uid, text):
self._require_login()