diff --git a/src/components/dialogs/UserDialog/UserDialog.vue b/src/components/dialogs/UserDialog/UserDialog.vue index 6b1844ed..1a3fefbf 100644 --- a/src/components/dialogs/UserDialog/UserDialog.vue +++ b/src/components/dialogs/UserDialog/UserDialog.vue @@ -1896,7 +1896,7 @@ const { isGameRunning } = storeToRefs(useGameStore()); const { logout } = useAuthStore(); const { cachedConfig } = storeToRefs(useAuthStore()); - const { handlePlayerModerationAtSend, handlePlayerModeration, handlePlayerModerationDelete } = useModerationStore(); + const { applyPlayerModeration, handlePlayerModerationDelete } = useModerationStore(); const { shiftHeld } = storeToRefs(useUiStore()); watch( @@ -2386,14 +2386,26 @@ } function handleSendPlayerModeration(args) { - const ref = { - json: args.json, - params: { - playerModerationId: args.json.id - } - }; - handlePlayerModeration(); - handlePlayerModerationAtSend(ref); + const ref = applyPlayerModeration(args.json); + const D = userDialog.value; + if (D.visible === false || (ref.targetUserId !== D.id && ref.sourceUserId !== currentUser.value.id)) { + return; + } + if (ref.type === 'block') { + D.isBlock = true; + } else if (ref.type === 'mute') { + D.isMute = true; + } else if (ref.type === 'hideAvatar') { + D.isHideAvatar = true; + } else if (ref.type === 'interactOff') { + D.isInteractOff = true; + } else if (ref.type === 'muteChat') { + D.isMuteChat = true; + } + $message({ + message: t('message.user.moderated'), + type: 'success' + }); } async function performUserDialogCommand(command, userId) { @@ -2446,10 +2458,11 @@ break; } case 'Moderation Unblock': - playerModerationRequest.deletePlayerModeration({ + args = await playerModerationRequest.deletePlayerModeration({ moderated: userId, type: 'block' }); + handlePlayerModerationDelete(args); break; case 'Moderation Block': { args = await playerModerationRequest.sendPlayerModeration({ diff --git a/src/stores/moderation.js b/src/stores/moderation.js index 51844e1b..8c4fa6e7 100644 --- a/src/stores/moderation.js +++ b/src/stores/moderation.js @@ -64,51 +64,6 @@ export const useModerationStore = defineStore('Moderation', () => { { flush: 'sync' } ); - function handlePlayerModeration(args) { - args.ref = applyPlayerModeration(args.json); - const { ref } = args; - const array = state.playerModerationTable.data; - const { length } = array; - for (let i = 0; i < length; ++i) { - if (array[i].id === ref.id) { - Vue.set(array, i, ref); - return; - } - } - state.playerModerationTable.data.push(ref); - } - - /** - * - * @param args - */ - function handlePlayerModerationAtSend(args) { - const { ref } = args; - const D = userStore.userDialog; - if ( - D.visible === false || - (ref.targetUserId !== D.id && - ref.sourceUserId !== userStore.currentUser.id) - ) { - return; - } - if (ref.type === 'block') { - D.isBlock = true; - } else if (ref.type === 'mute') { - D.isMute = true; - } else if (ref.type === 'hideAvatar') { - D.isHideAvatar = true; - } else if (ref.type === 'interactOff') { - D.isInteractOff = true; - } else if (ref.type === 'muteChat') { - D.isMuteChat = true; - } - $app.$message({ - message: t('message.user.moderated'), - type: 'success' - }); - } - function handlePlayerModerationAtDelete(args) { const { ref } = args; const D = userStore.userDialog; @@ -191,6 +146,13 @@ export const useModerationStore = defineStore('Moderation', () => { if (json.targetUserId) { state.cachedPlayerModerationsUserIds.add(json.targetUserId); } + const array = state.playerModerationTable.data; + const index = array.findIndex((item) => item.id === ref.id); + if (index !== -1) { + array[index] = ref; + } else { + array.push(ref); + } return ref; } @@ -238,18 +200,16 @@ export const useModerationStore = defineStore('Moderation', () => { } if (res[0]?.json) { for (let json of res[0].json) { - handlePlayerModeration({ - json, - params: { - playerModerationId: json.id - } - }); + applyPlayerModeration(json); } } deleteExpiredPlayerModerations(); }) .catch((error) => { - console.error('Failed to load player/avatar moderations:', error); + console.error( + 'Failed to load player/avatar moderations:', + error + ); }); } @@ -261,8 +221,7 @@ export const useModerationStore = defineStore('Moderation', () => { playerModerationTable, refreshPlayerModerations, - handlePlayerModerationAtSend, - handlePlayerModeration, + applyPlayerModeration, handlePlayerModerationDelete }; }); diff --git a/src/stores/user.js b/src/stores/user.js index fe0b7e5c..26cc0ced 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -1000,7 +1000,7 @@ export const useUserStore = defineStore('User', () => { if (!D.visible) { return; } - const L = parseLocation(D.ref.$location.tag); + const L = parseLocation(D.ref.$location?.tag); if (updateInstanceOccupants && L.isRealInstance) { instanceRequest.getInstance({ worldId: L.worldId,