feat: Add utility method to get all users associated with a doc
This commit is contained in:
parent
e2c9eb7f01
commit
5e8377df50
@ -139,4 +139,21 @@ export class PermanentUserData {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array<string>}
|
||||||
|
*/
|
||||||
|
getUsers () {
|
||||||
|
const users = new Map()
|
||||||
|
|
||||||
|
for (const [userDescription] of this.dss.entries()) {
|
||||||
|
users.set(userDescription, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const client of this.clients.entries()) {
|
||||||
|
users.set(client[1], true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(users.keys())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,4 +60,8 @@ export const testPermanentUserData = async tc => {
|
|||||||
applyUpdate(ydoc3, encodeStateAsUpdate(ydoc1))
|
applyUpdate(ydoc3, encodeStateAsUpdate(ydoc1))
|
||||||
const pd3 = new PermanentUserData(ydoc3)
|
const pd3 = new PermanentUserData(ydoc3)
|
||||||
pd3.setUserMapping(ydoc3, ydoc3.clientID, 'user a')
|
pd3.setUserMapping(ydoc3, ydoc3.clientID, 'user a')
|
||||||
|
|
||||||
|
t.assert(pd3.getUsers().length === 2)
|
||||||
|
t.assert(pd3.getUsers().includes('user a'))
|
||||||
|
t.assert(pd3.getUsers().includes('user b'))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user