From 09dad4e36d745f55035acffc8bceee834490a53e Mon Sep 17 00:00:00 2001 From: Natsumi Date: Sat, 5 Nov 2022 01:39:55 +1300 Subject: [PATCH] Dynamic favorite group sizes --- html/src/app.js | 46 +++++++++++++++++++++++++++++++++++++++------- html/src/index.pug | 2 +- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/html/src/app.js b/html/src/app.js index c53fbfd1..0b8ef1e0 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -3203,6 +3203,18 @@ speechSynthesis.getVoices(); API.favoriteAvatarGroups = []; API.isFavoriteLoading = false; API.isFavoriteGroupLoading = false; + API.favoriteLimits = { + maxFavoriteGroups: { + avatar: 6, + friend: 3, + world: 4 + }, + maxFavoritesPerGroup: { + avatar: 50, + friend: 150, + world: 100 + } + }; API.$on('LOGIN', function () { this.cachedFavorites.clear(); @@ -3484,11 +3496,12 @@ speechSynthesis.getVoices(); } }; - API.refreshFavorites = function () { + API.refreshFavorites = async function () { if (this.isFavoriteLoading) { return; } this.isFavoriteLoading = true; + await this.getFavoriteLimits(); this.expireFavorites(); this.bulk({ fn: 'getFavorites', @@ -3538,28 +3551,28 @@ speechSynthesis.getVoices(); API.buildFavoriteGroups = function () { // 450 = ['group_0', 'group_1', 'group_2'] x 150 this.favoriteFriendGroups = []; - for (var i = 0; i < 3; ++i) { + for (var i = 0; i < this.favoriteLimits.maxFavoriteGroups.friend; ++i) { this.favoriteFriendGroups.push({ assign: false, key: `friend:group_${i}`, type: 'friend', name: `group_${i}`, displayName: `Group ${i + 1}`, - capacity: 150, + capacity: this.favoriteLimits.maxFavoritesPerGroup.friend, count: 0, visibility: 'private' }); } // 400 = ['worlds1', 'worlds2', 'worlds3', 'worlds4'] x 100 this.favoriteWorldGroups = []; - for (var i = 0; i < 4; ++i) { + for (var i = 0; i < this.favoriteLimits.maxFavoriteGroups.world; ++i) { this.favoriteWorldGroups.push({ assign: false, key: `world:worlds${i + 1}`, type: 'world', name: `worlds${i + 1}`, displayName: `Group ${i + 1}`, - capacity: 100, + capacity: this.favoriteLimits.maxFavoritesPerGroup.world, count: 0, visibility: 'private' }); @@ -3568,14 +3581,14 @@ speechSynthesis.getVoices(); // Favorite Avatars (0/50) // VRC+ Group 1..5 (0/50) this.favoriteAvatarGroups = []; - for (var i = 0; i < 6; ++i) { + for (var i = 0; i < this.favoriteLimits.maxFavoriteGroups.avatar; ++i) { this.favoriteAvatarGroups.push({ assign: false, key: `avatar:avatars${i + 1}`, type: 'avatar', name: `avatars${i + 1}`, displayName: `Group ${i + 1}`, - capacity: 50, + capacity: this.favoriteLimits.maxFavoritesPerGroup.avatar, count: 0, visibility: 'private' }); @@ -3674,6 +3687,25 @@ speechSynthesis.getVoices(); } }; + API.getFavoriteLimits = function () { + return this.call('auth/user/favoritelimits', { + method: 'GET' + }).then((json) => { + var args = { + json + }; + this.$emit('FAVORITE:LIMITS', args); + return args; + }); + }; + + API.$on('FAVORITE:LIMITS', function (args) { + this.favoriteLimits = { + ...this.favoriteLimits, + ...args.json + }; + }); + API.refreshFavoriteGroups = function () { if (this.isFavoriteGroupLoading) { return; diff --git a/html/src/index.pug b/html/src/index.pug index 91af9d7d..9fe9a28e 100644 --- a/html/src/index.pug +++ b/html/src/index.pug @@ -1768,7 +1768,7 @@ html span(slot="label") span(v-text="list[0]" style="font-weight:bold;font-size:16px") i.x-user-status(style="margin-left:5px" :class="userFavoriteWorldsStatus(list[1])") - span(style="color:#909399;font-size:12px;margin-left:5px") {{ list[2].length }}/100 + span(style="color:#909399;font-size:12px;margin-left:5px") {{ list[2].length }}/{{ API.favoriteLimits.maxFavoritesPerGroup.world }} .x-friend-list(style="margin-top:10px;margin-bottom:15px;min-height:60px") .x-friend-item(v-for="world in list[2]" :key="world.id" @click="showWorldDialog(world.id)" class="x-friend-item-border") .avatar