feat: Add utility method to get all users associated with a doc

This commit is contained in:
Tom Moor 2020-10-27 16:14:48 -07:00
parent e2c9eb7f01
commit 5e8377df50
2 changed files with 21 additions and 0 deletions

View File

@ -139,4 +139,21 @@ export class PermanentUserData {
}
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())
}
}

View File

@ -60,4 +60,8 @@ export const testPermanentUserData = async tc => {
applyUpdate(ydoc3, encodeStateAsUpdate(ydoc1))
const pd3 = new PermanentUserData(ydoc3)
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'))
}