split some store func and add test

This commit is contained in:
pa
2026-03-04 20:21:17 +09:00
parent ea82825823
commit 1f1b996239
15 changed files with 1172 additions and 1307 deletions
+40 -120
View File
@@ -8,7 +8,9 @@ import dayjs from 'dayjs';
import {
convertYoutubeTime,
findUserByDisplayName,
formatSeconds,
gameLogSearchFilter,
getGroupName,
isRpcWorld,
parseLocation,
@@ -221,12 +223,11 @@ export const useGameLogStore = defineStore('GameLog', () => {
const ctx = structuredClone(data);
if (nowPlaying.value.url !== ctx.videoUrl) {
if (!ctx.userId && ctx.displayName) {
for (const ref of userStore.cachedUsers.values()) {
if (ref.displayName === ctx.displayName) {
ctx.userId = ref.id;
break;
}
}
ctx.userId =
findUserByDisplayName(
userStore.cachedUsers,
ctx.displayName
)?.id ?? '';
}
notificationStore.queueGameLogNoty(ctx);
addGameLog(ctx);
@@ -324,12 +325,11 @@ export const useGameLogStore = defineStore('GameLog', () => {
ctx = data[i];
if (ctx.type === 'OnPlayerJoined') {
if (!ctx.userId) {
for (let ref of userStore.cachedUsers.values()) {
if (ref.displayName === ctx.displayName) {
ctx.userId = ref.id;
break;
}
}
ctx.userId =
findUserByDisplayName(
userStore.cachedUsers,
ctx.displayName
)?.id ?? '';
}
const userMap = {
displayName: ctx.displayName,
@@ -484,72 +484,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
}
function gameLogSearch(row) {
const value = gameLogTable.value.search.trim().toUpperCase();
if (!value) {
return true;
}
if (
(value.startsWith('wrld_') || value.startsWith('grp_')) &&
String(row.location).toUpperCase().includes(value)
) {
return true;
}
switch (row.type) {
case 'Location':
if (String(row.worldName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'OnPlayerJoined':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'OnPlayerLeft':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'PortalSpawn':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.worldName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'Event':
if (String(row.data).toUpperCase().includes(value)) {
return true;
}
return false;
case 'External':
if (String(row.message).toUpperCase().includes(value)) {
return true;
}
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'VideoPlay':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.videoName).toUpperCase().includes(value)) {
return true;
}
if (String(row.videoUrl).toUpperCase().includes(value)) {
return true;
}
return false;
case 'StringLoad':
case 'ImageLoad':
if (String(row.resourceUrl).toUpperCase().includes(value)) {
return true;
}
return false;
}
return true;
return gameLogSearchFilter(row, gameLogTable.value.search);
}
function sweepGameLog() {
@@ -566,12 +501,11 @@ export const useGameLogStore = defineStore('GameLog', () => {
}
let userId = String(gameLog.userId || '');
if (!userId && gameLog.displayName) {
for (const ref of userStore.cachedUsers.values()) {
if (ref.displayName === gameLog.displayName) {
userId = ref.id;
break;
}
}
userId =
findUserByDisplayName(
userStore.cachedUsers,
gameLog.displayName
)?.id ?? '';
}
switch (gameLog.type) {
case 'location-destination':
@@ -890,12 +824,13 @@ export const useGameLogStore = defineStore('GameLog', () => {
const photonId = parseInt(gameLog.photonId, 10);
const ref2 = photonStore.photonLobby.get(photonId);
if (typeof ref2 === 'undefined') {
for (const ctx of userStore.cachedUsers.values()) {
if (ctx.displayName === gameLog.displayName) {
photonStore.photonLobby.set(photonId, ctx);
photonStore.photonLobbyCurrent.set(photonId, ctx);
break;
}
const foundUser = findUserByDisplayName(
userStore.cachedUsers,
gameLog.displayName
);
if (foundUser) {
photonStore.photonLobby.set(photonId, foundUser);
photonStore.photonLobbyCurrent.set(photonId, foundUser);
}
const ctx1 = {
displayName: gameLog.displayName
@@ -1101,12 +1036,9 @@ export const useGameLogStore = defineStore('GameLog', () => {
}
let userId = '';
if (displayName) {
for (const ref of userStore.cachedUsers.values()) {
if (ref.displayName === displayName) {
userId = ref.id;
break;
}
}
userId =
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
'';
}
if (videoId === 'YouTube') {
const entry1 = {
@@ -1172,12 +1104,9 @@ export const useGameLogStore = defineStore('GameLog', () => {
}
let userId = '';
if (displayName) {
for (let ref of userStore.cachedUsers.values()) {
if (ref.displayName === displayName) {
userId = ref.id;
break;
}
}
userId =
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
'';
}
if (videoId === 'YouTube') {
const entry1 = {
@@ -1238,12 +1167,9 @@ export const useGameLogStore = defineStore('GameLog', () => {
}
let userId = '';
if (displayName) {
for (const ref of userStore.cachedUsers.values()) {
if (ref.displayName === displayName) {
userId = ref.id;
break;
}
}
userId =
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
'';
}
if (videoId === 'YouTube') {
const entry1 = {
@@ -1298,12 +1224,9 @@ export const useGameLogStore = defineStore('GameLog', () => {
}
let userId = '';
if (displayName) {
for (const ref of userStore.cachedUsers.values()) {
if (ref.displayName === displayName) {
userId = ref.id;
break;
}
}
userId =
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
'';
}
const entry1 = {
created_at: gameLog.dt,
@@ -1358,12 +1281,9 @@ export const useGameLogStore = defineStore('GameLog', () => {
}
let userId = '';
if (displayName) {
for (const ref of userStore.cachedUsers.values()) {
if (ref.displayName === displayName) {
userId = ref.id;
break;
}
}
userId =
findUserByDisplayName(userStore.cachedUsers, displayName)?.id ??
'';
}
const entry1 = {
created_at: gameLog.dt,
+22 -57
View File
@@ -30,6 +30,7 @@ import {
instanceContentSettings
} from '../shared/constants';
import { database } from '../service/database';
import { resolveRef } from '../shared/resolveRef';
import { useAppearanceSettingsStore } from './settings/appearance';
import { useFriendStore } from './friend';
import { useGroupStore } from './group';
@@ -211,67 +212,31 @@ export const useInstanceStore = defineStore('Instance', () => {
previousInstancesListDialog.value.visible = false;
}
async function resolveUserRef(input) {
if (!input) {
return { id: '', displayName: '' };
}
if (typeof input === 'string') {
input = { id: input, displayName: '' };
}
const id = input.id || input.userId || '';
let displayName = input.displayName || '';
if (id && !displayName) {
try {
const args = await userRequest.getCachedUser({ userId: id });
displayName = args?.ref?.displayName || displayName;
return { ...args.ref, id, displayName };
} catch {
return { ...input, id, displayName };
}
}
return { ...input, id, displayName };
function resolveUserRef(input) {
return resolveRef(input, {
emptyDefault: { id: '', displayName: '' },
idAlias: 'userId',
nameKey: 'displayName',
fetchFn: (id) => userRequest.getCachedUser({ userId: id })
});
}
async function resolveWorldRef(input) {
if (!input) {
return { id: '', name: '' };
}
if (typeof input === 'string') {
input = { id: input, name: '' };
}
const id = input.id || input.worldId || '';
let name = input.name || '';
if (id && !name) {
try {
const args = await worldRequest.getCachedWorld({ worldId: id });
name = args?.ref?.name || name;
return { ...args.ref, id, name };
} catch {
return { ...input, id, name };
}
}
return { ...input, id, name };
function resolveWorldRef(input) {
return resolveRef(input, {
emptyDefault: { id: '', name: '' },
idAlias: 'worldId',
nameKey: 'name',
fetchFn: (id) => worldRequest.getCachedWorld({ worldId: id })
});
}
async function resolveGroupRef(input) {
if (!input) {
return { id: '', name: '' };
}
if (typeof input === 'string') {
input = { id: input, name: '' };
}
const id = input.id || input.groupId || '';
let name = input.name || '';
if (id && !name) {
try {
const args = await groupRequest.getCachedGroup({ groupId: id });
name = args?.ref?.name || name;
return { ...args.ref, id, name };
} catch {
return { ...input, id, name };
}
}
return { ...input, id, name };
function resolveGroupRef(input) {
return resolveRef(input, {
emptyDefault: { id: '', name: '' },
idAlias: 'groupId',
nameKey: 'name',
fetchFn: (id) => groupRequest.getCachedGroup({ groupId: id })
});
}
function translateAccessType(accessTypeNameRaw) {
+38 -1124
View File
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -13,6 +13,7 @@ import {
compareByName,
compareByUpdatedAt,
extractFileId,
findUserByDisplayName,
getAllUserMemos,
getGroupName,
getUserMemo,
@@ -1257,11 +1258,10 @@ export const useUserStore = defineStore('User', () => {
if (!ref.displayName || ref.displayName.substring(0, 3) === 'ID:') {
return;
}
for (ctx of cachedUsers.values()) {
if (ctx.displayName === ref.displayName) {
showUserDialog(ctx.id);
return;
}
const found = findUserByDisplayName(cachedUsers, ref.displayName);
if (found) {
showUserDialog(found.id);
return;
}
searchStore.searchText = ref.displayName;
await searchStore.searchUserByDisplayName(ref.displayName);