mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
* fix(content): textual tweaks and updates * fix(link): direct to FAQ instead of wiki * fix(faq): correct Markdown * Show orb of rebirth confirmation modal after use (window refresh) * Set and check rebirth confirmation modal from localstorage Set and check rebirth confirmation modal from localstorage after window reload * Don't show orb of rebirth confirmation modal until page reloads * message effective limit optimization * Keep max limit for web (400 recent messages) * Fix amount of messages initially being shown * PM_PER_PAGE set to 50 * Increases number of messages in inbox test * Increases number of messages for inbox pagination test * Set and check rebirth confirmation modal from localstorage Set and check rebirth confirmation modal from localstorage after window reload * Don't show orb of rebirth confirmation modal until page reloads * message effective limit optimization * Keep max limit for web (400 recent messages) * Add UUID validation for 'before' query parameter * add party message stress test tool in admin panel * lint * add MAX_PM_COUNT of 400, admin tool for stress testing messages * comment * update stress test inbox message tool to use logged in user * comment --------- Co-authored-by: Kalista Payne <kalista@habitica.com>
145 lines
4.8 KiB
JavaScript
145 lines
4.8 KiB
JavaScript
import _ from 'lodash';
|
|
import { chatModel as Chat } from '../../models/message';
|
|
import shared from '../../../common';
|
|
import { // eslint-disable-line import/no-cycle
|
|
MAX_CHAT_COUNT,
|
|
MAX_SUBBED_GROUP_CHAT_COUNT,
|
|
} from '../../models/group';
|
|
|
|
const questScrolls = shared.content.quests;
|
|
|
|
// @TODO: Don't use this method when the group can be saved.
|
|
export async function getGroupChat (group, options = {}) {
|
|
const { limit, before } = options;
|
|
|
|
let maxChatCount = MAX_CHAT_COUNT;
|
|
if (group.chatLimitCount && group.chatLimitCount >= MAX_CHAT_COUNT) {
|
|
maxChatCount = group.chatLimitCount;
|
|
} else if (group.hasActiveGroupPlan()) {
|
|
maxChatCount = MAX_SUBBED_GROUP_CHAT_COUNT;
|
|
}
|
|
|
|
const effectiveLimit = limit !== undefined ? Math.min(limit, maxChatCount) : maxChatCount;
|
|
|
|
let query = Chat.find({ groupId: group._id })
|
|
.sort('-timestamp');
|
|
|
|
if (before) {
|
|
const beforeMessage = await Chat.findOne({ _id: before }).exec();
|
|
if (beforeMessage) {
|
|
query = query.where('timestamp').lt(beforeMessage.timestamp);
|
|
}
|
|
}
|
|
|
|
const groupChat = await query.limit(effectiveLimit).exec();
|
|
|
|
// @TODO: Concat old chat to keep continuity of chat stored on group object
|
|
const currentGroupChat = group.chat || [];
|
|
const concatedGroupChat = groupChat.concat(currentGroupChat);
|
|
|
|
group.chat = concatedGroupChat.reduce((previous, current) => {
|
|
const foundMessage = previous.find(message => message.id === current.id);
|
|
if (!foundMessage) previous.push(current);
|
|
return previous;
|
|
}, []);
|
|
}
|
|
|
|
export function translateMessage (lang, info) {
|
|
let msg;
|
|
let foundText = '';
|
|
const { spells } = shared.content;
|
|
const { quests } = shared.content;
|
|
|
|
switch (info.type) { // eslint-disable-line default-case
|
|
case 'quest_start':
|
|
msg = shared.i18n.t('chatQuestStarted', { questName: questScrolls[info.quest].text(lang) }, lang);
|
|
break;
|
|
|
|
case 'boss_damage':
|
|
msg = shared.i18n.t('chatBossDamage', {
|
|
username: info.user,
|
|
bossName: questScrolls[info.quest].boss.name(lang),
|
|
userDamage: info.userDamage,
|
|
bossDamage: info.bossDamage,
|
|
}, lang);
|
|
break;
|
|
|
|
case 'boss_dont_attack':
|
|
msg = shared.i18n.t('chatBossDontAttack', { username: info.user, bossName: questScrolls[info.quest].boss.name(lang), userDamage: info.userDamage }, lang);
|
|
break;
|
|
|
|
case 'boss_rage':
|
|
msg = questScrolls[info.quest].boss.rage.effect(lang);
|
|
break;
|
|
|
|
case 'boss_defeated':
|
|
msg = shared.i18n.t('chatBossDefeated', { bossName: questScrolls[info.quest].boss.name(lang) }, lang);
|
|
break;
|
|
|
|
case 'user_found_items':
|
|
foundText = _.reduce(info.items, (m, v, k) => {
|
|
m.push(`${v} ${questScrolls[info.quest].collect[k].text(lang)}`);
|
|
return m;
|
|
}, []).join(', ');
|
|
msg = shared.i18n.t('chatFindItems', { username: info.user, items: foundText }, lang);
|
|
break;
|
|
|
|
case 'all_items_found':
|
|
msg = shared.i18n.t('chatItemQuestFinish', lang);
|
|
break;
|
|
|
|
case 'spell_cast_party':
|
|
msg = shared.i18n.t('chatCastSpellParty', { username: info.user, spell: spells[info.class][info.spell].text(lang) }, lang);
|
|
break;
|
|
|
|
case 'spell_cast_user':
|
|
msg = shared.i18n.t('chatCastSpellUser', { username: info.user, spell: spells[info.class][info.spell].text(lang), target: info.target }, lang);
|
|
break;
|
|
|
|
case 'spell_cast_party_multi':
|
|
msg = shared.i18n.t('chatCastSpellPartyTimes', { username: info.user, spell: spells[info.class][info.spell].text(lang), times: info.times }, lang);
|
|
break;
|
|
|
|
case 'spell_cast_user_multi':
|
|
msg = shared.i18n.t('chatCastSpellUserTimes', {
|
|
username: info.user,
|
|
spell: spells[info.class][info.spell].text(lang),
|
|
target: info.target,
|
|
times: info.times,
|
|
}, lang);
|
|
break;
|
|
|
|
case 'quest_cancel':
|
|
msg = shared.i18n.t('chatQuestCancelled', { username: info.user, questName: questScrolls[info.quest].text(lang) }, lang);
|
|
break;
|
|
|
|
case 'quest_abort':
|
|
msg = shared.i18n.t('chatQuestAborted', { username: info.user, questName: questScrolls[info.quest].text(lang) }, lang);
|
|
break;
|
|
|
|
case 'tavern_quest_completed':
|
|
msg = quests[info.quest].completionChat(lang);
|
|
break;
|
|
|
|
case 'tavern_boss_rage_tired':
|
|
msg = shared.i18n.t('tavernBossTired', { rageName: quests[info.quest].boss.rage.title(lang), bossName: quests[info.quest].boss.name(lang) }, lang);
|
|
break;
|
|
|
|
case 'tavern_boss_rage':
|
|
msg = quests[info.quest].boss.rage[info.scene](lang);
|
|
break;
|
|
|
|
case 'tavern_boss_desperation':
|
|
msg = quests[info.quest].boss.desperation.text(lang);
|
|
break;
|
|
|
|
case 'claim_task':
|
|
msg = shared.i18n.t('userIsClamingTask', { username: info.user, task: info.task }, lang);
|
|
break;
|
|
|
|
default:
|
|
msg = 'Error translating party chat. Unknown message type.';
|
|
}
|
|
return msg;
|
|
}
|