{"version":3,"file":"SessionList-CEjn9R56.chunk.mjs","sources":["../node_modules/vue-material-design-icons/AccountMultipleOutline.vue","../src/composables/useSessions.ts","../node_modules/vue-material-design-icons/AccountOutline.vue","../src/components/Editor/AvatarWrapper.vue","../src/components/Editor/GuestNameDialog.vue","../src/components/Editor/SessionList.vue"],"sourcesContent":["\n \n \n \n\n\n","/**\n * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport {\n\tcomputed,\n\tonMounted,\n\tonUnmounted,\n\treadonly,\n\tref,\n\tshallowRef,\n\twatch,\n\ttype ShallowRef,\n} from 'vue'\nimport type { OpenData } from '../apis/connect.js'\nimport {\n\tCOLLABORATOR_DISCONNECT_TIME,\n\tisGuest,\n\tSyncService,\n\ttype Session,\n} from '../services/SyncService.js'\nimport { useConnection } from './useConnection.js'\n\n/**\n * Get the sessions from the sync service.\n *\n * @param syncService to watch for changes to the sessions.\n */\nexport function useSessions(syncService: SyncService) {\n\tconst { openData } = useConnection() as {\n\t\topenData: ShallowRef\n\t}\n\tconst currentSession = ref(openData.value?.session)\n\tconst sessions = shallowRef([])\n\n\twatch(openData, (val) => {\n\t\tif (val?.session) {\n\t\t\tcurrentSession.value = val.session\n\t\t}\n\t})\n\n\tconst currentGuestSession = computed({\n\t\tget() {\n\t\t\tif (currentSession.value && isGuest(currentSession.value)) {\n\t\t\t\treturn currentSession.value\n\t\t\t}\n\t\t},\n\t\tset(newValue) {\n\t\t\tcurrentSession.value = newValue\n\t\t},\n\t})\n\n\tconst updateSessions = ({ sessions: updated }: { sessions: Session[] }) => {\n\t\tconst cutoff = Date.now() / 1000 - COLLABORATOR_DISCONNECT_TIME\n\t\tsessions.value = updated\n\t\t\t.filter((session) => session.lastContact > cutoff)\n\t\t\t.sort((a, b) => b.lastContact - a.lastContact)\n\t\t\t.filter(uniqueUserId)\n\n\t\t// Make sure we get our own session updated\n\t\tconst currentUpdatedSession = sessions.value.find(\n\t\t\t(session) => session.id === currentSession.value?.id,\n\t\t)\n\t\tif (currentUpdatedSession) {\n\t\t\tcurrentSession.value = currentUpdatedSession\n\t\t}\n\t}\n\tonMounted(() => {\n\t\tsyncService.bus.on('change', updateSessions)\n\t})\n\tonUnmounted(() => {\n\t\tsyncService.bus.off('change', updateSessions)\n\t})\n\treturn {\n\t\tcurrentGuestSession,\n\t\tcurrentSession: readonly(currentSession),\n\t\tsessions: readonly(sessions),\n\t}\n}\n\n/**\n * Return true for entries with a unique user id or with no user id (Guests).\n *\n * To be used in filter. Will keep the first entry and remove duplicates.\n *\n * @param val the current value\n * @param idx index of the current value\n * @param arr the entire array\n */\nfunction uniqueUserId(val: Session, idx: number, arr: Session[]): boolean {\n\tif (!('userId' in val)) {\n\t\treturn true\n\t}\n\treturn !arr\n\t\t.slice(0, idx)\n\t\t.some((session) => 'userId' in session && session.userId === val.userId)\n}\n","\n \n \n \n\n\n","\n\n\n\t