Moderations in playerList

This commit is contained in:
Natsumi
2025-08-21 05:07:06 +12:00
parent 7d06966fef
commit 887f59d2b4
9 changed files with 138 additions and 39 deletions
+28 -14
View File
@@ -440,6 +440,34 @@ export const useFriendStore = defineStore('Friend', () => {
if (typeof ref !== 'undefined') {
location = ref.location;
$location_at = ref.$location_at;
// wtf, fetch user if offline in an instance
if (
ctx.state !== 'online' &&
isRealInstance(ref.location) &&
ref.$lastFetch < Date.now() - 10000 // 10 seconds
) {
console.log(
`Fetching offline friend in an instance ${ctx.name}`
);
userRequest.getUser({
userId: id
});
}
// wtf, fetch user if online in an offline location
if (
ctx.state === 'online' &&
ref.location === 'offline' &&
ref.$lastFetch < Date.now() - 10000 // 10 seconds
) {
console.log(
`Fetching online friend in an offline location ${ctx.name}`
);
userRequest.getUser({
userId: id
});
return;
}
}
if (typeof stateInput === 'undefined' || ctx.state === stateInput) {
// this is should be: undefined -> user
@@ -489,20 +517,6 @@ export const useFriendStore = defineStore('Friend', () => {
state.sortOfflineFriends = true;
}
}
// wtf, fetch user if offline in an instance
if (
ctx.state !== 'online' &&
typeof ref !== 'undefined' &&
isRealInstance(ref.location) &&
ref.$lastFetch < Date.now() - 10000 // 10 seconds
) {
console.log(
`Fetching offline friend in an instance ${ctx.name}`
);
userRequest.getUser({
userId: id
});
}
} else if (
ctx.state === 'online' &&
(stateInput === 'active' || stateInput === 'offline')
+10 -1
View File
@@ -1080,8 +1080,12 @@ export const useInstanceStore = defineStore('Instance', () => {
function updatePlayerListDebounce() {
const users = [];
const pushUser = function (ref) {
let photonId = '';
let photonId = -1;
let isFriend = false;
let isBlocked = false;
let isMuted = false;
let isAvatarInteractionDisabled = false;
let isChatBoxMuted = false;
photonStore.photonLobbyCurrent.forEach((ref1, id) => {
if (typeof ref1 !== 'undefined') {
if (
@@ -1138,6 +1142,11 @@ export const useInstanceStore = defineStore('Instance', () => {
}
});
}
isBlocked = ref.$moderations.isBlocked;
isMuted = ref.$moderations.isMuted;
isAvatarInteractionDisabled =
ref.$moderations.isAvatarInteractionDisabled;
isChatBoxMuted = ref.$moderations.isChatBoxMuted;
}
users.push({
ref,
+64 -7
View File
@@ -1,16 +1,13 @@
import { defineStore } from 'pinia';
import Vue, { computed, reactive, watch } from 'vue';
import { computed, reactive, watch } from 'vue';
import { avatarModerationRequest, playerModerationRequest } from '../api';
import { $app } from '../app';
import { watchState } from '../service/watchState';
import { useAvatarStore } from './avatar';
import { useUserStore } from './user';
import { useI18n } from 'vue-i18n-bridge';
export const useModerationStore = defineStore('Moderation', () => {
const avatarStore = useAvatarStore();
const userStore = useUserStore();
const { t } = useI18n();
const state = reactive({
cachedPlayerModerations: new Map(),
@@ -66,6 +63,23 @@ export const useModerationStore = defineStore('Moderation', () => {
function handlePlayerModerationAtDelete(args) {
const { ref } = args;
let hasModeration = false;
for (const ref of state.cachedPlayerModerations.values()) {
if (ref.targetUserId === ref.targetUserId) {
hasModeration = true;
break;
}
}
if (!hasModeration) {
state.cachedPlayerModerationsUserIds.delete(ref.targetUserId);
}
const userRef = userStore.cachedUsers.get(ref.targetUserId);
if (typeof userRef !== 'undefined') {
userRef.$moderations = getUserModerations(ref.targetUserId);
}
const D = userStore.userDialog;
if (
D.visible === false ||
@@ -91,7 +105,7 @@ export const useModerationStore = defineStore('Moderation', () => {
for (let i = 0; i < length; ++i) {
if (array[i].id === ref.id) {
array.splice(i, 1);
return;
break;
}
}
}
@@ -112,9 +126,9 @@ export const useModerationStore = defineStore('Moderation', () => {
playerModerationId: ref.id
}
});
break;
}
}
state.cachedPlayerModerationsUserIds.delete(moderated);
}
/**
@@ -153,6 +167,10 @@ export const useModerationStore = defineStore('Moderation', () => {
} else {
array.push(ref);
}
const userRef = userStore.cachedUsers.get(ref.targetUserId);
if (typeof userRef !== 'undefined') {
userRef.$moderations = getUserModerations(ref.targetUserId);
}
return ref;
}
@@ -213,6 +231,44 @@ export const useModerationStore = defineStore('Moderation', () => {
});
}
/**
* Get user moderations
* @param {string} userId
* @return {object} moderations
* @property {boolean} isBlocked
* @property {boolean} isMuted
* @property {boolean} isAvatarInteractionDisabled
* @property {boolean} isChatBoxMuted
*/
function getUserModerations(userId) {
let moderations = {
isBlocked: false,
isMuted: false,
isAvatarInteractionDisabled: false,
isChatBoxMuted: false
};
for (let ref of state.cachedPlayerModerations.values()) {
if (ref.targetUserId !== userId) {
continue;
}
switch (ref.type) {
case 'block':
moderations.isBlocked = true;
break;
case 'mute':
moderations.isMuted = true;
break;
case 'interactOff':
moderations.isAvatarInteractionDisabled = true;
break;
case 'muteChat':
moderations.isChatBoxMuted = true;
break;
}
}
return moderations;
}
return {
state,
cachedPlayerModerations,
@@ -222,6 +278,7 @@ export const useModerationStore = defineStore('Moderation', () => {
refreshPlayerModerations,
applyPlayerModeration,
handlePlayerModerationDelete
handlePlayerModerationDelete,
getUserModerations
};
});
+2 -2
View File
@@ -524,6 +524,7 @@ export const useUserStore = defineStore('User', () => {
$customTagColour: '',
$friendNumber: 0,
$platform: '',
$moderations: {},
//
...json
};
@@ -594,6 +595,7 @@ export const useUserStore = defineStore('User', () => {
}
Object.assign(ref, json);
}
ref.$moderations = moderationStore.getUserModerations(ref.id);
ref.$isVRCPlus = ref.tags.includes('system_supporter');
appearanceSettingsStore.applyUserTrustLevel(ref);
applyUserLanguage(ref);
@@ -846,8 +848,6 @@ export const useUserStore = defineStore('User', () => {
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') {