mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-04 22:06:06 +02:00
refactor findUserByDisplayName
This commit is contained in:
@@ -193,7 +193,8 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
||||
ctx.userId =
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
ctx.displayName
|
||||
ctx.displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
notificationStore.queueGameLogNoty(ctx);
|
||||
|
||||
@@ -139,8 +139,11 @@ export function createMediaParsers({
|
||||
let userId = '';
|
||||
if (displayName) {
|
||||
userId =
|
||||
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
|
||||
'';
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
if (videoId === 'YouTube') {
|
||||
const entry1 = {
|
||||
@@ -207,8 +210,11 @@ export function createMediaParsers({
|
||||
let userId = '';
|
||||
if (displayName) {
|
||||
userId =
|
||||
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
|
||||
'';
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
if (videoId === 'YouTube') {
|
||||
const entry1 = {
|
||||
@@ -270,8 +276,11 @@ export function createMediaParsers({
|
||||
let userId = '';
|
||||
if (displayName) {
|
||||
userId =
|
||||
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
|
||||
'';
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
if (videoId === 'YouTube') {
|
||||
const entry1 = {
|
||||
@@ -327,8 +336,11 @@ export function createMediaParsers({
|
||||
let userId = '';
|
||||
if (displayName) {
|
||||
userId =
|
||||
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
|
||||
'';
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
const entry1 = {
|
||||
created_at: gameLog.dt,
|
||||
@@ -384,8 +396,11 @@ export function createMediaParsers({
|
||||
let userId = '';
|
||||
if (displayName) {
|
||||
userId =
|
||||
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
|
||||
'';
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? '';
|
||||
}
|
||||
const entry1 = {
|
||||
created_at: gameLog.dt,
|
||||
|
||||
@@ -1018,8 +1018,11 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
if (id) return id;
|
||||
if (noty.displayName) {
|
||||
return (
|
||||
findUserByDisplayName(userStore.cachedUsers, noty.displayName)
|
||||
?.id ?? ''
|
||||
findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
noty.displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
)?.id ?? ''
|
||||
);
|
||||
}
|
||||
return '';
|
||||
@@ -1086,7 +1089,8 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
} else if (noty.displayName) {
|
||||
const ref = findUserByDisplayName(
|
||||
userStore.cachedUsers,
|
||||
noty.displayName
|
||||
noty.displayName,
|
||||
userStore.cachedUserIdsByDisplayName
|
||||
);
|
||||
if (ref) {
|
||||
noty.isFriend = friendStore.friends.has(ref.id);
|
||||
|
||||
@@ -271,6 +271,78 @@ export const useUserStore = defineStore('User', () => {
|
||||
});
|
||||
|
||||
const cachedUsers = shallowReactive(new Map());
|
||||
const cachedUserIdsByDisplayName = shallowReactive(new Map());
|
||||
|
||||
function addCachedUserDisplayNameEntry(displayName, userId) {
|
||||
if (!displayName || !userId) {
|
||||
return;
|
||||
}
|
||||
let userIds = cachedUserIdsByDisplayName.get(displayName);
|
||||
if (!userIds) {
|
||||
userIds = new Set();
|
||||
cachedUserIdsByDisplayName.set(displayName, userIds);
|
||||
}
|
||||
userIds.add(userId);
|
||||
}
|
||||
|
||||
function removeCachedUserDisplayNameEntry(displayName, userId) {
|
||||
if (!displayName || !userId) {
|
||||
return;
|
||||
}
|
||||
const userIds = cachedUserIdsByDisplayName.get(displayName);
|
||||
if (!userIds) {
|
||||
return;
|
||||
}
|
||||
userIds.delete(userId);
|
||||
if (userIds.size === 0) {
|
||||
cachedUserIdsByDisplayName.delete(displayName);
|
||||
}
|
||||
}
|
||||
|
||||
function syncCachedUserDisplayName(ref, previousDisplayName = '') {
|
||||
if (!ref?.id) {
|
||||
return;
|
||||
}
|
||||
if (previousDisplayName && previousDisplayName !== ref.displayName) {
|
||||
removeCachedUserDisplayNameEntry(previousDisplayName, ref.id);
|
||||
}
|
||||
addCachedUserDisplayNameEntry(ref.displayName, ref.id);
|
||||
}
|
||||
|
||||
function setCachedUser(
|
||||
ref,
|
||||
previousDisplayName = '',
|
||||
{ skipIndex = false } = {}
|
||||
) {
|
||||
if (!ref?.id) {
|
||||
return;
|
||||
}
|
||||
cachedUsers.set(ref.id, ref);
|
||||
if (!skipIndex) {
|
||||
syncCachedUserDisplayName(ref, previousDisplayName);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteCachedUser(userId) {
|
||||
const ref = cachedUsers.get(userId);
|
||||
if (!ref) {
|
||||
return false;
|
||||
}
|
||||
removeCachedUserDisplayNameEntry(ref.displayName, userId);
|
||||
return cachedUsers.delete(userId);
|
||||
}
|
||||
|
||||
function clearCachedUsers() {
|
||||
cachedUsers.clear();
|
||||
cachedUserIdsByDisplayName.clear();
|
||||
}
|
||||
|
||||
function rebuildCachedUserDisplayNameIndex() {
|
||||
cachedUserIdsByDisplayName.clear();
|
||||
for (const ref of cachedUsers.values()) {
|
||||
addCachedUserDisplayNameEntry(ref.displayName, ref.id);
|
||||
}
|
||||
}
|
||||
|
||||
const isLocalUserVrcPlusSupporter = computed(
|
||||
() => currentUser.value.$isVRCPlus || AppDebug.debugVrcPlus
|
||||
@@ -730,10 +802,16 @@ export const useUserStore = defineStore('User', () => {
|
||||
showUserDialogHistory,
|
||||
customUserTags,
|
||||
cachedUsers,
|
||||
cachedUserIdsByDisplayName,
|
||||
isLocalUserVrcPlusSupporter,
|
||||
applyUserLanguage,
|
||||
applyPresenceLocation,
|
||||
applyUserDialogLocation,
|
||||
setCachedUser,
|
||||
syncCachedUserDisplayName,
|
||||
deleteCachedUser,
|
||||
clearCachedUsers,
|
||||
rebuildCachedUserDisplayNameIndex,
|
||||
sortUserDialogAvatars,
|
||||
initUserNotes,
|
||||
showSendBoopDialog,
|
||||
|
||||
Reference in New Issue
Block a user