mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 06:43:51 +02:00
refactor findUserByDisplayName
This commit is contained in:
@@ -88,7 +88,8 @@ export async function tryLoadPlayerList() {
|
||||
ctx.userId =
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
ctx.displayName
|
||||
ctx.displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
const userMap = {
|
||||
@@ -159,8 +160,11 @@ export function addGameLogEntry(gameLog, location) {
|
||||
let userId = String(gameLog.userId || '');
|
||||
if (!userId && gameLog.displayName) {
|
||||
userId =
|
||||
findUserByDisplayName(userStore.cachedUsers, gameLog.displayName)
|
||||
?.id ?? '';
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
gameLog.displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
switch (gameLog.type) {
|
||||
case 'location-destination':
|
||||
@@ -408,7 +412,8 @@ export function addGameLogEntry(gameLog, location) {
|
||||
if (typeof ref2 === 'undefined') {
|
||||
const foundUser = findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
gameLog.displayName
|
||||
gameLog.displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
);
|
||||
if (foundUser) {
|
||||
photonStore.photonLobby.set(photonId, foundUser);
|
||||
|
||||
@@ -80,11 +80,14 @@ export function applyUser(json) {
|
||||
cachedUsers,
|
||||
currentTravelers,
|
||||
customUserTags,
|
||||
rebuildCachedUserDisplayNameIndex,
|
||||
setCachedUser,
|
||||
state,
|
||||
userDialog
|
||||
} = userStore;
|
||||
|
||||
let ref = cachedUsers.get(json.id);
|
||||
let previousDisplayName = '';
|
||||
let hasPropChanged = false;
|
||||
let changedProps = {};
|
||||
sanitizeUserJson(json, getRobotUrl());
|
||||
@@ -111,18 +114,24 @@ export function applyUser(json) {
|
||||
ref.$customTag = '';
|
||||
ref.$customTagColour = '';
|
||||
}
|
||||
evictMapCache(
|
||||
const { deletedCount } = evictMapCache(
|
||||
cachedUsers,
|
||||
friendStore.friends.size + 300,
|
||||
(_value, key) => friendStore.friends.has(key),
|
||||
{ logLabel: 'User cache cleanup' }
|
||||
);
|
||||
cachedUsers.set(ref.id, ref);
|
||||
if (deletedCount > 0) {
|
||||
setCachedUser(ref, '', { skipIndex: true });
|
||||
rebuildCachedUserDisplayNameIndex();
|
||||
} else {
|
||||
setCachedUser(ref);
|
||||
}
|
||||
runUpdateFriendFlow(ref.id);
|
||||
} else {
|
||||
if (json.state !== 'online') {
|
||||
runUpdateFriendFlow(ref.id, json.state);
|
||||
}
|
||||
previousDisplayName = ref.displayName;
|
||||
const { hasPropChanged: _hasPropChanged, changedProps: _changedProps } =
|
||||
diffObjectProps(ref, json, arraysMatch);
|
||||
for (const prop in json) {
|
||||
@@ -130,6 +139,7 @@ export function applyUser(json) {
|
||||
ref[prop] = json[prop];
|
||||
}
|
||||
}
|
||||
setCachedUser(ref, previousDisplayName);
|
||||
hasPropChanged = _hasPropChanged;
|
||||
changedProps = _changedProps;
|
||||
}
|
||||
@@ -637,7 +647,11 @@ export async function lookupUser(ref) {
|
||||
if (!ref.displayName || ref.displayName.substring(0, 3) === 'ID:') {
|
||||
return;
|
||||
}
|
||||
const found = findUserByDisplayName(userStore.cachedUsers, ref.displayName);
|
||||
const found = findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
ref.displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
);
|
||||
if (found) {
|
||||
showUserDialog(found.id);
|
||||
return;
|
||||
|
||||
@@ -51,7 +51,7 @@ export function runFirstLoginFlow(ref, { now = Date.now } = {}) {
|
||||
if (gameStore.isGameRunning) {
|
||||
ref.$previousAvatarSwapTime = now();
|
||||
}
|
||||
userStore.cachedUsers.clear(); // clear before running applyUser
|
||||
userStore.clearCachedUsers(); // clear before running applyUser
|
||||
userStore.setCurrentUser(ref);
|
||||
authStore.loginComplete();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export function clearVRCXCache() {
|
||||
!locationStore.lastLocation.playerList.has(ref.id) &&
|
||||
id !== userStore.currentUser.id
|
||||
) {
|
||||
userStore.cachedUsers.delete(id);
|
||||
userStore.deleteCachedUser(id);
|
||||
}
|
||||
});
|
||||
worldStore.cachedWorlds.forEach((ref, id) => {
|
||||
|
||||
Reference in New Issue
Block a user