Local friend import/export

This commit is contained in:
Natsumi
2026-02-18 13:48:23 +11:00
committed by pa
parent ec6d224d71
commit 4db9cd0392
6 changed files with 255 additions and 64 deletions
+7
View File
@@ -162,6 +162,12 @@ export const useFavoriteStore = defineStore('Favorite', () => {
.map((fav) => fav.id) .map((fav) => fav.id)
); );
const localFriendFavoritesList = computed(() =>
Object.values(localFriendFavorites)
.flat()
.map((userId) => userId)
);
const groupedByGroupKeyFavoriteFriends = computed(() => { const groupedByGroupKeyFavoriteFriends = computed(() => {
const groupedByGroupKeyFavoriteFriends = {}; const groupedByGroupKeyFavoriteFriends = {};
favoriteFriends.value.forEach((friend) => { favoriteFriends.value.forEach((friend) => {
@@ -1765,6 +1771,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
localAvatarFavoriteGroups, localAvatarFavoriteGroups,
favoriteDialog, favoriteDialog,
localWorldFavoritesList, localWorldFavoritesList,
localFriendFavoritesList,
localWorldFavoriteGroups, localWorldFavoriteGroups,
localFriendFavorites, localFriendFavorites,
+60 -4
View File
@@ -591,7 +591,8 @@
localAvatarFavorites, localAvatarFavorites,
selectedFavoriteAvatars, selectedFavoriteAvatars,
isFavoriteLoading, isFavoriteLoading,
localAvatarFavoriteGroups localAvatarFavoriteGroups,
avatarImportDialogInput
} = storeToRefs(favoriteStore); } = storeToRefs(favoriteStore);
const { const {
showAvatarImportDialog, showAvatarImportDialog,
@@ -1239,11 +1240,13 @@
description: 'Continue? Clear Group', description: 'Continue? Clear Group',
title: 'Confirm' title: 'Confirm'
}) })
.then(() => { .then(({ ok }) => {
if (ok) {
favoriteRequest.clearFavoriteGroup({ favoriteRequest.clearFavoriteGroup({
type: ctx.type, type: ctx.type,
group: ctx.name group: ctx.name
}); });
}
}) })
.catch(() => {}); .catch(() => {});
} }
@@ -1276,10 +1279,14 @@
function promptLocalAvatarFavoriteGroupDelete(group) { function promptLocalAvatarFavoriteGroupDelete(group) {
modalStore modalStore
.confirm({ .confirm({
description: `Trash2 Group? ${group}`, description: `Delete Group? ${group}`,
title: 'Confirm' title: 'Confirm'
}) })
.then(() => deleteLocalAvatarFavoriteGroup(group)) .then(({ ok }) => {
if (ok) {
deleteLocalAvatarFavoriteGroup(group);
}
})
.catch(() => {}); .catch(() => {});
} }
@@ -1400,6 +1407,55 @@
refreshingLocalFavorites.value = false; 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(() => { onBeforeUnmount(() => {
cancelLocalAvatarRefresh(); cancelLocalAvatarRefresh();
if (avatarSplitterObserver) { if (avatarSplitterObserver) {
+4 -2
View File
@@ -930,7 +930,7 @@
modalStore modalStore
.confirm({ .confirm({
description: `Are you sure you want to unfavorite ${total} favorites?\n This action cannot be undone.`, 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])) .then(({ ok }) => ok && bulkUnfavoriteSelectedFriends([...selectedFavoriteFriends.value]))
.catch(() => {}); .catch(() => {});
@@ -958,11 +958,13 @@
description: 'Continue? Clear Group', description: 'Continue? Clear Group',
title: 'Confirm' title: 'Confirm'
}) })
.then(() => { .then(({ ok }) => {
if (ok) {
favoriteRequest.clearFavoriteGroup({ favoriteRequest.clearFavoriteGroup({
type: ctx.type, type: ctx.type,
group: ctx.name group: ctx.name
}); });
}
}) })
.catch(() => {}); .catch(() => {});
} }
+15 -5
View File
@@ -1095,9 +1095,13 @@
.confirm({ .confirm({
description: `Are you sure you want to unfavorite ${total} favorites? description: `Are you sure you want to unfavorite ${total} favorites?
This action cannot be undone.`, 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(() => {}); .catch(() => {});
} }
@@ -1170,10 +1174,14 @@
function promptLocalWorldFavoriteGroupDelete(group) { function promptLocalWorldFavoriteGroupDelete(group) {
modalStore modalStore
.confirm({ .confirm({
description: `Trash2 Group? ${group}`, description: `Delete Group? ${group}`,
title: 'Confirm' title: 'Confirm'
}) })
.then(() => deleteLocalWorldFavoriteGroup(group)) .then(({ ok }) => {
if (ok) {
deleteLocalWorldFavoriteGroup(group);
}
})
.catch(() => {}); .catch(() => {});
} }
@@ -1183,11 +1191,13 @@
description: 'Continue? Clear Group', description: 'Continue? Clear Group',
title: 'Confirm' title: 'Confirm'
}) })
.then(() => { .then(({ ok }) => {
if (ok) {
favoriteRequest.clearFavoriteGroup({ favoriteRequest.clearFavoriteGroup({
type: ctx.type, type: ctx.type,
group: ctx.name group: ctx.name
}); });
}
}) })
.catch(() => {}); .catch(() => {});
} }
@@ -12,7 +12,7 @@
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectGroup> <SelectGroup>
<SelectItem :value="FRIEND_EXPORT_ALL_VALUE">All Favorites</SelectItem> <SelectItem :value="FRIEND_EXPORT_ALL_VALUE">None</SelectItem>
<SelectItem <SelectItem
v-for="groupAPI in favoriteFriendGroups" v-for="groupAPI in favoriteFriendGroups"
:key="groupAPI.name" :key="groupAPI.name"
@@ -23,6 +23,22 @@
</SelectContent> </SelectContent>
</Select> </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 /> <br />
<InputGroupTextareaField <InputGroupTextareaField
@@ -45,7 +61,7 @@
import { toast } from 'vue-sonner'; import { toast } from 'vue-sonner';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useFavoriteStore } from '../../../stores'; import { useFavoriteStore, useUserStore } from '../../../stores';
const { t } = useI18n(); const { t } = useI18n();
@@ -58,12 +74,24 @@
const emit = defineEmits(['update:friendExportDialogVisible']); 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 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({ const isDialogVisible = computed({
get() { get() {
@@ -99,6 +127,15 @@
selectFriendExportGroup(group); selectFriendExportGroup(group);
} }
function handleFriendExportLocalGroupSelect(value) {
friendExportLocalFavoriteGroupSelection.value = value;
if (value === FRIEND_EXPORT_NONE_VALUE) {
selectFriendExportLocalGroup(null);
return;
}
selectFriendExportLocalGroup(value);
}
function handleCopyFriendExportData(event) { function handleCopyFriendExportData(event) {
if (event.target.tagName === 'TEXTAREA') { if (event.target.tagName === 'TEXTAREA') {
event.target.select(); event.target.select();
@@ -135,8 +172,10 @@
return text; return text;
}; };
const lines = ['UserID,Name']; const lines = ['UserID,Name'];
if (friendExportFavoriteGroup.value) {
favoriteFriendGroups.value.forEach((group) => { favoriteFriendGroups.value.forEach((group) => {
if (!friendExportFavoriteGroup.value || friendExportFavoriteGroup.value === group) { if (friendExportFavoriteGroup.value === group) {
favoriteFriends.value.forEach((ref) => { favoriteFriends.value.forEach((ref) => {
if (group.key === ref.groupKey) { if (group.key === ref.groupKey) {
lines.push(`${formatter(ref.id)},${formatter(ref.name)}`); lines.push(`${formatter(ref.id)},${formatter(ref.name)}`);
@@ -144,12 +183,46 @@
}); });
} }
}); });
} 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'); friendExportContent.value = lines.join('\n');
} }
function selectFriendExportGroup(group) { function selectFriendExportGroup(group) {
friendExportFavoriteGroup.value = group; friendExportFavoriteGroup.value = group;
friendExportLocalFavoriteGroup.value = null;
friendExportFavoriteGroupSelection.value = group?.name ?? FRIEND_EXPORT_ALL_VALUE; 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(); updateFriendExportDialog();
} }
</script> </script>
@@ -25,8 +25,9 @@
:rows="10" :rows="10"
style="margin-top: 10px" style="margin-top: 10px"
input-class="resize-none" /> input-class="resize-none" />
<div style="display: flex; align-items: center; justify-content: space-between; margin-top: 5px">
<div> <div>
<div class="mb-2">
<div class="flex items-center gap-2">
<Select <Select
:model-value="friendImportFavoriteGroupSelection" :model-value="friendImportFavoriteGroupSelection"
@update:modelValue="handleFriendImportGroupSelect"> @update:modelValue="handleFriendImportGroupSelect">
@@ -45,6 +46,23 @@
</SelectGroup> </SelectGroup>
</SelectContent> </SelectContent>
</Select> </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"> <span v-if="friendImportDialog.friendImportFavoriteGroup" style="margin-left: 5px">
{{ friendImportTable.data.length }} / {{ friendImportTable.data.length }} /
{{ {{
@@ -64,7 +82,11 @@
</Button> </Button>
<Button <Button
size="sm" size="sm"
:disabled="friendImportTable.data.length === 0 || !friendImportDialog.friendImportFavoriteGroup" :disabled="
friendImportTable.data.length === 0 ||
(!friendImportDialog.friendImportFavoriteGroup &&
!friendImportDialog.friendImportLocalFavoriteGroup)
"
@click="importFriendImportTable"> @click="importFriendImportTable">
{{ t('dialog.friend_import.import') }} {{ t('dialog.friend_import.import') }}
</Button> </Button>
@@ -118,10 +140,10 @@
const emit = defineEmits(['update:friendImportDialogInput']); const emit = defineEmits(['update:friendImportDialogInput']);
const { showUserDialog } = useUserStore(); const { showUserDialog } = useUserStore();
const { favoriteFriendGroups, friendImportDialogInput, friendImportDialogVisible } = const { favoriteFriendGroups, friendImportDialogInput, friendImportDialogVisible, localFriendFavoriteGroups } =
storeToRefs(useFavoriteStore()); storeToRefs(useFavoriteStore());
const { showFullscreenImageDialog } = useGalleryStore(); const { showFullscreenImageDialog } = useGalleryStore();
const { getCachedFavoritesByObjectId } = useFavoriteStore(); const { getCachedFavoritesByObjectId, localFriendFavGroupLength, addLocalFriendFavorite } = useFavoriteStore();
const friendImportDialog = ref({ const friendImportDialog = ref({
loading: false, loading: false,
@@ -131,11 +153,13 @@
userIdList: new Set(), userIdList: new Set(),
errors: '', errors: '',
friendImportFavoriteGroup: null, friendImportFavoriteGroup: null,
friendImportLocalFavoriteGroup: null,
importProgress: 0, importProgress: 0,
importProgressTotal: 0 importProgressTotal: 0
}); });
const friendImportFavoriteGroupSelection = ref(''); const friendImportFavoriteGroupSelection = ref('');
const friendImportLocalFavoriteGroupSelection = ref('');
const friendImportTable = ref({ const friendImportTable = ref({
data: [], data: [],
@@ -203,6 +227,11 @@
} }
} }
function handleFriendImportLocalGroupSelect(value) {
friendImportLocalFavoriteGroupSelection.value = value;
selectFriendImportLocalGroup(value || null);
}
function cancelFriendImport() { function cancelFriendImport() {
friendImportDialog.value.loading = false; friendImportDialog.value.loading = false;
} }
@@ -215,13 +244,23 @@
friendImportDialog.value.userIdList = new Set(); friendImportDialog.value.userIdList = new Set();
} }
function selectFriendImportGroup(group) { function selectFriendImportGroup(group) {
friendImportDialog.value.friendImportLocalFavoriteGroup = null;
friendImportDialog.value.friendImportFavoriteGroup = group; friendImportDialog.value.friendImportFavoriteGroup = group;
friendImportFavoriteGroupSelection.value = group?.name ?? ''; 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() { async function importFriendImportTable() {
const D = friendImportDialog.value; const D = friendImportDialog.value;
D.loading = true; D.loading = true;
if (!D.friendImportFavoriteGroup) { if (!D.friendImportFavoriteGroup && !D.friendImportLocalFavoriteGroup) {
return; return;
} }
const data = [...friendImportTable.value.data].reverse(); const data = [...friendImportTable.value.data].reverse();
@@ -233,10 +272,14 @@
break; break;
} }
ref = data[i]; ref = data[i];
if (D.friendImportFavoriteGroup) {
if (getCachedFavoritesByObjectId(ref.id)) { if (getCachedFavoritesByObjectId(ref.id)) {
throw new Error('Friend is already in favorites'); throw new Error('Friend is already in favorites');
} }
await addFavoriteUser(ref, D.friendImportFavoriteGroup, false); await addFavoriteUser(ref, D.friendImportFavoriteGroup, false);
} else if (D.friendImportLocalFavoriteGroup) {
addLocalFriendFavorite(ref.id, D.friendImportLocalFavoriteGroup);
}
removeFromArray(friendImportTable.value.data, ref); removeFromArray(friendImportTable.value.data, ref);
D.userIdList.delete(ref.id); D.userIdList.delete(ref.id);
D.importProgress++; D.importProgress++;