mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 14:26:06 +02:00
refactor store
This commit is contained in:
@@ -19,6 +19,7 @@ import { AppDebug } from '../service/appConfig';
|
||||
import { database } from '../service/database';
|
||||
import { patchAvatarFromEvent } from '../queries';
|
||||
import { processBulk } from '../service/request';
|
||||
import { applyFavorite } from '../coordinators/favoriteCoordinator';
|
||||
import { useAdvancedSettingsStore } from './settings/advanced';
|
||||
import { useAvatarProviderStore } from './avatarProvider';
|
||||
import { useFavoriteStore } from './favorite';
|
||||
@@ -114,7 +115,7 @@ export const useAvatarStore = defineStore('Avatar', () => {
|
||||
listing.displayName = replaceBioSymbols(listing.displayName);
|
||||
listing.description = replaceBioSymbols(listing.description);
|
||||
}
|
||||
favoriteStore.applyFavorite('avatar', ref.id);
|
||||
applyFavorite('avatar', ref.id);
|
||||
if (favoriteStore.localAvatarFavoritesList.includes(ref.id)) {
|
||||
const avatarRef = ref;
|
||||
favoriteStore.syncLocalAvatarFavoriteRef(avatarRef);
|
||||
|
||||
+22
-1188
File diff suppressed because it is too large
Load Diff
+7
-8
@@ -3,8 +3,6 @@ import { defineStore } from 'pinia';
|
||||
|
||||
import { database } from '../service/database';
|
||||
import { useFriendStore } from './friend';
|
||||
import { useNotificationStore } from './notification';
|
||||
import { useSharedFeedStore } from './sharedFeed';
|
||||
import { useVrcxStore } from './vrcx';
|
||||
import { watchState } from '../service/watchState';
|
||||
|
||||
@@ -12,9 +10,7 @@ import configRepository from '../service/config';
|
||||
|
||||
export const useFeedStore = defineStore('Feed', () => {
|
||||
const friendStore = useFriendStore();
|
||||
const notificationStore = useNotificationStore();
|
||||
const vrcxStore = useVrcxStore();
|
||||
const sharedFeedStore = useSharedFeedStore();
|
||||
|
||||
const feedTableData = shallowRef([]);
|
||||
const feedTable = ref({
|
||||
@@ -170,9 +166,12 @@ export const useFeedStore = defineStore('Feed', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function addFeed(feed) {
|
||||
notificationStore.queueFeedNoty(feed);
|
||||
sharedFeedStore.addEntry(feed);
|
||||
/**
|
||||
* Appends a feed entry to the local table if it passes filters.
|
||||
* Does NOT trigger notifications or shared feed — that is the caller's responsibility.
|
||||
* @param {object} feed The feed entry to add.
|
||||
*/
|
||||
function addFeedEntry(feed) {
|
||||
if (
|
||||
feedTable.value.filter.length > 0 &&
|
||||
!feedTable.value.filter.includes(feed.type)
|
||||
@@ -222,6 +221,6 @@ export const useFeedStore = defineStore('Feed', () => {
|
||||
feedTableData,
|
||||
initFeedTable,
|
||||
feedTableLookup,
|
||||
addFeed
|
||||
addFeedEntry
|
||||
};
|
||||
});
|
||||
|
||||
+41
-211
@@ -1,38 +1,9 @@
|
||||
import { reactive, ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { toast } from 'vue-sonner';
|
||||
|
||||
import {
|
||||
deleteVRChatCache as _deleteVRChatCache,
|
||||
isRealInstance
|
||||
} from '../shared/utils';
|
||||
import { database } from '../service/database';
|
||||
import { runGameRunningChangedFlow } from '../coordinators/gameCoordinator';
|
||||
import { useAdvancedSettingsStore } from './settings/advanced';
|
||||
import { useAvatarStore } from './avatar';
|
||||
import { useGameLogStore } from './gameLog';
|
||||
import { useLaunchStore } from './launch';
|
||||
import { useLocationStore } from './location';
|
||||
import { useModalStore } from './modal';
|
||||
import { useNotificationStore } from './notification';
|
||||
import { useVrStore } from './vr';
|
||||
import { useWorldStore } from './world';
|
||||
|
||||
import configRepository from '../service/config.js';
|
||||
|
||||
import * as workerTimers from 'worker-timers';
|
||||
|
||||
export const useGameStore = defineStore('Game', () => {
|
||||
const advancedSettingsStore = useAdvancedSettingsStore();
|
||||
const locationStore = useLocationStore();
|
||||
const notificationStore = useNotificationStore();
|
||||
const avatarStore = useAvatarStore();
|
||||
const launchStore = useLaunchStore();
|
||||
const worldStore = useWorldStore();
|
||||
const gameLogStore = useGameLogStore();
|
||||
const vrStore = useVrStore();
|
||||
const modalStore = useModalStore();
|
||||
|
||||
const state = reactive({
|
||||
lastCrashedTime: null
|
||||
});
|
||||
@@ -60,139 +31,13 @@ export const useGameStore = defineStore('Game', () => {
|
||||
|
||||
init();
|
||||
|
||||
/**
|
||||
* @param {object} ref Avatar or world reference payload.
|
||||
*/
|
||||
async function deleteVRChatCache(ref) {
|
||||
await _deleteVRChatCache(ref);
|
||||
getVRChatCacheSize();
|
||||
worldStore.updateVRChatWorldCache();
|
||||
avatarStore.updateVRChatAvatarCache();
|
||||
}
|
||||
// --- Atomic setters ---
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {boolean} value Game running flag.
|
||||
*/
|
||||
function autoVRChatCacheManagement() {
|
||||
if (advancedSettingsStore.autoSweepVRChatCache) {
|
||||
sweepVRChatCache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function sweepVRChatCache() {
|
||||
try {
|
||||
const output = await AssetBundleManager.SweepCache();
|
||||
console.log('SweepCache', output);
|
||||
} catch (e) {
|
||||
console.error('SweepCache failed', e);
|
||||
}
|
||||
if (advancedSettingsStore.isVRChatConfigDialogVisible) {
|
||||
getVRChatCacheSize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function checkIfGameCrashed() {
|
||||
if (!advancedSettingsStore.relaunchVRChatAfterCrash) {
|
||||
return;
|
||||
}
|
||||
const { location } = locationStore.lastLocation;
|
||||
AppApi.VrcClosedGracefully().then((result) => {
|
||||
if (result || !isRealInstance(location)) {
|
||||
return;
|
||||
}
|
||||
// check if relaunched less than 2mins ago (prvent crash loop)
|
||||
if (
|
||||
state.lastCrashedTime &&
|
||||
new Date().getTime() - state.lastCrashedTime.getTime() < 120_000
|
||||
) {
|
||||
console.log('VRChat was recently crashed, not relaunching');
|
||||
return;
|
||||
}
|
||||
state.lastCrashedTime = new Date();
|
||||
// wait a bit for SteamVR to potentially close before deciding to relaunch
|
||||
let restartDelay = 8000;
|
||||
if (isGameNoVR.value) {
|
||||
// wait for game to close before relaunching
|
||||
restartDelay = 2000;
|
||||
}
|
||||
workerTimers.setTimeout(
|
||||
() => restartCrashedGame(location),
|
||||
restartDelay
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} location Last known location to relaunch.
|
||||
*/
|
||||
function restartCrashedGame(location) {
|
||||
if (!isGameNoVR.value && !isSteamVRRunning.value) {
|
||||
console.log("SteamVR isn't running, not relaunching VRChat");
|
||||
return;
|
||||
}
|
||||
AppApi.FocusWindow();
|
||||
const message = 'VRChat crashed, attempting to rejoin last instance';
|
||||
toast(message);
|
||||
const entry = {
|
||||
created_at: new Date().toJSON(),
|
||||
type: 'Event',
|
||||
data: message
|
||||
};
|
||||
database.addGamelogEventToDatabase(entry);
|
||||
notificationStore.queueGameLogNoty(entry);
|
||||
gameLogStore.addGameLog(entry);
|
||||
launchStore.launchGame(location, '', isGameNoVR.value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function getVRChatCacheSize() {
|
||||
VRChatCacheSizeLoading.value = true;
|
||||
const totalCacheSize = 30;
|
||||
VRChatTotalCacheSize.value = totalCacheSize;
|
||||
const usedCacheSize = await AssetBundleManager.GetCacheSize();
|
||||
VRChatUsedCacheSize.value = (usedCacheSize / 1073741824).toFixed(2);
|
||||
VRChatCacheSizeLoading.value = false;
|
||||
}
|
||||
|
||||
// use in C#
|
||||
/**
|
||||
* @param {boolean} isGameRunningArg Game running flag from IPC.
|
||||
* @param {boolean} isSteamVRRunningArg SteamVR running flag from IPC.
|
||||
*/
|
||||
async function updateIsGameRunning(isGameRunningArg, isSteamVRRunningArg) {
|
||||
if (advancedSettingsStore.gameLogDisabled) {
|
||||
return;
|
||||
}
|
||||
if (isGameRunningArg !== isGameRunning.value) {
|
||||
isGameRunning.value = isGameRunningArg;
|
||||
await runGameRunningChangedFlow(isGameRunningArg);
|
||||
console.log(new Date(), 'isGameRunning', isGameRunningArg);
|
||||
}
|
||||
|
||||
if (isSteamVRRunningArg !== isSteamVRRunning.value) {
|
||||
isSteamVRRunning.value = isSteamVRRunningArg;
|
||||
console.log('isSteamVRRunning:', isSteamVRRunningArg);
|
||||
}
|
||||
vrStore.updateOpenVR();
|
||||
}
|
||||
|
||||
// use in C#
|
||||
/**
|
||||
* @param {boolean} isHmdAfkArg HMD AFK flag from VR polling.
|
||||
*/
|
||||
function updateIsHmdAfk(isHmdAfkArg) {
|
||||
if (isHmdAfkArg !== isHmdAfk.value) {
|
||||
isHmdAfk.value = isHmdAfkArg;
|
||||
console.log('isHmdAfk', isHmdAfkArg);
|
||||
}
|
||||
function setIsGameRunning(value) {
|
||||
isGameRunning.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,50 +48,38 @@ export const useGameStore = defineStore('Game', () => {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {boolean} value SteamVR running flag.
|
||||
*/
|
||||
async function checkVRChatDebugLogging() {
|
||||
if (advancedSettingsStore.gameLogDisabled) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const loggingEnabled =
|
||||
await getVRChatRegistryKey('LOGGING_ENABLED');
|
||||
if (
|
||||
loggingEnabled === null ||
|
||||
typeof loggingEnabled === 'undefined'
|
||||
) {
|
||||
// key not found
|
||||
return;
|
||||
}
|
||||
if (parseInt(loggingEnabled, 10) === 1) {
|
||||
// already enabled
|
||||
return;
|
||||
}
|
||||
const result = await AppApi.SetVRChatRegistryKey(
|
||||
'LOGGING_ENABLED',
|
||||
'1',
|
||||
4
|
||||
);
|
||||
if (!result) {
|
||||
// failed to set key
|
||||
modalStore.alert({
|
||||
description:
|
||||
'VRCX has noticed VRChat debug logging is disabled. VRCX requires debug logging in order to function correctly. Please enable debug logging in VRChat quick menu settings > debug > enable debug logging, then rejoin the instance or restart VRChat.',
|
||||
title: 'Enable debug logging'
|
||||
});
|
||||
console.error('Failed to enable debug logging', result);
|
||||
return;
|
||||
}
|
||||
modalStore.alert({
|
||||
description:
|
||||
'VRCX has noticed VRChat debug logging is disabled and automatically re-enabled it. VRCX requires debug logging in order to function correctly.',
|
||||
title: 'Enabled debug logging'
|
||||
});
|
||||
console.log('Enabled debug logging');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
function setIsSteamVRRunning(value) {
|
||||
isSteamVRRunning.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} value HMD AFK flag.
|
||||
*/
|
||||
function setIsHmdAfk(value) {
|
||||
isHmdAfk.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Date | null} value Last crashed time.
|
||||
*/
|
||||
function setLastCrashedTime(value) {
|
||||
state.lastCrashedTime = value;
|
||||
}
|
||||
|
||||
// --- Self-contained operations (no cross-store deps) ---
|
||||
|
||||
/**
|
||||
* Fetches VRChat cache size from AssetBundleManager.
|
||||
*/
|
||||
async function getVRChatCacheSize() {
|
||||
VRChatCacheSizeLoading.value = true;
|
||||
const totalCacheSize = 30;
|
||||
VRChatTotalCacheSize.value = totalCacheSize;
|
||||
const usedCacheSize = await AssetBundleManager.GetCacheSize();
|
||||
VRChatUsedCacheSize.value = (usedCacheSize / 1073741824).toFixed(2);
|
||||
VRChatCacheSizeLoading.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,15 +104,12 @@ export const useGameStore = defineStore('Game', () => {
|
||||
isSteamVRRunning,
|
||||
isHmdAfk,
|
||||
|
||||
deleteVRChatCache,
|
||||
sweepVRChatCache,
|
||||
getVRChatCacheSize,
|
||||
updateIsGameRunning,
|
||||
setIsGameRunning,
|
||||
setIsGameNoVR,
|
||||
getVRChatRegistryKey,
|
||||
checkVRChatDebugLogging,
|
||||
autoVRChatCacheManagement,
|
||||
checkIfGameCrashed,
|
||||
updateIsHmdAfk
|
||||
setIsSteamVRRunning,
|
||||
setIsHmdAfk,
|
||||
setLastCrashedTime,
|
||||
getVRChatCacheSize,
|
||||
getVRChatRegistryKey
|
||||
};
|
||||
});
|
||||
|
||||
@@ -31,6 +31,7 @@ import { useGameStore } from '../game';
|
||||
import { useGeneralSettingsStore } from '../settings/general';
|
||||
import { useInstanceStore } from '../instance';
|
||||
import { useLocationStore } from '../location';
|
||||
import { runLastLocationResetFlow, runUpdateCurrentUserLocationFlow } from '../../coordinators/locationCoordinator';
|
||||
import { useModalStore } from '../modal';
|
||||
import { useNotificationStore } from '../notification';
|
||||
import { usePhotonStore } from '../photon';
|
||||
@@ -376,7 +377,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
||||
}
|
||||
});
|
||||
|
||||
locationStore.updateCurrentUserLocation();
|
||||
runUpdateCurrentUserLocationFlow();
|
||||
instanceStore.updateCurrentInstanceWorld();
|
||||
vrStore.updateVRLastLocation();
|
||||
instanceStore.getCurrentInstanceUserList();
|
||||
@@ -560,7 +561,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
||||
type: 'LocationDestination',
|
||||
location: gameLog.location
|
||||
});
|
||||
locationStore.lastLocationReset(gameLog.dt);
|
||||
runLastLocationResetFlow(gameLog.dt);
|
||||
locationStore.setLastLocationLocation('traveling');
|
||||
locationStore.setLastLocationDestination(gameLog.location);
|
||||
locationStore.setLastLocationDestinationTime(
|
||||
@@ -568,7 +569,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
||||
);
|
||||
state.lastLocationAvatarList.clear();
|
||||
instanceStore.removeQueuedInstance(gameLog.location);
|
||||
locationStore.updateCurrentUserLocation();
|
||||
runUpdateCurrentUserLocationFlow();
|
||||
clearNowPlaying();
|
||||
instanceStore.updateCurrentInstanceWorld();
|
||||
userStore.applyUserDialogLocation();
|
||||
@@ -583,7 +584,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
||||
);
|
||||
const worldName = replaceBioSymbols(gameLog.worldName);
|
||||
if (gameStore.isGameRunning) {
|
||||
locationStore.lastLocationReset(gameLog.dt);
|
||||
runLastLocationResetFlow(gameLog.dt);
|
||||
clearNowPlaying();
|
||||
locationStore.setLastLocation({
|
||||
date: Date.parse(gameLog.dt),
|
||||
@@ -593,7 +594,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
||||
friendList: new Map()
|
||||
});
|
||||
instanceStore.removeQueuedInstance(gameLog.location);
|
||||
locationStore.updateCurrentUserLocation();
|
||||
runUpdateCurrentUserLocationFlow();
|
||||
vrStore.updateVRLastLocation();
|
||||
instanceStore.updateCurrentInstanceWorld();
|
||||
userStore.applyUserDialogLocation();
|
||||
|
||||
+2
-39
@@ -1,22 +1,14 @@
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { instanceRequest, inviteMessagesRequest } from '../api';
|
||||
import { parseLocation } from '../shared/utils';
|
||||
import { inviteMessagesRequest } from '../api';
|
||||
import { useAdvancedSettingsStore } from './settings/advanced';
|
||||
import { useGameStore } from './game';
|
||||
import { useInstanceStore } from './instance';
|
||||
import { useLaunchStore } from './launch';
|
||||
import { watchState } from '../service/watchState';
|
||||
|
||||
export const useInviteStore = defineStore('Invite', () => {
|
||||
const instanceStore = useInstanceStore();
|
||||
const gameStore = useGameStore();
|
||||
const launchStore = useLaunchStore();
|
||||
const advancedSettingsStore = useAdvancedSettingsStore();
|
||||
const { t } = useI18n();
|
||||
|
||||
const inviteMessageTable = ref({
|
||||
data: [],
|
||||
@@ -93,35 +85,7 @@ export const useInviteStore = defineStore('Invite', () => {
|
||||
});
|
||||
}
|
||||
|
||||
function newInstanceSelfInvite(worldId) {
|
||||
instanceStore.createNewInstance(worldId).then((args) => {
|
||||
const location = args?.json?.location;
|
||||
if (!location) {
|
||||
toast.error(t('message.instance.create_failed'));
|
||||
return;
|
||||
}
|
||||
// self invite
|
||||
const L = parseLocation(location);
|
||||
if (!L.isRealInstance) {
|
||||
return;
|
||||
}
|
||||
if (canOpenInstanceInGame.value) {
|
||||
const secureOrShortName =
|
||||
args.json.shortName || args.json.secureName;
|
||||
launchStore.tryOpenInstanceInVrc(location, secureOrShortName);
|
||||
return;
|
||||
}
|
||||
instanceRequest
|
||||
.selfInvite({
|
||||
instanceId: L.instanceId,
|
||||
worldId: L.worldId
|
||||
})
|
||||
.then((args) => {
|
||||
toast.success(t('message.invite.self_sent'));
|
||||
return args;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
inviteMessageTable,
|
||||
@@ -129,7 +93,6 @@ export const useInviteStore = defineStore('Invite', () => {
|
||||
inviteRequestMessageTable,
|
||||
inviteRequestResponseMessageTable,
|
||||
refreshInviteMessageTableData,
|
||||
newInstanceSelfInvite,
|
||||
canOpenInstanceInGame
|
||||
};
|
||||
});
|
||||
|
||||
+1
-175
@@ -1,32 +1,7 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import {
|
||||
getGroupName,
|
||||
getWorldName,
|
||||
isRealInstance,
|
||||
parseLocation
|
||||
} from '../shared/utils';
|
||||
import { database } from '../service/database';
|
||||
import { useAdvancedSettingsStore } from './settings/advanced';
|
||||
import { useGameLogStore } from './gameLog';
|
||||
import { useGameStore } from './game';
|
||||
import { useInstanceStore } from './instance';
|
||||
import { useNotificationStore } from './notification';
|
||||
import { usePhotonStore } from './photon';
|
||||
import { useUserStore } from './user';
|
||||
import { useVrStore } from './vr';
|
||||
|
||||
export const useLocationStore = defineStore('Location', () => {
|
||||
const advancedSettingsStore = useAdvancedSettingsStore();
|
||||
const userStore = useUserStore();
|
||||
const instanceStore = useInstanceStore();
|
||||
const notificationStore = useNotificationStore();
|
||||
const gameStore = useGameStore();
|
||||
const vrStore = useVrStore();
|
||||
const photonStore = usePhotonStore();
|
||||
const gameLogStore = useGameLogStore();
|
||||
|
||||
const lastLocation = ref({
|
||||
date: null,
|
||||
location: '',
|
||||
@@ -37,153 +12,6 @@ export const useLocationStore = defineStore('Location', () => {
|
||||
const lastLocationDestination = ref('');
|
||||
const lastLocationDestinationTime = ref(0);
|
||||
|
||||
function updateCurrentUserLocation() {
|
||||
const ref = userStore.cachedUsers.get(userStore.currentUser.id);
|
||||
if (typeof ref === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
// update cached user with both gameLog and API locations
|
||||
let currentLocation = userStore.currentUser.$locationTag;
|
||||
const L = parseLocation(currentLocation);
|
||||
if (L.isTraveling) {
|
||||
currentLocation = userStore.currentUser.$travelingToLocation;
|
||||
}
|
||||
ref.location = userStore.currentUser.$locationTag;
|
||||
ref.travelingToLocation = userStore.currentUser.$travelingToLocation;
|
||||
|
||||
if (
|
||||
gameStore.isGameRunning &&
|
||||
!advancedSettingsStore.gameLogDisabled &&
|
||||
lastLocation.value.location !== ''
|
||||
) {
|
||||
// use gameLog instead of API when game is running
|
||||
currentLocation = lastLocation.value.location;
|
||||
if (lastLocation.value.location === 'traveling') {
|
||||
currentLocation = lastLocationDestination.value;
|
||||
}
|
||||
ref.location = lastLocation.value.location;
|
||||
ref.travelingToLocation = lastLocationDestination.value;
|
||||
}
|
||||
|
||||
ref.$online_for = userStore.currentUser.$online_for;
|
||||
ref.$offline_for = userStore.currentUser.$offline_for;
|
||||
ref.$location = parseLocation(currentLocation);
|
||||
if (!gameStore.isGameRunning || advancedSettingsStore.gameLogDisabled) {
|
||||
ref.$location_at = userStore.currentUser.$location_at;
|
||||
ref.$travelingToTime = userStore.currentUser.$travelingToTime;
|
||||
userStore.applyUserDialogLocation();
|
||||
instanceStore.applyWorldDialogInstances();
|
||||
instanceStore.applyGroupDialogInstances();
|
||||
} else {
|
||||
ref.$location_at = lastLocation.value.date;
|
||||
ref.$travelingToTime = lastLocationDestinationTime.value;
|
||||
userStore.setCurrentUserTravelingToTime(
|
||||
lastLocationDestinationTime.value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function setCurrentUserLocation(location, travelingToLocation) {
|
||||
userStore.setCurrentUserLocationState(location, travelingToLocation);
|
||||
updateCurrentUserLocation();
|
||||
|
||||
// janky gameLog support for Quest
|
||||
if (gameStore.isGameRunning) {
|
||||
// with the current state of things, lets not run this if we don't need to
|
||||
return;
|
||||
}
|
||||
const lastLocationArray = await database.lookupGameLogDatabase(
|
||||
['Location'],
|
||||
[],
|
||||
1
|
||||
);
|
||||
const lastLocationTemp =
|
||||
lastLocationArray.length > 0 ? lastLocationArray[0].location : '';
|
||||
if (lastLocationTemp === location) {
|
||||
return;
|
||||
}
|
||||
lastLocationDestination.value = '';
|
||||
lastLocationDestinationTime.value = 0;
|
||||
|
||||
if (isRealInstance(location)) {
|
||||
const dt = new Date().toJSON();
|
||||
const L = parseLocation(location);
|
||||
|
||||
lastLocation.value.location = location;
|
||||
lastLocation.value.date = Date.now();
|
||||
|
||||
const entry = {
|
||||
created_at: dt,
|
||||
type: 'Location',
|
||||
location,
|
||||
worldId: L.worldId,
|
||||
worldName: await getWorldName(L.worldId),
|
||||
groupName: await getGroupName(L.groupId),
|
||||
time: 0
|
||||
};
|
||||
database.addGamelogLocationToDatabase(entry);
|
||||
notificationStore.queueGameLogNoty(entry);
|
||||
gameLogStore.addGameLog(entry);
|
||||
instanceStore.addInstanceJoinHistory(location, dt);
|
||||
|
||||
userStore.applyUserDialogLocation();
|
||||
instanceStore.applyWorldDialogInstances();
|
||||
instanceStore.applyGroupDialogInstances();
|
||||
} else {
|
||||
lastLocation.value.location = '';
|
||||
lastLocation.value.date = null;
|
||||
}
|
||||
}
|
||||
|
||||
function lastLocationReset(gameLogDate) {
|
||||
let dateTime = gameLogDate;
|
||||
if (!gameLogDate) {
|
||||
dateTime = new Date().toJSON();
|
||||
}
|
||||
const dateTimeStamp = Date.parse(dateTime);
|
||||
photonStore.resetLocationPhotonState();
|
||||
const playerList = Array.from(lastLocation.value.playerList.values());
|
||||
const dataBaseEntries = [];
|
||||
for (const ref of playerList) {
|
||||
const entry = {
|
||||
created_at: dateTime,
|
||||
type: 'OnPlayerLeft',
|
||||
displayName: ref.displayName,
|
||||
location: lastLocation.value.location,
|
||||
userId: ref.userId,
|
||||
time: dateTimeStamp - ref.joinTime
|
||||
};
|
||||
dataBaseEntries.unshift(entry);
|
||||
gameLogStore.addGameLog(entry);
|
||||
}
|
||||
database.addGamelogJoinLeaveBulk(dataBaseEntries);
|
||||
if (lastLocation.value.date !== null && lastLocation.value.date > 0) {
|
||||
const update = {
|
||||
time: dateTimeStamp - lastLocation.value.date,
|
||||
created_at: new Date(lastLocation.value.date).toJSON()
|
||||
};
|
||||
database.updateGamelogLocationTimeToDatabase(update);
|
||||
}
|
||||
lastLocationDestination.value = '';
|
||||
lastLocationDestinationTime.value = 0;
|
||||
lastLocation.value = {
|
||||
date: 0,
|
||||
location: '',
|
||||
name: '',
|
||||
playerList: new Map(),
|
||||
friendList: new Map()
|
||||
};
|
||||
updateCurrentUserLocation();
|
||||
instanceStore.updateCurrentInstanceWorld();
|
||||
vrStore.updateVRLastLocation();
|
||||
instanceStore.getCurrentInstanceUserList();
|
||||
gameLogStore.resetLastMediaUrls();
|
||||
userStore.applyUserDialogLocation();
|
||||
instanceStore.applyWorldDialogInstances();
|
||||
instanceStore.applyGroupDialogInstances();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{date: number|null, location: string, name: string, playerList: Map<any, any>, friendList: Map<any, any>}} value
|
||||
*/
|
||||
@@ -216,12 +44,10 @@ export const useLocationStore = defineStore('Location', () => {
|
||||
lastLocation,
|
||||
lastLocationDestination,
|
||||
lastLocationDestinationTime,
|
||||
updateCurrentUserLocation,
|
||||
setCurrentUserLocation,
|
||||
lastLocationReset,
|
||||
setLastLocation,
|
||||
setLastLocationLocation,
|
||||
setLastLocationDestination,
|
||||
setLastLocationDestinationTime
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { avatarModerationRequest, playerModerationRequest } from '../api';
|
||||
import { useAvatarStore } from './avatar';
|
||||
import { playerModerationRequest } from '../api';
|
||||
import { useUserStore } from './user';
|
||||
import { watchState } from '../service/watchState';
|
||||
|
||||
export const useModerationStore = defineStore('Moderation', () => {
|
||||
const avatarStore = useAvatarStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const cachedPlayerModerations = reactive(new Map());
|
||||
@@ -37,9 +35,6 @@ export const useModerationStore = defineStore('Moderation', () => {
|
||||
cachedPlayerModerationsUserIds.clear();
|
||||
playerModerationTable.value.loading = false;
|
||||
playerModerationTable.value.data = [];
|
||||
if (isLoggedIn) {
|
||||
refreshPlayerModerations();
|
||||
}
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
);
|
||||
@@ -178,41 +173,7 @@ export const useModerationStore = defineStore('Moderation', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshPlayerModerations() {
|
||||
if (playerModerationTable.value.loading) {
|
||||
return;
|
||||
}
|
||||
playerModerationTable.value.loading = true;
|
||||
expirePlayerModerations();
|
||||
Promise.all([
|
||||
playerModerationRequest.getPlayerModerations(),
|
||||
avatarModerationRequest.getAvatarModerations()
|
||||
])
|
||||
.finally(() => {
|
||||
playerModerationTable.value.loading = false;
|
||||
})
|
||||
.then((res) => {
|
||||
// TODO: compare with cachedAvatarModerations
|
||||
avatarStore.resetCachedAvatarModerations();
|
||||
if (res[1]?.json) {
|
||||
for (const json of res[1].json) {
|
||||
avatarStore.applyAvatarModeration(json);
|
||||
}
|
||||
}
|
||||
if (res[0]?.json) {
|
||||
for (let json of res[0].json) {
|
||||
applyPlayerModeration(json);
|
||||
}
|
||||
}
|
||||
deleteExpiredPlayerModerations();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
'Failed to load player/avatar moderations:',
|
||||
error
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get user moderations
|
||||
@@ -257,7 +218,8 @@ export const useModerationStore = defineStore('Moderation', () => {
|
||||
cachedPlayerModerationsUserIds,
|
||||
playerModerationTable,
|
||||
|
||||
refreshPlayerModerations,
|
||||
expirePlayerModerations,
|
||||
deleteExpiredPlayerModerations,
|
||||
applyPlayerModeration,
|
||||
handlePlayerModerationDelete,
|
||||
getUserModerations
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// @deprecated
|
||||
// This store is no longer maintained.
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { toast } from 'vue-sonner';
|
||||
|
||||
@@ -4,6 +4,8 @@ import { watch } from 'vue';
|
||||
import { database } from '../service/database';
|
||||
import { groupRequest } from '../api';
|
||||
import { runRefreshFriendsListFlow } from '../coordinators/friendSyncCoordinator';
|
||||
import { runUpdateIsGameRunningFlow } from '../coordinators/gameCoordinator';
|
||||
import { runRefreshPlayerModerationsFlow } from '../coordinators/moderationCoordinator';
|
||||
import { useAuthStore } from './auth';
|
||||
import { useDiscordPresenceSettingsStore } from './settings/discordPresence';
|
||||
import { useFriendStore } from './friend';
|
||||
@@ -82,7 +84,7 @@ export const useUpdateLoopStore = defineStore('UpdateLoop', () => {
|
||||
new Date(userStore.currentUser.last_activity) >
|
||||
new Date(Date.now() - 3600 * 1000) // 1hour
|
||||
) {
|
||||
moderationStore.refreshPlayerModerations();
|
||||
runRefreshPlayerModerationsFlow();
|
||||
}
|
||||
}
|
||||
if (--state.nextGroupInstanceRefresh <= 0) {
|
||||
@@ -133,7 +135,7 @@ export const useUpdateLoopStore = defineStore('UpdateLoop', () => {
|
||||
}
|
||||
if (LINUX && --state.nextGameRunningCheck <= 0) {
|
||||
state.nextGameRunningCheck = 1;
|
||||
gameStore.updateIsGameRunning(
|
||||
await runUpdateIsGameRunningFlow(
|
||||
await AppApi.IsGameRunning(),
|
||||
await AppApi.IsSteamVRRunning()
|
||||
);
|
||||
|
||||
+5
-3
@@ -41,7 +41,9 @@ import { AppDebug } from '../service/appConfig';
|
||||
import { database } from '../service/database';
|
||||
import { patchUserFromEvent } from '../queries';
|
||||
import { runHandleUserUpdateFlow } from '../coordinators/userEventCoordinator';
|
||||
import { runUpdateCurrentUserLocationFlow } from '../coordinators/locationCoordinator';
|
||||
import { runUpdateFriendFlow } from '../coordinators/friendPresenceCoordinator';
|
||||
import { applyFavorite } from '../coordinators/favoriteCoordinator';
|
||||
import { useAppearanceSettingsStore } from './settings/appearance';
|
||||
import { useAuthStore } from './auth';
|
||||
import { useAvatarStore } from './avatar';
|
||||
@@ -424,7 +426,7 @@ export const useUserStore = defineStore('User', () => {
|
||||
} else {
|
||||
ref.$travelingToLocation = presence.travelingToWorld;
|
||||
}
|
||||
locationStore.updateCurrentUserLocation();
|
||||
runUpdateCurrentUserLocationFlow();
|
||||
}
|
||||
|
||||
const robotUrl = `${AppDebug.endpointDomain}/file/file_0e8c4e32-7444-44ea-ade4-313c010d4bae/1/file`;
|
||||
@@ -546,7 +548,7 @@ export const useUserStore = defineStore('User', () => {
|
||||
if (ref.status) {
|
||||
currentUser.value.status = ref.status;
|
||||
}
|
||||
locationStore.updateCurrentUserLocation();
|
||||
runUpdateCurrentUserLocationFlow();
|
||||
}
|
||||
// add user ref to playerList, friendList, photonLobby, photonLobbyCurrent
|
||||
const playerListRef = locationStore.lastLocation.playerList.get(ref.id);
|
||||
@@ -586,7 +588,7 @@ export const useUserStore = defineStore('User', () => {
|
||||
if (ref.state === 'online') {
|
||||
runUpdateFriendFlow(ref.id, ref.state); // online/offline
|
||||
}
|
||||
favoriteStore.applyFavorite('friend', ref.id);
|
||||
applyFavorite('friend', ref.id);
|
||||
friendStore.userOnFriend(ref);
|
||||
const D = userDialog.value;
|
||||
if (D.visible && D.id === ref.id) {
|
||||
|
||||
+1
-1
@@ -181,7 +181,7 @@ export const useVrStore = defineStore('Vr', () => {
|
||||
newState.overlayHand
|
||||
);
|
||||
if (!newState.active) {
|
||||
gameStore.updateIsHmdAfk(false);
|
||||
gameStore.setIsHmdAfk(false);
|
||||
}
|
||||
|
||||
if (LINUX) {
|
||||
|
||||
+6
-2
@@ -22,6 +22,10 @@ import { refreshCustomScript } from '../shared/utils/base/ui';
|
||||
import { useAdvancedSettingsStore } from './settings/advanced';
|
||||
import { useAvatarProviderStore } from './avatarProvider';
|
||||
import { useAvatarStore } from './avatar';
|
||||
import {
|
||||
addLocalWorldFavorite,
|
||||
addLocalAvatarFavorite
|
||||
} from '../coordinators/favoriteCoordinator';
|
||||
import { useFavoriteStore } from './favorite';
|
||||
import { useFriendStore } from './friend';
|
||||
import { useGalleryStore } from './gallery';
|
||||
@@ -686,7 +690,7 @@ export const useVrcxStore = defineStore('Vrcx', () => {
|
||||
}
|
||||
queryRequest.fetch('world', { worldId: id }).then(() => {
|
||||
searchStore.directAccessWorld(id);
|
||||
favoriteStore.addLocalWorldFavorite(id, group);
|
||||
addLocalWorldFavorite(id, group);
|
||||
});
|
||||
break;
|
||||
case 'local-favorite-avatar':
|
||||
@@ -698,7 +702,7 @@ export const useVrcxStore = defineStore('Vrcx', () => {
|
||||
}
|
||||
avatarRequest.getAvatar({ avatarId: avatarIdFav }).then(() => {
|
||||
avatarStore.showAvatarDialog(avatarIdFav);
|
||||
favoriteStore.addLocalAvatarFavorite(
|
||||
addLocalAvatarFavorite(
|
||||
avatarIdFav,
|
||||
avatarGroup
|
||||
);
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ import { instanceRequest, queryRequest, worldRequest } from '../api';
|
||||
import { database } from '../service/database';
|
||||
import { patchWorldFromEvent } from '../queries';
|
||||
import { processBulk } from '../service/request';
|
||||
import { applyFavorite } from '../coordinators/favoriteCoordinator';
|
||||
import { useFavoriteStore } from './favorite';
|
||||
import { useInstanceStore } from './instance';
|
||||
import { useLocationStore } from './location';
|
||||
@@ -275,7 +276,7 @@ export const useWorldStore = defineStore('World', () => {
|
||||
Object.assign(ref, json);
|
||||
}
|
||||
ref.$isLabs = ref.tags.includes('system_labs');
|
||||
favoriteStore.applyFavorite('world', ref.id);
|
||||
applyFavorite('world', ref.id);
|
||||
const userDialog = userStore.userDialog;
|
||||
if (userDialog.visible && userDialog.$location.worldId === ref.id) {
|
||||
userStore.applyUserDialogLocation();
|
||||
|
||||
Reference in New Issue
Block a user