mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
@@ -64,8 +64,6 @@ function textContainsBannedSlur (message) {
|
||||
*
|
||||
* @apiParam (Path) {String} groupId The group _id ('party' for the user party and
|
||||
* 'habitrpg' for tavern are accepted).
|
||||
* @apiParam (Query) {Number} [limit=50] The number of messages to fetch (max 400).
|
||||
* @apiParam (Query) {String} [before] Fetch messages older than this message ID.
|
||||
*
|
||||
* @apiSuccess {Array} data An array of <a href='https://github.com/HabitRPG/habitica/blob/develop/website/server/models/group.js#L51' target='_blank'>chat messages</a>
|
||||
*
|
||||
@@ -80,21 +78,18 @@ api.getChat = {
|
||||
const { user } = res.locals;
|
||||
|
||||
req.checkParams('groupId', apiError('groupIdRequired')).notEmpty();
|
||||
req.checkQuery('before').optional().isUUID();
|
||||
|
||||
const validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
const { groupId } = req.params;
|
||||
const limit = req.query.limit ? Math.min(parseInt(req.query.limit, 10), 400) : 50;
|
||||
const { before } = req.query;
|
||||
const group = await Group.getGroup({ user, groupId, fields: 'chat privacy' });
|
||||
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||
if (group.privacy === 'public') {
|
||||
throw new BadRequest(res.t('featureRetired'));
|
||||
}
|
||||
|
||||
const groupChat = await Group.toJSONCleanChat(group, user, { limit, before });
|
||||
const groupChat = await Group.toJSONCleanChat(group, user);
|
||||
res.respond(200, groupChat.chat);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@ import mongoose from 'mongoose';
|
||||
import get from 'lodash/get';
|
||||
import sinon from 'sinon';
|
||||
import moment from 'moment';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { authWithHeaders } from '../../middlewares/auth';
|
||||
import ensureDevelopmentMode from '../../middlewares/ensureDevelopmentMode';
|
||||
import ensureTimeTravelMode from '../../middlewares/ensureTimeTravelMode';
|
||||
@@ -12,7 +11,6 @@ import {
|
||||
model as Group,
|
||||
// basicFields as basicGroupFields,
|
||||
} from '../../models/group';
|
||||
import { chatModel as Chat, inboxModel as Inbox } from '../../models/message';
|
||||
import connectToMongoDB from '../../libs/mongoose';
|
||||
|
||||
const { content } = common;
|
||||
@@ -313,93 +311,4 @@ api.timeTravelAdjust = {
|
||||
},
|
||||
};
|
||||
|
||||
api.seedPartyChat = {
|
||||
method: 'POST',
|
||||
url: '/debug/seed-party-chat',
|
||||
middlewares: [ensureDevelopmentMode, authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const messageCount = Number(req.body.messageCount);
|
||||
|
||||
if (!Number.isInteger(messageCount) || messageCount < 1) {
|
||||
throw new BadRequest('messageCount must be a positive integer.');
|
||||
}
|
||||
|
||||
if (!user.party._id) {
|
||||
throw new BadRequest('You are not in a party.');
|
||||
}
|
||||
|
||||
const party = await Group.findOne({ _id: user.party._id, type: 'party' }).exec();
|
||||
if (!party) {
|
||||
throw new BadRequest('Party not found.');
|
||||
}
|
||||
|
||||
const messages = [];
|
||||
const baseTimestamp = Date.now();
|
||||
|
||||
for (let i = 1; i <= messageCount; i += 1) {
|
||||
const id = uuid();
|
||||
messages.push({
|
||||
_id: id,
|
||||
id,
|
||||
groupId: party._id,
|
||||
text: `#${i}`,
|
||||
unformattedText: `#${i}`,
|
||||
timestamp: new Date(baseTimestamp - (messageCount - i) * 1000),
|
||||
likes: {},
|
||||
flags: {},
|
||||
flagCount: 0,
|
||||
uuid: 'system',
|
||||
user: 'System',
|
||||
client: 'debug-seed',
|
||||
});
|
||||
}
|
||||
|
||||
await Chat.insertMany(messages);
|
||||
|
||||
res.respond(200, { messageCount });
|
||||
},
|
||||
};
|
||||
|
||||
// Messaging ourselves for testing
|
||||
api.seedInbox = {
|
||||
method: 'POST',
|
||||
url: '/debug/seed-inbox',
|
||||
middlewares: [ensureDevelopmentMode, authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const messageCount = Number(req.body.messageCount);
|
||||
|
||||
if (!Number.isInteger(messageCount) || messageCount < 1) {
|
||||
throw new BadRequest('messageCount must be a positive integer.');
|
||||
}
|
||||
|
||||
const messages = [];
|
||||
const baseTimestamp = Date.now();
|
||||
|
||||
for (let i = 1; i <= messageCount; i += 1) {
|
||||
const id = uuid();
|
||||
messages.push({
|
||||
_id: id,
|
||||
id,
|
||||
ownerId: user._id,
|
||||
uuid: user._id,
|
||||
user: user.profile.name,
|
||||
text: `#${i}`,
|
||||
unformattedText: `#${i}`,
|
||||
timestamp: new Date(baseTimestamp - (messageCount - i) * 1000),
|
||||
likes: {},
|
||||
flags: {},
|
||||
flagCount: 0,
|
||||
sent: true,
|
||||
client: 'debug-seed',
|
||||
});
|
||||
}
|
||||
|
||||
await Inbox.insertMany(messages);
|
||||
|
||||
res.respond(200, { messageCount });
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
||||
|
||||
Reference in New Issue
Block a user