Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 1x 9x 7x 2x 2x 2x 6x 9x 9x | import { defineStore } from 'pinia'
import { ref } from 'vue'
export const usePresenceStore = defineStore('presence', () => {
// listId → Set of online deviceIds
const onlineByList = ref<Record<string, Set<string>>>({})
function setSnapshot(listId: string, devices: string[]) {
onlineByList.value[listId] = new Set(devices)
}
function addDevice(listId: string, deviceId: string) {
if (!onlineByList.value[listId]) onlineByList.value[listId] = new Set()
onlineByList.value[listId]!.add(deviceId)
}
function removeDevice(listId: string, deviceId: string) {
onlineByList.value[listId]?.delete(deviceId)
}
function getCount(listId: string): number {
return onlineByList.value[listId]?.size ?? 0
}
function isOnline(listId: string, deviceId: string): boolean {
return onlineByList.value[listId]?.has(deviceId) ?? false
}
return { onlineByList, setSnapshot, addDevice, removeDevice, getCount, isOnline }
})
|