-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove q #1564
base: dev
Are you sure you want to change the base?
Remove q #1564
Conversation
const { UNAUTHORIZED, BAD_REQUEST, SERVER_ERROR, OK } = | ||
require('../../util/constants').STATUS_CODES; | ||
const { MAX_AMOUNT_OF_CONNECTIONS } = | ||
require('../../util/constants').MESSAGES_API; | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const bodyParser = require('body-parser'); | ||
const User = require('../models/User.js'); | ||
const logger = require('../../util/logger'); | ||
const client = require('prom-client'); | ||
const { decodeToken, decodeTokenFromBodyOrQuery } = require('../util/token-functions.js'); | ||
const { | ||
decodeToken, | ||
decodeTokenFromBodyOrQuery, | ||
} = require('../util/token-functions.js'); | ||
const { MetricsHandler, register } = require('../../util/metrics.js'); | ||
|
||
|
||
router.use(bodyParser.json()); | ||
|
||
|
||
|
||
const clients = {}; | ||
const numberOfConnections = {}; | ||
const lastMessageSent = {}; | ||
|
||
const writeMessage = ((roomId, message, username) => { | ||
|
||
const writeMessage = (roomId, message, username) => { | ||
const messageObj = { | ||
timestamp: Date.now(), | ||
message, | ||
username | ||
username, | ||
}; | ||
|
||
if (clients[roomId]) { | ||
clients[roomId].forEach(res => res.write(`data: ${JSON.stringify(messageObj)}\n\n`)); | ||
clients[roomId].forEach((res) => | ||
res.write(`data: ${JSON.stringify(messageObj)}\n\n`) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a bunch of random changes in this file. lets disable prettier on vscode, and undo these changes
the only diff in this file should be the logic to remove the mongodb query
bdd4544
to
81d6b1d
Compare
Sorry about the Prettier formatting issues. Looking over the change log I can see it caused a ton of unnecessary changes that probably makes reviewing the PR pretty tough. I rolled back the commits, disabled Prettier, and pushed a new commit that should have the changes cleaner, and without the random formatting changes. |
}); | ||
} catch (error) { | ||
logger.error('Error in /send: ', error); | ||
res.sendStatus(SERVER_ERROR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res.sendStatus(SERVER_ERROR); | |
return res.sendStatus(SERVER_ERROR); |
} | ||
filterQuery._id = userObj._id; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove the entire else
indentation, if we use return
statements inside if (apiKey) {
let me know if this makes sense. it makes the code easier to follow
if (thing) {
// stuff
return idk;
}
// no more else block
// just the original code that wouldve been in the else ere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, removed the else block. I had to change the code to make the User.findOne() function call async since the code ended up sending multiple responses (I think it was running the code after the if (apiKey) block as it waited for the User.findOne() function?). Please let me know if that's okay or there was an alternative I should have done. Thanks!
Followed the instructions in setting up the Messaging Component and the Form to send the username in the request. The request is then passed through and used in the endpoint to avoid querying the DB if user is not using an APIKey. Apologies if my Prettier messed up the formatting.
concering issue #1555