mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-17 13:53:52 +02:00
Local friend import/export
This commit is contained in:
@@ -162,6 +162,12 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
.map((fav) => fav.id)
|
||||
);
|
||||
|
||||
const localFriendFavoritesList = computed(() =>
|
||||
Object.values(localFriendFavorites)
|
||||
.flat()
|
||||
.map((userId) => userId)
|
||||
);
|
||||
|
||||
const groupedByGroupKeyFavoriteFriends = computed(() => {
|
||||
const groupedByGroupKeyFavoriteFriends = {};
|
||||
favoriteFriends.value.forEach((friend) => {
|
||||
@@ -1765,6 +1771,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
localAvatarFavoriteGroups,
|
||||
favoriteDialog,
|
||||
localWorldFavoritesList,
|
||||
localFriendFavoritesList,
|
||||
|
||||
localWorldFavoriteGroups,
|
||||
localFriendFavorites,
|
||||
|
||||
@@ -591,7 +591,8 @@
|
||||
localAvatarFavorites,
|
||||
selectedFavoriteAvatars,
|
||||
isFavoriteLoading,
|
||||
localAvatarFavoriteGroups
|
||||
localAvatarFavoriteGroups,
|
||||
avatarImportDialogInput
|
||||
} = storeToRefs(favoriteStore);
|
||||
const {
|
||||
showAvatarImportDialog,
|
||||
@@ -1239,11 +1240,13 @@
|
||||
description: 'Continue? Clear Group',
|
||||
title: 'Confirm'
|
||||
})
|
||||
.then(() => {
|
||||
favoriteRequest.clearFavoriteGroup({
|
||||
type: ctx.type,
|
||||
group: ctx.name
|
||||
});
|
||||
.then(({ ok }) => {
|
||||
if (ok) {
|
||||
favoriteRequest.clearFavoriteGroup({
|
||||
type: ctx.type,
|
||||
group: ctx.name
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
@@ -1276,10 +1279,14 @@
|
||||
function promptLocalAvatarFavoriteGroupDelete(group) {
|
||||
modalStore
|
||||
.confirm({
|
||||
description: `Trash2 Group? ${group}`,
|
||||
description: `Delete Group? ${group}`,
|
||||
title: 'Confirm'
|
||||
})
|
||||
.then(() => deleteLocalAvatarFavoriteGroup(group))
|
||||
.then(({ ok }) => {
|
||||
if (ok) {
|
||||
deleteLocalAvatarFavoriteGroup(group);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
@@ -1400,6 +1407,55 @@
|
||||
refreshingLocalFavorites.value = false;
|
||||
}
|
||||
|
||||
function toggleSelectAllAvatars() {
|
||||
if (!activeRemoteGroup.value) {
|
||||
return;
|
||||
}
|
||||
if (isAllAvatarsSelected.value) {
|
||||
selectedFavoriteAvatars.value = [];
|
||||
} else {
|
||||
selectedFavoriteAvatars.value = currentRemoteFavorites.value.map((fav) => fav.id);
|
||||
}
|
||||
}
|
||||
|
||||
function copySelectedAvatars() {
|
||||
if (!selectedFavoriteAvatars.value.length) {
|
||||
return;
|
||||
}
|
||||
const idList = selectedFavoriteAvatars.value.map((id) => `${id}\n`).join('');
|
||||
avatarImportDialogInput.value = idList;
|
||||
showAvatarImportDialog();
|
||||
}
|
||||
|
||||
function showAvatarBulkUnfavoriteSelectionConfirm() {
|
||||
if (!selectedFavoriteAvatars.value.length) {
|
||||
return;
|
||||
}
|
||||
const total = selectedFavoriteAvatars.value.length;
|
||||
modalStore
|
||||
.confirm({
|
||||
description: `Are you sure you want to unfavorite ${total} favorites?
|
||||
This action cannot be undone.`,
|
||||
title: `Delete ${total} favorites?`
|
||||
})
|
||||
.then(({ ok }) => {
|
||||
if (ok) {
|
||||
bulkUnfavoriteSelectedAvatars(selectedFavoriteAvatars.value);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
function bulkUnfavoriteSelectedAvatars(ids) {
|
||||
ids.forEach((id) => {
|
||||
favoriteRequest.deleteFavorite({
|
||||
objectId: id
|
||||
});
|
||||
});
|
||||
selectedFavoriteAvatars.value = [];
|
||||
avatarEditMode.value = false;
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
cancelLocalAvatarRefresh();
|
||||
if (avatarSplitterObserver) {
|
||||
|
||||
@@ -930,7 +930,7 @@
|
||||
modalStore
|
||||
.confirm({
|
||||
description: `Are you sure you want to unfavorite ${total} favorites?\n This action cannot be undone.`,
|
||||
title: `Trash2 ${total} favorites?`
|
||||
title: `Delete ${total} favorites?`
|
||||
})
|
||||
.then(({ ok }) => ok && bulkUnfavoriteSelectedFriends([...selectedFavoriteFriends.value]))
|
||||
.catch(() => {});
|
||||
@@ -958,11 +958,13 @@
|
||||
description: 'Continue? Clear Group',
|
||||
title: 'Confirm'
|
||||
})
|
||||
.then(() => {
|
||||
favoriteRequest.clearFavoriteGroup({
|
||||
type: ctx.type,
|
||||
group: ctx.name
|
||||
});
|
||||
.then(({ ok }) => {
|
||||
if (ok) {
|
||||
favoriteRequest.clearFavoriteGroup({
|
||||
type: ctx.type,
|
||||
group: ctx.name
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
@@ -1095,9 +1095,13 @@
|
||||
.confirm({
|
||||
description: `Are you sure you want to unfavorite ${total} favorites?
|
||||
This action cannot be undone.`,
|
||||
title: `Trash2 ${total} favorites?`
|
||||
title: `Delete ${total} favorites?`
|
||||
})
|
||||
.then(({ ok }) => {
|
||||
if (ok) {
|
||||
bulkUnfavoriteSelectedWorlds([...selectedFavoriteWorlds.value]);
|
||||
}
|
||||
})
|
||||
.then(() => bulkUnfavoriteSelectedWorlds([...selectedFavoriteWorlds.value]))
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
@@ -1170,10 +1174,14 @@
|
||||
function promptLocalWorldFavoriteGroupDelete(group) {
|
||||
modalStore
|
||||
.confirm({
|
||||
description: `Trash2 Group? ${group}`,
|
||||
description: `Delete Group? ${group}`,
|
||||
title: 'Confirm'
|
||||
})
|
||||
.then(() => deleteLocalWorldFavoriteGroup(group))
|
||||
.then(({ ok }) => {
|
||||
if (ok) {
|
||||
deleteLocalWorldFavoriteGroup(group);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
@@ -1183,11 +1191,13 @@
|
||||
description: 'Continue? Clear Group',
|
||||
title: 'Confirm'
|
||||
})
|
||||
.then(() => {
|
||||
favoriteRequest.clearFavoriteGroup({
|
||||
type: ctx.type,
|
||||
group: ctx.name
|
||||
});
|
||||
.then(({ ok }) => {
|
||||
if (ok) {
|
||||
favoriteRequest.clearFavoriteGroup({
|
||||
type: ctx.type,
|
||||
group: ctx.name
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="FRIEND_EXPORT_ALL_VALUE">All Favorites</SelectItem>
|
||||
<SelectItem :value="FRIEND_EXPORT_ALL_VALUE">None</SelectItem>
|
||||
<SelectItem
|
||||
v-for="groupAPI in favoriteFriendGroups"
|
||||
:key="groupAPI.name"
|
||||
@@ -23,6 +23,22 @@
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select
|
||||
:model-value="friendExportLocalFavoriteGroupSelection"
|
||||
@update:modelValue="handleFriendExportLocalGroupSelect"
|
||||
style="margin-top: 15px">
|
||||
<SelectTrigger size="sm">
|
||||
<SelectValue placeholder="Select Group" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="FRIEND_EXPORT_NONE_VALUE">None</SelectItem>
|
||||
<SelectItem v-for="group in localFriendFavoriteGroups" :key="group" :value="group">
|
||||
{{ group }} ({{ localFriendFavorites[group].length }})
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<br />
|
||||
|
||||
<InputGroupTextareaField
|
||||
@@ -45,7 +61,7 @@
|
||||
import { toast } from 'vue-sonner';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { useFavoriteStore } from '../../../stores';
|
||||
import { useFavoriteStore, useUserStore } from '../../../stores';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -58,12 +74,24 @@
|
||||
|
||||
const emit = defineEmits(['update:friendExportDialogVisible']);
|
||||
|
||||
const { favoriteFriends, favoriteFriendGroups } = storeToRefs(useFavoriteStore());
|
||||
const {
|
||||
favoriteFriends,
|
||||
favoriteFriendGroups,
|
||||
localFriendFavorites,
|
||||
localFriendFavoriteGroups,
|
||||
localFriendFavoritesList
|
||||
} = storeToRefs(useFavoriteStore());
|
||||
const { cachedUsers } = storeToRefs(useUserStore());
|
||||
|
||||
const friendExportFavoriteGroup = ref(null);
|
||||
const FRIEND_EXPORT_ALL_VALUE = '__all__';
|
||||
const friendExportFavoriteGroupSelection = ref(FRIEND_EXPORT_ALL_VALUE);
|
||||
const friendExportContent = ref('');
|
||||
const friendExportFavoriteGroup = ref(null);
|
||||
const friendExportLocalFavoriteGroup = ref(null);
|
||||
|
||||
const FRIEND_EXPORT_ALL_VALUE = '__all__';
|
||||
const FRIEND_EXPORT_NONE_VALUE = '__none__';
|
||||
|
||||
const friendExportFavoriteGroupSelection = ref(FRIEND_EXPORT_ALL_VALUE);
|
||||
const friendExportLocalFavoriteGroupSelection = ref(FRIEND_EXPORT_NONE_VALUE);
|
||||
|
||||
const isDialogVisible = computed({
|
||||
get() {
|
||||
@@ -99,6 +127,15 @@
|
||||
selectFriendExportGroup(group);
|
||||
}
|
||||
|
||||
function handleFriendExportLocalGroupSelect(value) {
|
||||
friendExportLocalFavoriteGroupSelection.value = value;
|
||||
if (value === FRIEND_EXPORT_NONE_VALUE) {
|
||||
selectFriendExportLocalGroup(null);
|
||||
return;
|
||||
}
|
||||
selectFriendExportLocalGroup(value);
|
||||
}
|
||||
|
||||
function handleCopyFriendExportData(event) {
|
||||
if (event.target.tagName === 'TEXTAREA') {
|
||||
event.target.select();
|
||||
@@ -135,21 +172,57 @@
|
||||
return text;
|
||||
};
|
||||
const lines = ['UserID,Name'];
|
||||
favoriteFriendGroups.value.forEach((group) => {
|
||||
if (!friendExportFavoriteGroup.value || friendExportFavoriteGroup.value === group) {
|
||||
favoriteFriends.value.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(`${formatter(ref.id)},${formatter(ref.name)}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (friendExportFavoriteGroup.value) {
|
||||
favoriteFriendGroups.value.forEach((group) => {
|
||||
if (friendExportFavoriteGroup.value === group) {
|
||||
favoriteFriends.value.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(`${formatter(ref.id)},${formatter(ref.name)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (friendExportLocalFavoriteGroup.value) {
|
||||
const favoriteGroup = localFriendFavorites.value[friendExportLocalFavoriteGroup.value];
|
||||
if (!favoriteGroup) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
favoriteGroup.forEach((userId) => {
|
||||
const ref = cachedUsers.value.get(userId);
|
||||
if (typeof ref !== 'undefined') {
|
||||
lines.push(`${formatter(ref.id)},${formatter(ref.displayName)}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// export all
|
||||
favoriteFriends.value.forEach((ref) => {
|
||||
lines.push(`${formatter(ref.id)},${formatter(ref.name)}`);
|
||||
});
|
||||
for (let i = 0; i < localFriendFavoritesList.value.length; ++i) {
|
||||
const userId = localFriendFavoritesList.value[i];
|
||||
const ref = cachedUsers.value.get(userId);
|
||||
if (typeof ref !== 'undefined') {
|
||||
lines.push(`${formatter(ref.id)},${formatter(ref.displayName)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
friendExportContent.value = lines.join('\n');
|
||||
}
|
||||
|
||||
function selectFriendExportGroup(group) {
|
||||
friendExportFavoriteGroup.value = group;
|
||||
friendExportLocalFavoriteGroup.value = null;
|
||||
friendExportFavoriteGroupSelection.value = group?.name ?? FRIEND_EXPORT_ALL_VALUE;
|
||||
friendExportLocalFavoriteGroupSelection.value = FRIEND_EXPORT_NONE_VALUE;
|
||||
updateFriendExportDialog();
|
||||
}
|
||||
|
||||
function selectFriendExportLocalGroup(groupName) {
|
||||
friendExportLocalFavoriteGroup.value = groupName;
|
||||
friendExportFavoriteGroup.value = null;
|
||||
friendExportFavoriteGroupSelection.value = FRIEND_EXPORT_ALL_VALUE;
|
||||
friendExportLocalFavoriteGroupSelection.value = groupName ?? FRIEND_EXPORT_NONE_VALUE;
|
||||
updateFriendExportDialog();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -25,26 +25,44 @@
|
||||
:rows="10"
|
||||
style="margin-top: 10px"
|
||||
input-class="resize-none" />
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-top: 5px">
|
||||
<div>
|
||||
<Select
|
||||
:model-value="friendImportFavoriteGroupSelection"
|
||||
@update:modelValue="handleFriendImportGroupSelect">
|
||||
<SelectTrigger size="sm">
|
||||
<SelectValue :placeholder="t('dialog.friend_import.select_group_placeholder')" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem
|
||||
v-for="groupAPI in favoriteFriendGroups"
|
||||
:key="groupAPI.name"
|
||||
:value="groupAPI.name"
|
||||
:disabled="groupAPI.count >= groupAPI.capacity">
|
||||
{{ groupAPI.displayName }} ({{ groupAPI.count }}/{{ groupAPI.capacity }})
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<div>
|
||||
<div class="mb-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<Select
|
||||
:model-value="friendImportFavoriteGroupSelection"
|
||||
@update:modelValue="handleFriendImportGroupSelect">
|
||||
<SelectTrigger size="sm">
|
||||
<SelectValue :placeholder="t('dialog.friend_import.select_group_placeholder')" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem
|
||||
v-for="groupAPI in favoriteFriendGroups"
|
||||
:key="groupAPI.name"
|
||||
:value="groupAPI.name"
|
||||
:disabled="groupAPI.count >= groupAPI.capacity">
|
||||
{{ groupAPI.displayName }} ({{ groupAPI.count }}/{{ groupAPI.capacity }})
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select
|
||||
:model-value="friendImportLocalFavoriteGroupSelection"
|
||||
@update:modelValue="handleFriendImportLocalGroupSelect"
|
||||
style="margin-left: 10px">
|
||||
<SelectTrigger size="sm">
|
||||
<SelectValue :placeholder="t('dialog.world_import.select_local_group_placeholder')" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem v-for="group in localFriendFavoriteGroups" :key="group" :value="group">
|
||||
{{ group }} ({{ localFriendFavGroupLength(group) }})
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<span v-if="friendImportDialog.friendImportFavoriteGroup" style="margin-left: 5px">
|
||||
{{ friendImportTable.data.length }} /
|
||||
{{
|
||||
@@ -64,7 +82,11 @@
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
:disabled="friendImportTable.data.length === 0 || !friendImportDialog.friendImportFavoriteGroup"
|
||||
:disabled="
|
||||
friendImportTable.data.length === 0 ||
|
||||
(!friendImportDialog.friendImportFavoriteGroup &&
|
||||
!friendImportDialog.friendImportLocalFavoriteGroup)
|
||||
"
|
||||
@click="importFriendImportTable">
|
||||
{{ t('dialog.friend_import.import') }}
|
||||
</Button>
|
||||
@@ -118,10 +140,10 @@
|
||||
const emit = defineEmits(['update:friendImportDialogInput']);
|
||||
|
||||
const { showUserDialog } = useUserStore();
|
||||
const { favoriteFriendGroups, friendImportDialogInput, friendImportDialogVisible } =
|
||||
const { favoriteFriendGroups, friendImportDialogInput, friendImportDialogVisible, localFriendFavoriteGroups } =
|
||||
storeToRefs(useFavoriteStore());
|
||||
const { showFullscreenImageDialog } = useGalleryStore();
|
||||
const { getCachedFavoritesByObjectId } = useFavoriteStore();
|
||||
const { getCachedFavoritesByObjectId, localFriendFavGroupLength, addLocalFriendFavorite } = useFavoriteStore();
|
||||
|
||||
const friendImportDialog = ref({
|
||||
loading: false,
|
||||
@@ -131,11 +153,13 @@
|
||||
userIdList: new Set(),
|
||||
errors: '',
|
||||
friendImportFavoriteGroup: null,
|
||||
friendImportLocalFavoriteGroup: null,
|
||||
importProgress: 0,
|
||||
importProgressTotal: 0
|
||||
});
|
||||
|
||||
const friendImportFavoriteGroupSelection = ref('');
|
||||
const friendImportLocalFavoriteGroupSelection = ref('');
|
||||
|
||||
const friendImportTable = ref({
|
||||
data: [],
|
||||
@@ -203,6 +227,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleFriendImportLocalGroupSelect(value) {
|
||||
friendImportLocalFavoriteGroupSelection.value = value;
|
||||
selectFriendImportLocalGroup(value || null);
|
||||
}
|
||||
|
||||
function cancelFriendImport() {
|
||||
friendImportDialog.value.loading = false;
|
||||
}
|
||||
@@ -215,13 +244,23 @@
|
||||
friendImportDialog.value.userIdList = new Set();
|
||||
}
|
||||
function selectFriendImportGroup(group) {
|
||||
friendImportDialog.value.friendImportLocalFavoriteGroup = null;
|
||||
friendImportDialog.value.friendImportFavoriteGroup = group;
|
||||
friendImportFavoriteGroupSelection.value = group?.name ?? '';
|
||||
friendImportLocalFavoriteGroupSelection.value = '';
|
||||
}
|
||||
|
||||
function selectFriendImportLocalGroup(group) {
|
||||
friendImportDialog.value.friendImportFavoriteGroup = null;
|
||||
friendImportDialog.value.friendImportLocalFavoriteGroup = group;
|
||||
friendImportFavoriteGroupSelection.value = '';
|
||||
friendImportLocalFavoriteGroupSelection.value = group ?? '';
|
||||
}
|
||||
|
||||
async function importFriendImportTable() {
|
||||
const D = friendImportDialog.value;
|
||||
D.loading = true;
|
||||
if (!D.friendImportFavoriteGroup) {
|
||||
if (!D.friendImportFavoriteGroup && !D.friendImportLocalFavoriteGroup) {
|
||||
return;
|
||||
}
|
||||
const data = [...friendImportTable.value.data].reverse();
|
||||
@@ -233,10 +272,14 @@
|
||||
break;
|
||||
}
|
||||
ref = data[i];
|
||||
if (getCachedFavoritesByObjectId(ref.id)) {
|
||||
throw new Error('Friend is already in favorites');
|
||||
if (D.friendImportFavoriteGroup) {
|
||||
if (getCachedFavoritesByObjectId(ref.id)) {
|
||||
throw new Error('Friend is already in favorites');
|
||||
}
|
||||
await addFavoriteUser(ref, D.friendImportFavoriteGroup, false);
|
||||
} else if (D.friendImportLocalFavoriteGroup) {
|
||||
addLocalFriendFavorite(ref.id, D.friendImportLocalFavoriteGroup);
|
||||
}
|
||||
await addFavoriteUser(ref, D.friendImportFavoriteGroup, false);
|
||||
removeFromArray(friendImportTable.value.data, ref);
|
||||
D.userIdList.delete(ref.id);
|
||||
D.importProgress++;
|
||||
|
||||
Reference in New Issue
Block a user