diff options
author | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
commit | c6dbf0450566c40efc4a26f4f0717452b6ef95cd (patch) | |
tree | b4be2d508223820d0a77d5a3e35e82684da3b6ec /server/hornchat.conversation.typing.js | |
download | hornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.tar.gz hornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.tar.bz2 hornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.zip |
Diffstat (limited to 'server/hornchat.conversation.typing.js')
-rw-r--r-- | server/hornchat.conversation.typing.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/server/hornchat.conversation.typing.js b/server/hornchat.conversation.typing.js new file mode 100644 index 0000000..d3c5755 --- /dev/null +++ b/server/hornchat.conversation.typing.js @@ -0,0 +1,34 @@ +const fs = require("fs"); + +module.exports = (socket, msg) => { + if (!msg.text) { + socket.send(JSON.stringify({error:"MISSING_OPERAND", fatal: false})); + console.log("[" + socket.id + "] Missing 'username' value"); + return; + } + + if (!data[socket.id]) { + socket.send(JSON.stringify({error:"NOT_STARTED", fatal: false})); + console.log("[" + socket.id + "] Conversation not started"); + return; + } + + let otherPeerSockets = Object.keys(data).filter((i) => { + let user = data[i]; + return !!(user && user.conversation === data[socket.id].conversation && user.peer === socket.authenticated.user); + }).map((i) => { + return data[i].socket; + }) + + for (let s of otherPeerSockets) { + s.send(JSON.stringify({ + type: "typing", + text: msg.text, + reply: msg.reply, + attachments: parseInt(msg.attachments), + position: msg.position + })) + } + + socket.send(JSON.stringify({success: true})); +}
\ No newline at end of file |