Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b5cc49e6e |
@@ -19,6 +19,7 @@ on 'error' -> Server emits and logs an error
|
|||||||
on 'open chat' -> Preps the server for your messages, places you in the room 'general'
|
on 'open chat' -> Preps the server for your messages, places you in the room 'general'
|
||||||
on 'message' -> Server broadcasts to all other users in your room
|
on 'message' -> Server broadcasts to all other users in your room
|
||||||
on 'disconnect' -> Server will no longer accept your messages
|
on 'disconnect' -> Server will no longer accept your messages
|
||||||
|
on 'report' -> Report the chatlog with the index 'id'
|
||||||
|
|
||||||
|
|
||||||
Chat Commands:
|
Chat Commands:
|
||||||
|
|||||||
+15
-2
@@ -1,13 +1,13 @@
|
|||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
const { Op } = require('sequelize');
|
const { Op } = require('sequelize');
|
||||||
const { chatlog, mute } = require('../database/models');
|
const { chatlog, mute, reports } = require('../database/models');
|
||||||
|
|
||||||
const chat = io => {
|
const chat = io => {
|
||||||
io.on('connection', socket => {
|
io.on('connection', socket => {
|
||||||
//middleware
|
//middleware
|
||||||
socket.use((request, next) => {
|
socket.use((request, next) => {
|
||||||
//verify request format
|
//verify request format
|
||||||
if (!['open chat', 'message'].includes(request[0])) {
|
if (!['open chat', 'message', 'report'].includes(request[0])) {
|
||||||
return next(`Invalid request to the chat server ${request[0]}`);
|
return next(`Invalid request to the chat server ${request[0]}`);
|
||||||
}
|
}
|
||||||
return next();
|
return next();
|
||||||
@@ -137,6 +137,19 @@ const chat = io => {
|
|||||||
emphasis: true
|
emphasis: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('report', info => {
|
||||||
|
//handle reports of malicious content
|
||||||
|
if (!info.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//report
|
||||||
|
reports.create({
|
||||||
|
reporter: socket.user.username,
|
||||||
|
chatlogId: info.id
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
chatlog: require('./chatlog'),
|
chatlog: require('./chatlog'),
|
||||||
mute: require('./mute')
|
mute: require('./mute'),
|
||||||
|
reports: require('./reports')
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
const Sequelize = require('sequelize');
|
||||||
|
const sequelize = require('..');
|
||||||
|
|
||||||
|
const chatlog = require('./chatlog');
|
||||||
|
|
||||||
|
const reports = sequelize.define('reports', {
|
||||||
|
id: {
|
||||||
|
type: Sequelize.INTEGER(11),
|
||||||
|
allowNull: false,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
unique: true
|
||||||
|
},
|
||||||
|
|
||||||
|
reporter: {
|
||||||
|
type: 'varchar(320)',
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
chatlog.hasMany(reports, { foreignKey: 'chatlogId', foreignKeyConstraint: true });
|
||||||
|
|
||||||
|
module.exports = reports;
|
||||||
Reference in New Issue
Block a user