mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
* transferGems: use receiver language translation for PM strings #7722 * chore(test): DRY up transfer gems test * chore(test): Allow check for language in translation assertion * chore(test): Add test that member locales are used in transfer gems msg * sendMessage: optionally take also the message in sender's language when present, it is stored in the sender's inbox instead of the version in the target language. * transferGems: prepare pm in both languages #7722 * sendMessage: take an object for the second parameter instead * payments: made two more gift strings translatable * buyGems: send both translations for gifted gems * buyGems: send push notifications in target user's locale * createSubscription: send both translations for gifted subs * createSubscription: send push notifications in target user's locale * transferGems: send push notifications in target user's locale * tests: adjust payment tests for translation changes * added function doc for sendMessage * tests: added bilingual test for buyGems
68 lines
2.3 KiB
JavaScript
68 lines
2.3 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;
|
|
};
|
|
|
|
|
|
/**
|
|
* Sends a message to a user. Archives a copy in sender's inbox.
|
|
*
|
|
* @param userToReceiveMessage The receiver
|
|
* @param options
|
|
* @param options.receiverMsg The message to send to the receiver
|
|
* @param options.senderMsg The message to archive instead of receiverMsg
|
|
* @return N/A
|
|
*/
|
|
schema.methods.sendMessage = async function sendMessage (userToReceiveMessage, options) {
|
|
let sender = this;
|
|
let senderMsg = options.senderMsg || options.receiverMsg;
|
|
|
|
common.refPush(userToReceiveMessage.inbox.messages, chatDefaults(options.receiverMsg, sender));
|
|
userToReceiveMessage.inbox.newMessages++;
|
|
userToReceiveMessage._v++;
|
|
userToReceiveMessage.markModified('inbox.messages');
|
|
|
|
common.refPush(sender.inbox.messages, defaults({sent: true}, chatDefaults(senderMsg, 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 stats object
|
|
schema.methods.addComputedStatsToJSONObj = function addComputedStatsToUserJSONObj (statsObject) {
|
|
// 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.
|
|
statsObject.toNextLevel = common.tnl(this.stats.lvl);
|
|
statsObject.maxHealth = common.maxHealth;
|
|
statsObject.maxMP = common.statsComputed(this).maxMP;
|
|
|
|
return statsObject;
|
|
};
|