diff --git a/public/Assets/locales/en.json b/public/Assets/locales/en.json index cd5801a0f..5495bc1cd 100644 --- a/public/Assets/locales/en.json +++ b/public/Assets/locales/en.json @@ -2543,7 +2543,9 @@ "members": "Members", "ccuTooltip": "Current players across public experiences created by this user.", "visitsTooltip": "Lifetime visits across public experiences created by this user.", - "membersTooltip": "Members across communities owned by this user." + "membersTooltip": "Members across communities owned by this user.", + "groupVisits": "Group Visits", + "groupVisitsTooltip": "Lifetime visits across public experiences of communities owned by this user." }, "plus": { "stats": { diff --git a/public/Assets/locales/fr.json b/public/Assets/locales/fr.json index 9907dea87..2a97732b1 100644 --- a/public/Assets/locales/fr.json +++ b/public/Assets/locales/fr.json @@ -2081,7 +2081,9 @@ "members": "Membres", "ccuTooltip": "Joueurs actuels sur les expériences publiques créées par cet utilisateur.", "visitsTooltip": "Visites totales des expériences publiques créées par cet utilisateur.", - "membersTooltip": "Membres des communautés dont cet utilisateur est propriétaire." + "membersTooltip": "Membres des communautés dont cet utilisateur est propriétaire.", + "groupVisits": "Visites de groupe", + "groupVisitsTooltip": "Visites totales des expériences publiques des communautés dont cet utilisateur est propriétaire." }, "plus": { "stats": { diff --git a/src/content/core/settings/settingConfig.js b/src/content/core/settings/settingConfig.js index 4ef06a8ce..9fa724142 100644 --- a/src/content/core/settings/settingConfig.js +++ b/src/content/core/settings/settingConfig.js @@ -1037,6 +1037,17 @@ export const SETTINGS_CONFIG = { type: 'checkbox', default: false, contributors: ['4632962611'], + childSettings: { + creatorStatsGroupVisitsEnabled: { + label: 'Group Visits', + description: [ + 'Shows the combined visits of experiences in communities owned by the user.', + ], + type: 'checkbox', + default: true, + contributors: ['4975603156'], + }, + }, }, socialLinksEnabled: { label: 'Profile Social Links', diff --git a/src/content/features/groups/placevisits.js b/src/content/features/groups/placevisits.js index f8d85a470..ab49e83b8 100644 --- a/src/content/features/groups/placevisits.js +++ b/src/content/features/groups/placevisits.js @@ -4,7 +4,7 @@ import { getGroupIdFromUrl } from '../../core/idExtractor.js'; import { createPill } from '../../core/ui/general/pill.js'; import { t } from '../../core/locale/i18n.js'; -async function fetchTotalVisits(groupId) { +export async function fetchTotalVisits(groupId) { let totalVisits = 0; let cursor = ''; diff --git a/src/content/features/profile/header/creatorStats.js b/src/content/features/profile/header/creatorStats.js index 64029eb96..bf75c087c 100644 --- a/src/content/features/profile/header/creatorStats.js +++ b/src/content/features/profile/header/creatorStats.js @@ -9,6 +9,7 @@ import { } from '../../../core/observer.js'; import { settings } from '../../../core/settings/getSettings.js'; import { createPill } from '../../../core/ui/general/pill.js'; +import { fetchTotalVisits } from '../../groups/placevisits.js'; const GAME_PAGE_SIZE = 50; const API_BATCH_SIZE = 50; @@ -322,12 +323,32 @@ async function getOwnedCommunityStats(userId) { }; } + const groupVisitsEnabled = + (await settings.creatorStatsGroupVisitsEnabled) !== false; + + const visits = groupVisitsEnabled + ? await Promise.all( + ownedMemberships.map((membership) => + fetchTotalVisits(membership?.group?.id), + ), + ) + : []; + + const validVisits = visits.filter( + (count) => count !== null, + ); + return { hasOwnedCommunities: true, members: validCounts.reduce( (total, count) => total + count, 0, ), + hasGroupVisits: validVisits.length > 0, + groupVisits: validVisits.reduce( + (total, count) => total + count, + 0, + ), }; } @@ -399,6 +420,10 @@ function getRequiredStats(stats) { required.push('members'); } + if (stats.communities?.hasGroupVisits) { + required.push('groupVisits'); + } + return required; } @@ -492,6 +517,19 @@ function renderStats( ); } + if (stats.communities?.hasGroupVisits) { + pills.push( + createStatPill( + stats.communities.groupVisits, + ts('creatorStats.groupVisits'), + ts( + 'creatorStats.groupVisitsTooltip', + ), + 'groupVisits', + ), + ); + } + container.append(...pills); return true;