mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 13:17:24 +01:00
Optimise chat storage by not storing both equipped and costume (#14409)
* don’t store both equipped and costume * fix lint
This commit is contained in:
@@ -541,6 +541,35 @@ describe('POST /chat', () => {
|
||||
.to.eql(userWithStyle.preferences.background);
|
||||
});
|
||||
|
||||
it('creates equipped to user styles', async () => {
|
||||
const userWithStyle = await generateUser({
|
||||
'preferences.costume': false,
|
||||
'auth.timestamps.created': new Date('2022-01-01'),
|
||||
});
|
||||
await userWithStyle.sync();
|
||||
|
||||
const message = await userWithStyle.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage });
|
||||
|
||||
expect(message.message.id).to.exist;
|
||||
expect(message.message.userStyles.items.gear.equipped)
|
||||
.to.eql(userWithStyle.items.gear.equipped);
|
||||
expect(message.message.userStyles.items.gear.costume).to.not.exist;
|
||||
});
|
||||
|
||||
it('creates costume to user styles', async () => {
|
||||
const userWithStyle = await generateUser({
|
||||
'preferences.costume': true,
|
||||
'auth.timestamps.created': new Date('2022-01-01'),
|
||||
});
|
||||
await userWithStyle.sync();
|
||||
|
||||
const message = await userWithStyle.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage });
|
||||
|
||||
expect(message.message.id).to.exist;
|
||||
expect(message.message.userStyles.items.gear.costume).to.eql(userWithStyle.items.gear.costume);
|
||||
expect(message.message.userStyles.items.gear.equipped).to.not.exist;
|
||||
});
|
||||
|
||||
it('adds backer info to chat', async () => {
|
||||
const backerInfo = {
|
||||
npc: 'Town Crier',
|
||||
|
||||
@@ -67,8 +67,11 @@ export function setUserStyles (newMessage, user) {
|
||||
|
||||
if (userCopy.items) {
|
||||
userStyles.items.gear = {};
|
||||
if (userCopy.preferences && userCopy.preferences.costume) {
|
||||
userStyles.items.gear.costume = { ...userCopy.items.gear.costume };
|
||||
} else {
|
||||
userStyles.items.gear.equipped = { ...userCopy.items.gear.equipped };
|
||||
}
|
||||
|
||||
userStyles.items.currentMount = userCopy.items.currentMount;
|
||||
userStyles.items.currentPet = userCopy.items.currentPet;
|
||||
|
||||
Reference in New Issue
Block a user