diff --git a/src/components/Location.vue b/src/components/Location.vue index 966768f4..9d253449 100644 --- a/src/components/Location.vue +++ b/src/components/Location.vue @@ -56,6 +56,13 @@ parse(); }); + function currentInstanceId() { + if (typeof props.traveling !== 'undefined' && props.location === 'traveling') { + return props.traveling; + } + return props.location; + } + function parse() { isTraveling.value = false; groupName.value = ''; @@ -68,7 +75,7 @@ setText(L, L.instanceName); getInstanceName(instanceId) .then((name) => { - if (name && props.location === L.tag) { + if (name && currentInstanceId() === L.tag) { setText(L, name); } }) @@ -82,7 +89,7 @@ groupName.value = L.groupId; getGroupName(instanceId) .then((name) => { - if (name && props.location === L.tag) { + if (name && currentInstanceId() === L.tag) { groupName.value = name; } }) @@ -114,17 +121,16 @@ text.value = props.hint; } } else if (L.worldId) { + if (L.instanceId) { + text.value = `${L.worldId} #${instanceName} ${L.accessTypeName}`; + } else { + text.value = L.worldId; + } const ref = cachedWorlds.get(L.worldId); if (typeof ref === 'undefined') { - const worldName = L.worldId; - if (L.instanceId) { - text.value = `${worldName} #${instanceName} ${L.accessTypeName}`; - } else { - text.value = worldName; - } getWorldName(L.worldId) .then((name) => { - if (name && props.location === L.tag) { + if (name && currentInstanceId() === L.tag) { if (L.instanceId) { text.value = `${name} #${instanceName} ${L.accessTypeName}`; } else { @@ -145,10 +151,7 @@ function handleShowWorldDialog() { if (props.link) { - let instanceId = props.location; - if (props.traveling && props.location === 'traveling') { - instanceId = props.traveling; - } + let instanceId = currentInstanceId(); if (!instanceId && props.hint.length === 8) { verifyShortName('', props.hint); return; @@ -162,10 +165,7 @@ } function handleShowGroupDialog() { - let location = props.location; - if (isTraveling.value) { - location = props.traveling; - } + let location = currentInstanceId(); if (!location || !props.link) { return; } diff --git a/src/shared/utils/friend.js b/src/shared/utils/friend.js index 20b6bb54..d63469c4 100644 --- a/src/shared/utils/friend.js +++ b/src/shared/utils/friend.js @@ -40,6 +40,16 @@ function getFriendsSortFunction(sortMethods) { ) { return 0; } + // sort pending offline to bottom + if (a.pendingOffline && !b.pendingOffline) { + return 1; + } + if (a.pendingOffline && b.pendingOffline) { + return 0; + } + if (!a.pendingOffline && b.pendingOffline) { + return -1; + } if (a.state !== 'online' || b.state !== 'online') { return 0; } diff --git a/src/stores/friend.js b/src/stores/friend.js index 1fe9b10e..0f707d21 100644 --- a/src/stores/friend.js +++ b/src/stores/friend.js @@ -16,7 +16,6 @@ import { getUserMemo, getWorldName, migrateMemos, - removeFromArray, isRealInstance } from '../shared/utils'; import { useAuthStore } from './auth'; @@ -47,14 +46,6 @@ export const useFriendStore = defineStore('Friend', () => { const state = reactive({ friends: new Map(), - onlineFriends_: [], - vipFriends_: [], - activeFriends_: [], - offlineFriends_: [], - sortOnlineFriends: false, - sortVIPFriends: false, - sortActiveFriends: false, - sortOfflineFriends: false, localFavoriteFriends: new Set(), isRefreshFriendsLoading: false, onlineFriendCount: 0, @@ -125,125 +116,44 @@ export const useFriendStore = defineStore('Friend', () => { init(); - // friends_(array) may not have change records in pinia because does not use action - const onlineFriends_ = computed({ - get() { - return state.onlineFriends_; - }, - set(value) { - state.onlineFriends_ = value; - } - }); - const vipFriends_ = computed({ - get() { - return state.vipFriends_; - }, - set(value) { - state.vipFriends_ = value; - } - }); - const activeFriends_ = computed({ - get() { - return state.activeFriends_; - }, - set(value) { - state.activeFriends_ = value; - } - }); - const offlineFriends_ = computed({ - get() { - return state.offlineFriends_; - }, - set(value) { - state.offlineFriends_ = value; - } - }); - const sortOnlineFriends = computed({ - get() { - return state.sortOnlineFriends; - }, - set(value) { - state.sortOnlineFriends = value; - } - }); - const sortVIPFriends = computed({ - get() { - return state.sortVIPFriends; - }, - set(value) { - state.sortVIPFriends = value; - } - }); - const sortActiveFriends = computed({ - get() { - return state.sortActiveFriends; - }, - set(value) { - state.sortActiveFriends = value; - } - }); - const sortOfflineFriends = computed({ - get() { - return state.sortOfflineFriends; - }, - set(value) { - state.sortOfflineFriends = value; - } - }); - - // VIP friends const vipFriends = computed(() => { - if (!state.sortVIPFriends) { - return state.vipFriends_; - } - state.sortVIPFriends = false; - - state.vipFriends_.sort( - getFriendsSortFunction(appearanceSettingsStore.sidebarSortMethods) - ); - return state.vipFriends_; + return Array.from(state.friends.values()) + .filter((f) => f.state === 'online' && f.isVIP) + .sort( + getFriendsSortFunction( + appearanceSettingsStore.sidebarSortMethods + ) + ); }); - // Online friends const onlineFriends = computed(() => { - if (!state.sortOnlineFriends) { - return state.onlineFriends_; - } - state.sortOnlineFriends = false; - - state.onlineFriends_.sort( - getFriendsSortFunction(appearanceSettingsStore.sidebarSortMethods) - ); - - return state.onlineFriends_; + return Array.from(state.friends.values()) + .filter((f) => f.state === 'online' && !f.isVIP) + .sort( + getFriendsSortFunction( + appearanceSettingsStore.sidebarSortMethods + ) + ); }); - // Active friends const activeFriends = computed(() => { - if (!state.sortActiveFriends) { - return state.activeFriends_; - } - state.sortActiveFriends = false; - - state.activeFriends_.sort( - getFriendsSortFunction(appearanceSettingsStore.sidebarSortMethods) - ); - - return state.activeFriends_; + return Array.from(state.friends.values()) + .filter((f) => f.state === 'active') + .sort( + getFriendsSortFunction( + appearanceSettingsStore.sidebarSortMethods + ) + ); }); - // Offline friends const offlineFriends = computed(() => { - if (!state.sortOfflineFriends) { - return state.offlineFriends_; - } - state.sortOfflineFriends = false; - - state.offlineFriends_.sort( - getFriendsSortFunction(appearanceSettingsStore.sidebarSortMethods) - ); - - return state.offlineFriends_; + return Array.from(state.friends.values()) + .filter((f) => f.state === 'offline' || !f.state) + .sort( + getFriendsSortFunction( + appearanceSettingsStore.sidebarSortMethods + ) + ); }); const isRefreshFriendsLoading = computed({ @@ -280,14 +190,6 @@ export const useFriendStore = defineStore('Friend', () => { friendLog.clear(); state.friendLogTable.data = []; groupStore.groupInstances = []; - state.vipFriends_ = []; - state.onlineFriends_ = []; - state.activeFriends_ = []; - state.offlineFriends_ = []; - state.sortVIPFriends = false; - state.sortOnlineFriends = false; - state.sortActiveFriends = false; - state.sortOfflineFriends = false; state.onlineFriendCount = 0; if (isLoggedIn) { initFriendsList(); @@ -402,18 +304,6 @@ export const useFriendStore = defineStore('Friend', () => { continue; } ctx.isVIP = isVIP; - if (ctx.state !== 'online') { - continue; - } - if (ctx.isVIP) { - removeFromArray(state.onlineFriends_, ctx); - state.vipFriends_.push(ctx); - state.sortVIPFriends = true; - } else { - removeFromArray(state.vipFriends_, ctx); - state.onlineFriends_.push(ctx); - state.sortOnlineFriends = true; - } } } @@ -491,40 +381,13 @@ export const useFriendStore = defineStore('Friend', () => { userId: id }); } - if (ctx.isVIP) { - state.sortVIPFriends = true; - } else { - state.sortOnlineFriends = true; - } } } if (ctx.isVIP !== isVIP) { ctx.isVIP = isVIP; - if (ctx.state === 'online') { - if (ctx.isVIP) { - removeFromArray(state.onlineFriends_, ctx); - state.vipFriends_.push(ctx); - state.sortVIPFriends = true; - } else { - removeFromArray(state.vipFriends_, ctx); - state.onlineFriends_.push(ctx); - state.sortOnlineFriends = true; - } - } } if (typeof ref !== 'undefined' && ctx.name !== ref.displayName) { ctx.name = ref.displayName; - if (ctx.state === 'online') { - if (ctx.isVIP) { - state.sortVIPFriends = true; - } else { - state.sortOnlineFriends = true; - } - } else if (ctx.state === 'active') { - state.sortActiveFriends = true; - } else { - state.sortOfflineFriends = true; - } } } else if ( ctx.state === 'online' && @@ -684,32 +547,6 @@ export const useFriendStore = defineStore('Friend', () => { ctx.ref.$active_for = Date.now(); } } - if (ctx.state === 'online') { - if (ctx.isVIP) { - removeFromArray(state.vipFriends_, ctx); - } else { - removeFromArray(state.onlineFriends_, ctx); - } - } else if (ctx.state === 'active') { - removeFromArray(state.activeFriends_, ctx); - } else { - removeFromArray(state.offlineFriends_, ctx); - } - if (newState === 'online') { - if (isVIP) { - state.vipFriends_.push(ctx); - state.sortVIPFriends = true; - } else { - state.onlineFriends_.push(ctx); - state.sortOnlineFriends = true; - } - } else if (newState === 'active') { - state.activeFriends_.push(ctx); - state.sortActiveFriends = true; - } else { - state.offlineFriends_.push(ctx); - state.sortOfflineFriends = true; - } if (ctx.state !== newState) { ctx.state = newState; updateOnlineFriendCoutner(); @@ -729,17 +566,6 @@ export const useFriendStore = defineStore('Friend', () => { return; } state.friends.delete(id); - if (ctx.state === 'online') { - if (ctx.isVIP) { - removeFromArray(state.vipFriends_, ctx); - } else { - removeFromArray(state.onlineFriends_, ctx); - } - } else if (ctx.state === 'active') { - removeFromArray(state.activeFriends_, ctx); - } else { - removeFromArray(state.offlineFriends_, ctx); - } } /** @@ -824,21 +650,6 @@ export const useFriendStore = defineStore('Friend', () => { ctx.name = ref.name; } state.friends.set(id, ctx); - if (ctx.state === 'online') { - if (ctx.isVIP) { - state.vipFriends_.push(ctx); - state.sortVIPFriends = true; - } else { - state.onlineFriends_.push(ctx); - state.sortOnlineFriends = true; - } - } else if (ctx.state === 'active') { - state.activeFriends_.push(ctx); - state.sortActiveFriends = true; - } else { - state.offlineFriends_.push(ctx); - state.sortOfflineFriends = true; - } } /** @@ -1033,18 +844,6 @@ export const useFriendStore = defineStore('Friend', () => { reconnectWebSocket(); } - /** - * @param {string} userId - */ - function updateFriendGPS(userId) { - const ctx = state.friends.get(userId); - if (ctx.isVIP) { - state.sortVIPFriends = true; - } else { - state.sortOnlineFriends = true; - } - } - function updateOnlineFriendCoutner() { const onlineFriendCount = vipFriends.value.length + onlineFriends.value.length; @@ -1609,8 +1408,8 @@ export const useFriendStore = defineStore('Friend', () => { state.friendNumber = state.friends.size + 1; const friendLogTable = getFriendLogFriendOrder(); for (let i = friendLogTable.length - 1; i > -1; i--) { - const friendLog = friendLogTable[i]; - const ref = friendLog.get(friendLog.id); + const friendLogEntry = friendLogTable[i]; + const ref = friendLog.get(friendLogEntry.id); if (!ref) { continue; } @@ -1620,7 +1419,7 @@ export const useFriendStore = defineStore('Friend', () => { ref.friendNumber = --state.friendNumber; friendLog.set(ref.userId, ref); database.setFriendLogCurrent(ref); - const friendRef = state.friends.get(friendLog.id); + const friendRef = state.friends.get(friendLogEntry.id); if (friendRef?.ref) { friendRef.ref.$friendNumber = ref.friendNumber; } @@ -1743,15 +1542,15 @@ export const useFriendStore = defineStore('Friend', () => { // will need to apply in reverse order instead return; } - for (const friendLog of friendLogTable) { - const ref = friendLog.get(friendLog.id); + for (const friendLogEntry of friendLogTable) { + const ref = friendLog.get(friendLogEntry.id); if (!ref || ref.friendNumber) { continue; } ref.friendNumber = ++state.friendNumber; friendLog.set(ref.userId, ref); database.setFriendLogCurrent(ref); - const friendRef = state.friends.get(friendLog.id); + const friendRef = state.friends.get(friendLogEntry.id); if (friendRef?.ref) { friendRef.ref.$friendNumber = ref.friendNumber; } @@ -1773,13 +1572,6 @@ export const useFriendStore = defineStore('Friend', () => { .catch(() => {}); } - async function saveSidebarSortOrder() { - state.sortVIPFriends = true; - state.sortOnlineFriends = true; - state.sortActiveFriends = true; - state.sortOfflineFriends = true; - } - async function initFriendsList() { const userId = userStore.currentUser.id; state.isRefreshFriendsLoading = true; @@ -1806,10 +1598,6 @@ export const useFriendStore = defineStore('Friend', () => { tryApplyFriendOrder(); // once again getAllUserStats(); // joinCount, lastSeen, timeSpent - state.sortVIPFriends = true; - state.sortOnlineFriends = true; - state.sortActiveFriends = true; - state.sortOfflineFriends = true; // remove old data from json file and migrate to SQLite (July 2021) if (await VRCXStorage.Get(`${userId}_friendLogUpdatedAt`)) { @@ -1823,21 +1611,12 @@ export const useFriendStore = defineStore('Friend', () => { state, friends, - onlineFriends_, - vipFriends_, - activeFriends_, - offlineFriends_, vipFriends, onlineFriends, activeFriends, offlineFriends, - sortOnlineFriends, - sortVIPFriends, - sortActiveFriends, - sortOfflineFriends, - localFavoriteFriends, isRefreshFriendsLoading, onlineFriendCount, @@ -1854,7 +1633,6 @@ export const useFriendStore = defineStore('Friend', () => { refreshFriends, refreshFriendsList, updateOnlineFriendCoutner, - updateFriendGPS, getAllUserStats, initFriendLog, migrateFriendLog, @@ -1862,7 +1640,6 @@ export const useFriendStore = defineStore('Friend', () => { getFriendRequest, userOnFriend, confirmDeleteFriend, - saveSidebarSortOrder, updateFriendships, updateUserCurrentStatus, handleFriendAdd, diff --git a/src/stores/user.js b/src/stores/user.js index 9a7fb1f4..3cca5bb9 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -1349,7 +1349,6 @@ export const useUserStore = defineStore('User', () => { }; feedStore.addFeed(feed); database.addGPSToDatabase(feed); - friendStore.updateFriendGPS(ref.id); // clear previousLocation after GPS ref.$previousLocation = ''; ref.$travelingToTime = Date.now(); @@ -1363,7 +1362,6 @@ export const useUserStore = defineStore('User', () => { // store previous location when user is traveling ref.$previousLocation = props.location[1]; ref.$travelingToTime = Date.now(); - friendStore.updateFriendGPS(ref.id); } let imageMatches = false; if ( diff --git a/src/views/Settings/Settings.vue b/src/views/Settings/Settings.vue index 4861c2ab..d6b15e04 100644 --- a/src/views/Settings/Settings.vue +++ b/src/views/Settings/Settings.vue @@ -466,10 +466,7 @@ :model-value="sidebarSortMethod1" style="width: 170px" :placeholder="t('view.settings.appearance.side_panel.sorting.placeholder')" - @change=" - setSidebarSortMethod1($event); - saveSidebarSortOrder(); - "> + @change="setSidebarSortMethod1($event)"> - + + @change="setSidebarSortMethod2($event)"> - + + @change="setSidebarSortMethod3($event)"> 1) { - sortedFriendsList.push(group.sort((a, b) => a.ref?.$location_at - b.ref?.$location_at)); + sortedFriendsList.push(group.sort(getFriendsSortFunction(sidebarSortMethods.value))); } }