Started work on flair
This commit is contained in:
parent
0fcd72b063
commit
4b4cb2ed3d
9 changed files with 149 additions and 10 deletions
|
|
@ -16,6 +16,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
|
||||
//Local Imports
|
||||
const channelModel = require('../../schemas/channelSchema');
|
||||
const flairModel = require('../../schemas/flairSchema');
|
||||
const userModel = require('../../schemas/userSchema');
|
||||
const activeChannel = require('./activeChannel');
|
||||
const chatHandler = require('./chatHandler');
|
||||
|
||||
|
|
@ -26,8 +28,17 @@ module.exports.handleConnection = async function(io, socket){
|
|||
//Prevent logged out connections and authenticate socket
|
||||
if(socket.request.session.user != null){
|
||||
try{
|
||||
//Find the user in the Database since the session won't store enough data to fulfill our needs :P
|
||||
const userDB = await userModel.findOne({user: socket.request.session.user.user});
|
||||
|
||||
//Set socket user and channel values
|
||||
socket.user = socket.request.session.user;
|
||||
socket.user = {
|
||||
id: userDB.id,
|
||||
user: userDB.user,
|
||||
rank: userDB.rank,
|
||||
flair: userDB.flair
|
||||
};
|
||||
|
||||
socket.chanName = socket.handshake.headers.referer.split('/c/')[1];
|
||||
|
||||
//Check if channel exists
|
||||
|
|
|
|||
|
|
@ -16,9 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
|
||||
//NPM Imports
|
||||
const validator = require('validator');//No express here, so regular validator it is!
|
||||
const loggerUtils = require('../../utils/loggerUtils');
|
||||
const userModel = require('../../schemas/userSchema');
|
||||
|
||||
module.exports.defineListeners = function(io, socket){
|
||||
socket.on("chat-message", (data) => {
|
||||
socket.on("chatMessage", (data) => {
|
||||
//Trim and Sanatize for XSS
|
||||
const msg = validator.trim(validator.escape(data.msg));
|
||||
//make sure high is an int
|
||||
|
|
@ -34,6 +36,22 @@ module.exports.defineListeners = function(io, socket){
|
|||
return;
|
||||
}
|
||||
|
||||
io.in(socket.chan).emit("chat-message", {user: socket.user.user, msg, high});
|
||||
io.in(socket.chan).emit("chatMessage", {user: socket.user.user, flair: socket.user.flair, high, msg});
|
||||
});
|
||||
|
||||
socket.on("setFlair", async (data) => {
|
||||
const userDB = await userModel.findOne({user: socket.user.user});
|
||||
|
||||
if(userDB){
|
||||
try{
|
||||
//We can take this data raw since our schema checks it against existing flairs, and mongoose sanatizes queries
|
||||
userDB.flair = data.flair;
|
||||
await userDB.save();
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue