Finished up work on advanced formatted private messaging.
This commit is contained in:
parent
faf72fd7a5
commit
2feea72694
11 changed files with 164 additions and 94 deletions
|
|
@ -14,49 +14,25 @@ GNU Affero General Public License for more details.
|
|||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//local imports
|
||||
const chatMetadata = require("../chatMetadata");
|
||||
|
||||
/**
|
||||
* Class representing a single chat message
|
||||
*/
|
||||
class chat{
|
||||
class chat extends chatMetadata{
|
||||
/**
|
||||
* Instantiates a chat message object
|
||||
* @param {connectedUser} user - User who sent the message
|
||||
* @param {String} flair - Flair ID String for the flair used to send the message
|
||||
* @param {Number} highLevel - Number representing current high level
|
||||
* @param {String} msg - Contents of the message, with links replaced with numbered file-seperator markers
|
||||
* @param {String} type - Message Type Identifier, used for client-side processing.
|
||||
* @param {Array} links - Array of URLs/Links included in the message.
|
||||
*/
|
||||
constructor(user, flair, highLevel, msg, type, links){
|
||||
//Call derived constructor
|
||||
super(flair, highLevel, msg, type, links);
|
||||
|
||||
/**
|
||||
* User who sent the message
|
||||
*/
|
||||
this.user = user;
|
||||
|
||||
/**
|
||||
* Flair ID String for the flair used to send the message
|
||||
*/
|
||||
this.flair = flair;
|
||||
|
||||
/**
|
||||
* Number representing current high level
|
||||
*/
|
||||
this.highLevel = highLevel;
|
||||
|
||||
/**
|
||||
* COntents of the message, with links replaced with numbered file-seperator marks
|
||||
*/
|
||||
this.msg = msg;
|
||||
|
||||
/**
|
||||
* Message Type Identifier, used for client-side processing.
|
||||
*/
|
||||
this.type = type;
|
||||
|
||||
/**
|
||||
* Array of URLs/Links included in the message.
|
||||
*/
|
||||
this.links = links;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
57
src/app/chatMetadata.js
Normal file
57
src/app/chatMetadata.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*Canopy - The next generation of stoner streaming software
|
||||
Copyright (C) 2024-2025 Rainbownapkin and the TTN Community
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
/**
|
||||
* Class representing a the metadata of a single message
|
||||
*/
|
||||
class chatMetadata{
|
||||
/**
|
||||
* Instantiates a chat metadata object
|
||||
* @param {String} flair - Flair ID String for the flair used to send the message
|
||||
* @param {Number} highLevel - Number representing current high level
|
||||
* @param {String} msg - Contents of the message, with links replaced with numbered file-seperator markers
|
||||
* @param {String} type - Message Type Identifier, used for client-side processing.
|
||||
* @param {Array} links - Array of URLs/Links included in the message.
|
||||
*/
|
||||
constructor(flair, highLevel, msg, type, links){
|
||||
/**
|
||||
* Flair ID String for the flair used to send the message
|
||||
*/
|
||||
this.flair = flair;
|
||||
|
||||
/**
|
||||
* Number representing current high level
|
||||
*/
|
||||
this.highLevel = highLevel;
|
||||
|
||||
/**
|
||||
* COntents of the message, with links replaced with numbered file-seperator marks
|
||||
*/
|
||||
this.msg = msg;
|
||||
|
||||
/**
|
||||
* Message Type Identifier, used for client-side processing.
|
||||
*/
|
||||
this.type = type;
|
||||
|
||||
/**
|
||||
* Array of URLs/Links included in the message.
|
||||
*/
|
||||
this.links = links;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = chatMetadata;
|
||||
|
|
@ -14,44 +14,30 @@ GNU Affero General Public License for more details.
|
|||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//localImports
|
||||
const chatMetadata = require("../chatMetadata");
|
||||
|
||||
/**
|
||||
* Class representing a single chat message
|
||||
*/
|
||||
class message{
|
||||
class message extends chatMetadata{
|
||||
/**
|
||||
* Instantiates a chat message object
|
||||
* @param {String} sender - Name of user who sent the message
|
||||
* @param {String} user - Name of user who sent the message
|
||||
* @param {Array} recipients - Array of usernames who are supposed to receive the message
|
||||
* @param {String} msg - Contents of the message, with links replaced with numbered file-seperator markers
|
||||
* @param {String} type - Message Type Identifier, used for client-side processing.
|
||||
* @param {Array} links - Array of URLs/Links included in the message.
|
||||
*/
|
||||
constructor(sender, recipients, msg, type, links){
|
||||
constructor(user, recipients, flair, highLevel, msg, type, links){
|
||||
//Call derived constructor
|
||||
super(flair, highLevel, msg, type, links);
|
||||
|
||||
/**
|
||||
* Name of user who sent the message
|
||||
*/
|
||||
this.sender = sender;
|
||||
this.user = user;
|
||||
|
||||
/**
|
||||
* Array of usernames who are supposed to receive the message
|
||||
*/
|
||||
this.recipients = recipients;
|
||||
|
||||
/**
|
||||
* Contenst of the messages, with links replaced with numbered file-seperator markers
|
||||
*/
|
||||
this.msg = msg;
|
||||
|
||||
/**
|
||||
* Message Type Identifier, used for client-side processing.
|
||||
*/
|
||||
this.type = type;
|
||||
|
||||
/**
|
||||
* Array of URLs/Links included in the message.
|
||||
*/
|
||||
this.links = links;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,13 +30,19 @@ class pmHandler{
|
|||
/**
|
||||
* Instantiates object containing global server-side private message relay logic
|
||||
* @param {Socket.io} io - Socket.io server instanced passed down from server.js
|
||||
* @param {channelManager} chanServer - Sister channel management server object
|
||||
*/
|
||||
constructor(io){
|
||||
constructor(io, chanServer){
|
||||
/**
|
||||
* Socket.io server instance passed down from server.js
|
||||
*/
|
||||
this.io = io;
|
||||
|
||||
/**
|
||||
* Sister channel management server object
|
||||
*/
|
||||
this.chanServer = chanServer;
|
||||
|
||||
/**
|
||||
* Socket.io server namespace for handling messaging
|
||||
*/
|
||||
|
|
@ -107,14 +113,28 @@ class pmHandler{
|
|||
//preprocess message
|
||||
const preprocessedMessage = await this.chatPreprocessor.preprocess(socket, data);
|
||||
|
||||
//Create message object and relay it off to the recipients
|
||||
this.relayPMObj(new message(
|
||||
socket.user.user,
|
||||
recipients,
|
||||
preprocessedMessage.message,
|
||||
preprocessedMessage.chatType,
|
||||
preprocessedMessage.links
|
||||
));
|
||||
//If the send flag wasnt thrown false
|
||||
if(preprocessedMessage != false){
|
||||
//Pull an active user profile from the first channel that gives it in the chan server
|
||||
const senderProfile = this.chanServer.activeUsers.get(socket.user.user);
|
||||
|
||||
//If user isn't actively connected to a channel
|
||||
if(senderProfile == null || senderProfile.length == 0){
|
||||
//They don't get to send shit lol
|
||||
return;
|
||||
}
|
||||
|
||||
//Create message object and relay it off to the recipients
|
||||
this.relayPMObj(new message(
|
||||
socket.user.user,
|
||||
recipients,
|
||||
senderProfile[0].flair,
|
||||
senderProfile[0].highLevel,
|
||||
preprocessedMessage.message,
|
||||
preprocessedMessage.chatType,
|
||||
preprocessedMessage.links
|
||||
));
|
||||
}
|
||||
|
||||
//If something fucked up
|
||||
}catch(err){
|
||||
|
|
@ -131,7 +151,7 @@ class pmHandler{
|
|||
}
|
||||
|
||||
//Acknowledge the sent message
|
||||
this.namespace.to(msg.sender).emit("sent", msg);
|
||||
this.namespace.to(msg.user).emit("sent", msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ scheduler.kickoff();
|
|||
|
||||
//Hand over general-namespace socket.io connections to the channel manager
|
||||
module.exports.channelManager = new channelManager(io)
|
||||
module.exports.pmHandler = new pmHandler(io)
|
||||
module.exports.pmHandler = new pmHandler(io, module.exports.channelManager);
|
||||
|
||||
//Listen Function
|
||||
webServer.listen(port, () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue