Updated effort at getting usernames

This commit is contained in:
Jacob Karlsson 2024-06-13 17:13:05 +02:00
parent ee156fd8f4
commit 05c381def5
3 changed files with 37 additions and 19 deletions

40
main.js
View File

@ -4,6 +4,7 @@ const URL = require('node:url')
const p = require('node:util').promisify
const awaitable = require('pull-awaitable')
const iterable = require( 'pull-iterable' )
const combineLatest = require('pull-combine-latest')
const pull = require('pull-stream')
const { createPeer } = require('pzp-sdk')
@ -181,29 +182,36 @@ createPeer({ path }).then(({ peer, account: globalAccountID }) => {
if (hasSubscribedToConnections) return
hasSubscribedToConnections = true
//async function* recordAdded( start, end ){
// peer.db.onRecordAdded((record) => {
// yield record
// })
//}
const recordsAdded = pull(
pull.count(),
pull.asyncMap((i, cb) => {
})
combineLatest([
peer.net.peers(),
pull(
pull.count(),
pull.asyncMap((i, cb) => {
// ideally we'd detect peer.db.onRecordAdded here but i couldn't figure out how to convert the obz into a pull stream
setTimeout(() => cb(null, i), 500)
}),
),
])
)
// TODO: combine peers() and onRecordAdded() into one async iterator, so we update the connections list if either there's a new connection *or* if one connected peer has a new name
for await (const connections of awaitable(peer.net.peers())) {
for await (const [connections, i] of awaitable(recordsAdded)) {
console.log('got conns', connections, i)
const connInfo = await Promise.all(connections.map(async (conn) => {
const [multiaddr] = conn
const parts = multiaddr.split('/')
// TODO: woops this seems to get your own name
const parts = [...multiaddr.matchAll(/\w{44}/g)].map(r => r[0])
const key = parts[parts.length - 1]
const accountId = await p(peer.db.account.find)({public: key, subdomain: 'person'})
if (!key) return conn
let accountId
try {
accountId = await p(peer.db.account.find)({keypair: { public: key }, subdomain: 'person'})
} catch {
return conn
}
// TODO: this seems to always return {}. Do the messages manage to replicate?
const profile = await p(peer.dict.read)(accountId, 'profile')
const name = profile?.name
console.log({key, accountId, profile})
return [
conn[0],
{

View File

@ -22,22 +22,23 @@
"concurrently": "^8.2.2",
"debounce": "2.0",
"pull-awaitable": "1.0.0",
"pull-combine-latest": "^1.1.2",
"pull-iterable": "^0.1.0",
"pull-stream": "^3.7.0",
"pzp-caps": "^1.0.0",
"pzp-conductor": "^1.0.2",
"pzp-db": "^1.0.4",
"pzp-dict": "^1.0.1",
"pzp-gc": "^1.0.0",
"pzp-goals": "^1.0.1",
"pzp-hub-client": "^1.0.0",
"pzp-invite": "^1.0.0",
"pzp-keypair": "^1.0.0",
"pzp-net": "^1.0.1",
"pzp-promise": "^1.0.0",
"pzp-sdk": "^1.0.0",
"pzp-set": "^1.0.1",
"pzp-sync": "^1.0.4",
"pzp-conductor": "^1.0.2",
"pzp-hub-client": "^1.0.0",
"pzp-invite": "^1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-outside-click-handler": "1.3.0",

View File

@ -22,6 +22,9 @@ dependencies:
pull-awaitable:
specifier: 1.0.0
version: 1.0.0
pull-combine-latest:
specifier: ^1.1.2
version: 1.1.2
pull-iterable:
specifier: ^0.1.0
version: 0.1.0
@ -1813,6 +1816,7 @@ packages:
/@humanwhocodes/config-array@0.11.14:
resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==}
engines: {node: '>=10.10.0'}
deprecated: Use @eslint/config-array instead
dependencies:
'@humanwhocodes/object-schema': 2.0.3
debug: 4.3.4
@ -1828,6 +1832,7 @@ packages:
/@humanwhocodes/object-schema@2.0.3:
resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==}
deprecated: Use @eslint/object-schema instead
dev: false
/@isaacs/cliui@8.0.2:
@ -9476,6 +9481,10 @@ packages:
resolution: {integrity: sha512-i3w+xZ3DCtTVz8S62hBOuNLRHqVDsHMNZmgrZsjPnsxXUgbWtXEee84lo1XswE7W2a3WHyqsNuDJTjVLAQR8xg==}
dev: false
/pull-combine-latest@1.1.2:
resolution: {integrity: sha512-pn2CD0ayccJCVKeRHzIrkHT4+JdgB7RGNVjEGXiSkl34UeY+pl21xSq6lT/aeED4i2cAGunkFYR0kBaMWVDu0A==}
dev: false
/pull-goodbye@0.0.3:
resolution: {integrity: sha512-fl3RcIHKsxFaygdU3dcwSznLr73HYGOEU9IshpiatYSV+PW3TOUEjtfdu1L8uIsUoDajJz3HM/+mG0mFD4+v5A==}
dependencies: