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);
|
||||
renameToSelf();
|
||||
return "";
|
||||
// case "chat":
|
||||
// renameToSelf();
|
||||
// return "";
|
||||
case "chat":
|
||||
groupMessage(modeSplit[1], input);
|
||||
renameToSelf();
|
||||
return "";
|
||||
}
|
||||
|
||||
// Default chat mode:
|
||||
@ -164,22 +165,33 @@ function cmd_nick(input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Initialize direct chat
|
||||
function cmd_msg(input) {
|
||||
// Check whether user is allowed to chat
|
||||
function canChatCheck(input) {
|
||||
if (input === undefined)
|
||||
return "No recipient was given!";
|
||||
if (!window.localStorage.getItem("connected"))
|
||||
return "You are not connected! Use the 'nick' command to connect using your username.";
|
||||
if (window.localStorage.getItem("name") === "")
|
||||
return "You do not have a name!";
|
||||
return "";
|
||||
}
|
||||
|
||||
// Initialize messaging
|
||||
function messagingIniti(mode, name) {
|
||||
// Get recipient username without spaces and pretext
|
||||
const username = input[0];
|
||||
pretext.current = `Chat (${username})> `;
|
||||
pretext.current = `Chat (${name})> `;
|
||||
// Set chat mode to direct messages and start pulling
|
||||
chatMode = `msg ${username}`;
|
||||
chatMode = `${mode} ${name}`;
|
||||
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)
|
||||
function cmd_exit(error) {
|
||||
const level = chatMode.split(' ')[0];
|
||||
@ -225,3 +237,11 @@ function cmd_logout() {
|
||||
return "You are not even connected yet!";
|
||||
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 => {});
|
||||
}
|
||||
|
||||
// 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
|
||||
function requestUsernames() {
|
||||
@ -231,3 +245,18 @@ function requestPing() {
|
||||
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