mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
* Re-organize common folder * fix: Correct paths in tests * fix: move new content to proper folder * chore: Move audio folder to assets * Move sprites to sprites assets directory * Move css sprites to assets directory * Split out readmes for common code and sprites * Move images to assets directory * Move destinatin of shared browserified file * remove unused file * move compiled js to client-old * Fix karma tests * fix: Correct paths for sprites
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
import common from '../../../common';
|
|
import Bluebird from 'bluebird';
|
|
import {
|
|
chatDefaults,
|
|
TAVERN_ID,
|
|
} from '../group';
|
|
import { defaults } from 'lodash';
|
|
|
|
import schema from './schema';
|
|
|
|
schema.methods.isSubscribed = function isSubscribed () {
|
|
return !!this.purchased.plan.customerId; // eslint-disable-line no-implicit-coercion
|
|
};
|
|
|
|
// Get an array of groups ids the user is member of
|
|
schema.methods.getGroups = function getUserGroups () {
|
|
let userGroups = this.guilds.slice(0); // clone user.guilds so we don't modify the original
|
|
if (this.party._id) userGroups.push(this.party._id);
|
|
userGroups.push(TAVERN_ID);
|
|
return userGroups;
|
|
};
|
|
|
|
schema.methods.sendMessage = async function sendMessage (userToReceiveMessage, message) {
|
|
let sender = this;
|
|
|
|
common.refPush(userToReceiveMessage.inbox.messages, chatDefaults(message, sender));
|
|
userToReceiveMessage.inbox.newMessages++;
|
|
userToReceiveMessage._v++;
|
|
userToReceiveMessage.markModified('inbox.messages');
|
|
|
|
common.refPush(sender.inbox.messages, defaults({sent: true}, chatDefaults(message, userToReceiveMessage)));
|
|
sender.markModified('inbox.messages');
|
|
|
|
let promises = [userToReceiveMessage.save(), sender.save()];
|
|
await Bluebird.all(promises);
|
|
};
|
|
|
|
schema.methods.addNotification = function addUserNotification (type, data = {}) {
|
|
this.notifications.push({
|
|
type,
|
|
data,
|
|
});
|
|
};
|
|
|
|
// Add stats.toNextLevel, stats.maxMP and stats.maxHealth
|
|
// to a JSONified User object
|
|
schema.methods.addComputedStatsToJSONObj = function addComputedStatsToUserJSONObj (obj) {
|
|
// NOTE: if an item is manually added to user.stats then
|
|
// common/fns/predictableRandom must be tweaked so the new item is not considered.
|
|
// Otherwise the client will have it while the server won't and the results will be different.
|
|
obj.stats.toNextLevel = common.tnl(this.stats.lvl);
|
|
obj.stats.maxHealth = common.maxHealth;
|
|
obj.stats.maxMP = common.statsComputed(this).maxMP;
|
|
};
|