initial group chat functionality
This commit is contained in:
parent
d2be753513
commit
e0b0df1fcc
@ -23,9 +23,10 @@ function runCommand(input) {
|
|||||||
directMessage(modeSplit[1].split(','), input);
|
directMessage(modeSplit[1].split(','), input);
|
||||||
renameToSelf();
|
renameToSelf();
|
||||||
return "";
|
return "";
|
||||||
// case "chat":
|
case "chat":
|
||||||
// renameToSelf();
|
groupMessage(modeSplit[1], input);
|
||||||
// return "";
|
renameToSelf();
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default chat mode:
|
// Default chat mode:
|
||||||
@ -164,22 +165,33 @@ function cmd_nick(input) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize direct chat
|
// Check whether user is allowed to chat
|
||||||
function cmd_msg(input) {
|
function canChatCheck(input) {
|
||||||
if (input === undefined)
|
if (input === undefined)
|
||||||
return "No recipient was given!";
|
return "No recipient was given!";
|
||||||
if (!window.localStorage.getItem("connected"))
|
if (!window.localStorage.getItem("connected"))
|
||||||
return "You are not connected! Use the 'nick' command to connect using your username.";
|
return "You are not connected! Use the 'nick' command to connect using your username.";
|
||||||
if (window.localStorage.getItem("name") === "")
|
if (window.localStorage.getItem("name") === "")
|
||||||
return "You do not have a name!";
|
return "You do not have a name!";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize messaging
|
||||||
|
function messagingIniti(mode, name) {
|
||||||
// Get recipient username without spaces and pretext
|
// Get recipient username without spaces and pretext
|
||||||
const username = input[0];
|
pretext.current = `Chat (${name})> `;
|
||||||
pretext.current = `Chat (${username})> `;
|
|
||||||
// Set chat mode to direct messages and start pulling
|
// Set chat mode to direct messages and start pulling
|
||||||
chatMode = `msg ${username}`;
|
chatMode = `${mode} ${name}`;
|
||||||
userData.chatPull = setInterval(getChatMessages, 500);
|
userData.chatPull = setInterval(getChatMessages, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize direct chat
|
||||||
|
function cmd_msg(input) {
|
||||||
|
let output = canChatCheck(input);
|
||||||
|
if (output !== "") return output;
|
||||||
|
messagingIniti('msg', input[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// Exit current level (example: chat -> main)
|
// Exit current level (example: chat -> main)
|
||||||
function cmd_exit(error) {
|
function cmd_exit(error) {
|
||||||
const level = chatMode.split(' ')[0];
|
const level = chatMode.split(' ')[0];
|
||||||
@ -225,3 +237,11 @@ function cmd_logout() {
|
|||||||
return "You are not even connected yet!";
|
return "You are not even connected yet!";
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize group chat
|
||||||
|
function cmd_chat(input) {
|
||||||
|
let output = canChatCheck(input);
|
||||||
|
if (output !== "") return output;
|
||||||
|
messagingIniti('chat', input[0]);
|
||||||
|
sendChatInit(input[0]);
|
||||||
|
}
|
@ -193,7 +193,21 @@ function directMessage(names, message) {
|
|||||||
}).then(res => {});
|
}).then(res => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// function globalMessage(message) {}
|
// Send a group message
|
||||||
|
function groupMessage(chat, message) {
|
||||||
|
fetch('/sendGroup', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: window.localStorage.getItem("name"),
|
||||||
|
id: window.localStorage.getItem("id"),
|
||||||
|
message,
|
||||||
|
chat
|
||||||
|
})
|
||||||
|
}).then(res => {});
|
||||||
|
}
|
||||||
|
|
||||||
// Request all usernames and number of anonymous users
|
// Request all usernames and number of anonymous users
|
||||||
function requestUsernames() {
|
function requestUsernames() {
|
||||||
@ -231,3 +245,18 @@ function requestPing() {
|
|||||||
outputText({output})
|
outputText({output})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize group chat
|
||||||
|
function sendChatInit(chat) {
|
||||||
|
fetch('/chatInit', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: window.localStorage.getItem("name"),
|
||||||
|
id: window.localStorage.getItem("id"),
|
||||||
|
chat
|
||||||
|
})
|
||||||
|
}).then(res => {});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user