user types

This commit is contained in:
Natsumi
2025-07-15 09:46:07 +12:00
parent 6fb2ad158e
commit fcfb9c6193
4 changed files with 154 additions and 40 deletions

View File

@@ -23,17 +23,16 @@ const userReq = {
} }
const args = { const args = {
json, json,
params params,
ref: userStore.applyUser(json)
}; };
args.ref = userStore.applyUser(json);
return args; return args;
}); });
}, },
/** /**
* Fetch user from cache if they're in it. Otherwise, calls API. * Fetch user from cache if they're in it. Otherwise, calls API.
* @param {{ userId: string }} params identifier of registered user * @type {import('../types/user').getUser}
* @returns {Promise<{json: any, params}>}
*/ */
getCachedUser(params) { getCachedUser(params) {
const userStore = useUserStore(); const userStore = useUserStore();
@@ -150,8 +149,7 @@ const userReq = {
/** /**
* Updates current user's status. * Updates current user's status.
* @param params {SaveCurrentUserParameters} new status to be set * @type {import('../types/user').getCurrentUser}
* @returns {Promise<{json: any, params}>}
*/ */
saveCurrentUser(params) { saveCurrentUser(params) {
const userStore = useUserStore(); const userStore = useUserStore();
@@ -161,9 +159,9 @@ const userReq = {
}).then((json) => { }).then((json) => {
const args = { const args = {
json, json,
params params,
ref: userStore.applyCurrentUser(json)
}; };
userStore.applyCurrentUser(json);
return args; return args;
}); });
}, },

View File

@@ -422,7 +422,7 @@ export const useInstanceStore = defineStore('Instance', () => {
/** /**
* *
* @param {string} worldId * @param {string} worldId
* @param {string} options * @param {any} options
* @returns {Promise<{json: *, params}|null>} * @returns {Promise<{json: *, params}|null>}
*/ */
async function createNewInstance(worldId = '', options) { async function createNewInstance(worldId = '', options) {
@@ -1000,8 +1000,8 @@ export const useInstanceStore = defineStore('Instance', () => {
/** /**
* *
* @param {string} instanceId * @param {string} instanceId
* @param {string} position * @param {number} position
* @param {string} queueSize * @param {number} queueSize
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async function instanceQueueUpdate(instanceId, position, queueSize) { async function instanceQueueUpdate(instanceId, position, queueSize) {

View File

@@ -118,6 +118,7 @@ export const useUserStore = defineStore('User', () => {
presence: { presence: {
avatarThumbnail: '', avatarThumbnail: '',
currentAvatarTags: '', currentAvatarTags: '',
debugflag: '',
displayName: '', displayName: '',
groups: [], groups: [],
id: '', id: '',
@@ -132,6 +133,7 @@ export const useUserStore = defineStore('User', () => {
world: '' world: ''
}, },
profilePicOverride: '', profilePicOverride: '',
profilePicOverrideThumbnail: '',
pronouns: '', pronouns: '',
queuedInstance: '', queuedInstance: '',
state: '', state: '',
@@ -153,10 +155,10 @@ export const useUserStore = defineStore('User', () => {
viveId: '', viveId: '',
// VRCX // VRCX
$online_for: Date.now(), $online_for: Date.now(),
$offline_for: '', $offline_for: null,
$location_at: Date.now(), $location_at: Date.now(),
$travelingToTime: Date.now(), $travelingToTime: Date.now(),
$previousAvatarSwapTime: '', $previousAvatarSwapTime: null,
$homeLocation: {}, $homeLocation: {},
$isVRCPlus: false, $isVRCPlus: false,
$isModerator: false, $isModerator: false,
@@ -434,8 +436,8 @@ export const useUserStore = defineStore('User', () => {
const robotUrl = `${AppGlobal.endpointDomain}/file/file_0e8c4e32-7444-44ea-ade4-313c010d4bae/1/file`; const robotUrl = `${AppGlobal.endpointDomain}/file/file_0e8c4e32-7444-44ea-ade4-313c010d4bae/1/file`;
/** /**
* *
* @param json * @param {import('../types/user').getUserResponse} json
* @returns {any} * @returns {import('../types/user').vrcxUser}
*/ */
function applyUser(json) { function applyUser(json) {
let hasPropChanged = false; let hasPropChanged = false;
@@ -500,7 +502,7 @@ export const useUserStore = defineStore('User', () => {
$location_at: Date.now(), $location_at: Date.now(),
$online_for: Date.now(), $online_for: Date.now(),
$travelingToTime: Date.now(), $travelingToTime: Date.now(),
$offline_for: '', $offline_for: null,
$active_for: Date.now(), $active_for: Date.now(),
$isVRCPlus: false, $isVRCPlus: false,
$isModerator: false, $isModerator: false,
@@ -550,7 +552,7 @@ export const useUserStore = defineStore('User', () => {
} }
state.cachedUsers.set(ref.id, ref); state.cachedUsers.set(ref.id, ref);
} else { } else {
json.$lastFetch = Date.now(); json.$lastFetch = Date.now(); // todo: make this not suck
if (json.state !== 'online') { if (json.state !== 'online') {
// offline event before GPS to offline location // offline event before GPS to offline location
friendStore.updateFriend(ref.id, json.state); friendStore.updateFriend(ref.id, json.state);
@@ -1021,7 +1023,6 @@ export const useUserStore = defineStore('User', () => {
}) })
.then((args) => { .then((args) => {
Vue.set(L, 'user', args.ref); Vue.set(L, 'user', args.ref);
return args;
}); });
} else { } else {
L.user = ref; L.user = ref;
@@ -1234,7 +1235,6 @@ export const useUserStore = defineStore('User', () => {
} }
/** /**
*
* @param {object} ref * @param {object} ref
* @param {object} props * @param {object} props
* @returns {Promise<void>} * @returns {Promise<void>}
@@ -1739,6 +1739,10 @@ export const useUserStore = defineStore('User', () => {
}); });
} }
/**
* @param {import('../types/user').getCurrentUserResponse} json
* @returns {import('../types/user').getCurrentUserResponse}
*/
function applyCurrentUser(json) { function applyCurrentUser(json) {
authStore.attemptingAutoLogin = false; authStore.attemptingAutoLogin = false;
let ref = state.currentUser; let ref = state.currentUser;
@@ -1801,6 +1805,7 @@ export const useUserStore = defineStore('User', () => {
presence: { presence: {
avatarThumbnail: '', avatarThumbnail: '',
currentAvatarTags: '', currentAvatarTags: '',
debugflag: '',
displayName: '', displayName: '',
groups: [], groups: [],
id: '', id: '',
@@ -1816,6 +1821,7 @@ export const useUserStore = defineStore('User', () => {
...json.presence ...json.presence
}, },
profilePicOverride: '', profilePicOverride: '',
profilePicOverrideThumbnail: '',
pronouns: '', pronouns: '',
queuedInstance: '', queuedInstance: '',
state: '', state: '',
@@ -1837,10 +1843,10 @@ export const useUserStore = defineStore('User', () => {
viveId: '', viveId: '',
// VRCX // VRCX
$online_for: Date.now(), $online_for: Date.now(),
$offline_for: '', $offline_for: null,
$location_at: Date.now(), $location_at: Date.now(),
$travelingToTime: Date.now(), $travelingToTime: Date.now(),
$previousAvatarSwapTime: '', $previousAvatarSwapTime: null,
$homeLocation: {}, $homeLocation: {},
$isVRCPlus: false, $isVRCPlus: false,
$isModerator: false, $isModerator: false,
@@ -1913,7 +1919,9 @@ export const useUserStore = defineStore('User', () => {
travelingToInstance = json.presence.travelingToInstance; travelingToInstance = json.presence.travelingToInstance;
travelingToWorld = json.presence.travelingToWorld; travelingToWorld = json.presence.travelingToWorld;
} }
applyUser({ const userRef = applyUser({
ageVerificationStatus: json.ageVerificationStatus,
ageVerified: json.ageVerified,
allowAvatarCopying: json.allowAvatarCopying, allowAvatarCopying: json.allowAvatarCopying,
badges: json.badges, badges: json.badges,
bio: json.bio, bio: json.bio,
@@ -1934,10 +1942,10 @@ export const useUserStore = defineStore('User', () => {
last_mobile: json.last_mobile, last_mobile: json.last_mobile,
last_platform: json.last_platform, last_platform: json.last_platform,
// location - missing from currentUser // location - missing from currentUser
// platform - missing from currentUser
// note - missing from currentUser // note - missing from currentUser
platform: json.presence.platform,
profilePicOverride: json.profilePicOverride, profilePicOverride: json.profilePicOverride,
// profilePicOverrideThumbnail - missing from currentUser profilePicOverrideThumbnail: json.profilePicOverrideThumbnail,
pronouns: json.pronouns, pronouns: json.pronouns,
state: json.state, state: json.state,
status: json.status, status: json.status,
@@ -1948,7 +1956,7 @@ export const useUserStore = defineStore('User', () => {
// travelingToWorld - missing from currentUser // travelingToWorld - missing from currentUser
userIcon: json.userIcon, userIcon: json.userIcon,
// worldId - missing from currentUser // worldId - missing from currentUser
fallbackAvatar: json.fallbackAvatar, // fallbackAvatar - gone from user
// Location from gameLog/presence // Location from gameLog/presence
location, location,
@@ -1956,14 +1964,20 @@ export const useUserStore = defineStore('User', () => {
worldId, worldId,
travelingToLocation, travelingToLocation,
travelingToInstance, travelingToInstance,
travelingToWorld, travelingToWorld
// set VRCX online/offline timers // $online_for: state.currentUser.$online_for,
$online_for: state.currentUser.$online_for, // $offline_for: state.currentUser.$offline_for,
$offline_for: state.currentUser.$offline_for, // $location_at: state.currentUser.$location_at,
$location_at: state.currentUser.$location_at, // $travelingToTime: state.currentUser.$travelingToTime
$travelingToTime: state.currentUser.$travelingToTime
}); });
// set VRCX online/offline timers
userRef.$online_for = state.currentUser.$online_for;
userRef.$offline_for = state.currentUser.$offline_for;
userRef.$location_at = state.currentUser.$location_at;
userRef.$travelingToTime = state.currentUser.$travelingToTime;
return ref;
} }
return { return {

120
src/types/user.d.ts vendored
View File

@@ -1,8 +1,37 @@
export type getUser = (params: { userId: string }) => Promise<{ export type getUser = (params: { userId: string }) => Promise<{
cache?: boolean;
json: getUserResponse; json: getUserResponse;
ref: vrcxUser;
params: { userId: string }; params: { userId: string };
}>; }>;
export interface vrcxUser extends getUserResponse {
$location: {};
$location_at: number;
$online_for: number;
$travelingToTime: number;
$offline_for: number;
$active_for: number;
$isVRCPlus: boolean;
$isModerator: boolean;
$isTroll: boolean;
$isProbableTroll: boolean;
$trustLevel: string;
$trustClass: string;
$userColour: string;
$trustSortNum: number;
$languages: string[];
$joinCount: number;
$timeSpent: number;
$lastSeen: string;
$nickName: string;
$previousLocation: string;
$customTag: string;
$customTagColour: string;
$friendNumber: number;
$lastFetch: number;
}
interface getUserResponse { interface getUserResponse {
ageVerificationStatus: string; ageVerificationStatus: string;
ageVerified: boolean; ageVerified: boolean;
@@ -23,17 +52,17 @@ interface getUserResponse {
developerType: string; developerType: string;
displayName: string; displayName: string;
friendKey: string; friendKey: string;
friendRequestStatus: string; friendRequestStatus?: string;
id: string; id: string;
instanceId: string; instanceId?: string;
isFriend: boolean; isFriend: boolean;
last_activity: string; last_activity: string;
last_login: string; last_login: string;
last_mobile: string | null; last_mobile: string | null;
last_platform: string; last_platform: string;
location: string; location?: string;
note: string; note?: string;
platform: string; platform?: string;
profilePicOverride: string; profilePicOverride: string;
profilePicOverrideThumbnail: string; profilePicOverrideThumbnail: string;
pronouns: string; pronouns: string;
@@ -41,9 +70,82 @@ interface getUserResponse {
status: string; status: string;
statusDescription: string; statusDescription: string;
tags: string[]; tags: string[];
travelingToInstance: string; travelingToInstance?: string;
travelingToLocation: string; travelingToLocation?: string;
travelingToWorld: string; travelingToWorld?: string;
userIcon: string; userIcon: string;
worldId: string; worldId?: string;
}
export type getCurrentUser = (any) => Promise<{
json: getCurrentUserResponse;
ref: vrcxCurrentUser;
params: getCurrentUserResponse;
}>;
export interface vrcxCurrentUser extends getCurrentUserResponse {
$online_for?: number;
$offline_for?: number | null;
$location_at?: number;
$travelingToTime?: number;
$previousAvatarSwapTime?: number | null;
$homeLocation?: {};
$isVRCPlus?: boolean;
$isModerator?: boolean;
$isTroll?: boolean;
$isProbableTroll?: boolean;
$trustLevel?: string;
$trustClass?: string;
$userColour?: string;
$trustSortNum?: number;
$languages?: string[];
$locationTag?: string;
$travelingToLocation?: string;
}
interface getCurrentUserResponse extends getUserResponse {
acceptedPrivacyVersion: number;
acceptedTOSVersion: number;
accountDeletionDate: string | null;
accountDeletionLog: string | null;
activeFriends: string[];
currentAvatar: string;
emailVerified: boolean;
fallbackAvatar: string;
friendGroupNames: string[];
friends: string[];
googleId: string;
hasBirthday: boolean;
hasEmail: boolean;
hasLoggedInFromClient: boolean;
hasPendingEmail: boolean;
hideContentFilterSettings: boolean;
homeLocation: string;
isAdult: boolean;
isBoopingEnabled: boolean;
obfuscatedEmail: string;
obfuscatedPendingEmail: string;
oculusId: string;
offlineFriends: string[];
onlineFriends: string[];
pastDisplayNames: { displayName: string; dateChanged: string }[];
picoId: string;
presence?: {
avatarThumbnail: string;
currentAvatarTags: string;
debugflag: string;
displayName: string;
groups: string[];
id: string;
instance: string;
instanceType: string;
platform: string;
profilePicOverride: string;
status: string;
travelingToInstance: string;
travelingToWorld: string;
userIcon: string;
world: string;
};
queuedInstance: string | null;
} }