adapt chat routes to groups saved on user model

This commit is contained in:
Matteo Pagliazzi
2015-12-18 16:29:57 +01:00
parent ddf77e0e35
commit e53bd5079a
4 changed files with 17 additions and 11 deletions

View File

@@ -232,6 +232,7 @@ export default function cron (options = {}) {
progress.collect = _.transform(progress.collect, (m, v, k) => m[k] = 0); progress.collect = _.transform(progress.collect, (m, v, k) => m[k] = 0);
// Clean PMs - keep 200 for subscribers and 50 for free users // Clean PMs - keep 200 for subscribers and 50 for free users
// TODO tests
let maxPMs = user.isSubscribed() ? 200 : 50; // TODO 200 limit for contributors too let maxPMs = user.isSubscribed() ? 200 : 50; // TODO 200 limit for contributors too
let numberOfPMs = Object.keys(user.inbox.messages).length; let numberOfPMs = Object.keys(user.inbox.messages).length;
if (Object.keys(user.inbox.messages).length > maxPMs) { if (Object.keys(user.inbox.messages).length > maxPMs) {

View File

@@ -30,16 +30,21 @@ api.getChat = {
let validationErrors = req.validationErrors(); let validationErrors = req.validationErrors();
if (validationErrors) return next(validationErrors); if (validationErrors) return next(validationErrors);
let query = groupId === 'party' ? let query;
Group.findOne({type: 'party', members: {$in: [user._id]}}) :
Group.findOne({$or: [
{_id: groupId, privacy: 'public'},
{_id: groupId, privacy: 'private', members: {$in: [user._id]}},
]});
query.exec() if (groupId === 'party' || user.party._id === groupId) {
.then((group) => { query = {type: 'party', _id: user.party._id};
} else if (user.guilds.indexOf(groupId)) {
query = {type: 'guild', _id: groupId};
} else {
query = {type: 'guild', privacy: 'public', _id: groupId};
}
Group
.findOne(query, 'chat').exec()
.then(group => {
if (!group) throw new NotFound(res.t('groupNotFound')); if (!group) throw new NotFound(res.t('groupNotFound'));
res.respond(200, group.chat); res.respond(200, group.chat);
}) })
.catch(next); .catch(next);

View File

@@ -127,7 +127,7 @@ schema.post('remove', function postRemoveGroup (group) {
firebase.deleteGroup(group._id); firebase.deleteGroup(group._id);
}); });
schema.methods.toJSON = function groupToJSON () { /*schema.methods.toJSON = function groupToJSON () {
let doc = this.toObject(); let doc = this.toObject();
// removeDuplicates(doc); // removeDuplicates(doc);
doc._isMember = this._isMember; // TODO ? doc._isMember = this._isMember; // TODO ?
@@ -143,7 +143,7 @@ schema.methods.toJSON = function groupToJSON () {
this.challengeCount = _.size(this.challenges); this.challengeCount = _.size(this.challenges);
return doc; return doc;
}; };*/
// TODO move to its own model // TODO move to its own model
export function chatDefaults (msg, user) { export function chatDefaults (msg, user) {

View File

@@ -479,7 +479,7 @@ schema.plugin(baseModel, {
// TODO revisit a lot of things are missing // TODO revisit a lot of things are missing
noSet: ['_id', 'apiToken', 'auth.blocked', 'auth.timestamps', 'lastCron', 'auth.local.hashed_password', 'auth.local.salt', 'tasksOrder', 'tags', 'stats', 'challenges', 'guilds', 'party._id', 'party.quest', 'invitations'], noSet: ['_id', 'apiToken', 'auth.blocked', 'auth.timestamps', 'lastCron', 'auth.local.hashed_password', 'auth.local.salt', 'tasksOrder', 'tags', 'stats', 'challenges', 'guilds', 'party._id', 'party.quest', 'invitations'],
private: ['auth.local.hashed_password', 'auth.local.salt'], private: ['auth.local.hashed_password', 'auth.local.salt'],
toJSONTransform: function toJSON (doc) { toJSONTransform: function userToJSON (doc) {
// FIXME? Is this a reference to `doc.filters` or just disabled code? Remove? // FIXME? Is this a reference to `doc.filters` or just disabled code? Remove?
doc.filters = {}; doc.filters = {};
doc._tmp = this._tmp; // be sure to send down drop notifs doc._tmp = this._tmp; // be sure to send down drop notifs