Skip to content

Commit

Permalink
user-info.js: refactor function names to reflect info being centerstage
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Feb 27, 2024
1 parent 927eaa1 commit b69be91
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class CableCore extends EventEmitter {

// gets the local user's most recently set nickname
getNick(cb) {
this.store.userInfoView.api.getLatestNameHash(this.kp.publicKey, (err, hash) => {
this.store.userInfoView.api.getLatestInfoHash(this.kp.publicKey, (err, hash) => {
if (err) { return cb(err) }
this.resolveHashes([hash], (err, results) => {
if (err) { return cb(err) }
Expand Down Expand Up @@ -444,7 +444,7 @@ class CableCore extends EventEmitter {
const hex = util.hex(publicKey)
users.set(hex, hex)
})
this.store.userInfoView.api.getLatestNameHashesAllUsers((err, latestNameHashes) => {
this.store.userInfoView.api.getLatestInfoHashAllUsers((err, latestNameHashes) => {
if (err) return cb(err)
this.resolveHashes(latestNameHashes, (err, posts) => {
// TODO (2023-09-06): handle post/info deletion and storing null?
Expand Down Expand Up @@ -532,7 +532,7 @@ class CableCore extends EventEmitter {
this.store.channelMembershipView.api.getHistoricUsers(channel, (err, pubkeys) => {
// get the latest nickname for each user that has been a member of channel
const namePromise = new Promise((res, reject) => {
this.store.userInfoView.api.getLatestNameHashMany(pubkeys, (err, nameHashes) => {
this.store.userInfoView.api.getLatestInfoHashMany(pubkeys, (err, nameHashes) => {
if (err) return reject(err)
res(nameHashes)
})
Expand Down
4 changes: 2 additions & 2 deletions store.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ class CableStore extends EventEmitter {
}

_reindexInfoName (channel, publicKey, sendHash, done) {
this.channelStateView.api.getLatestNameHash(channel, publicKey, (err, hash) => {
this.channelStateView.api.getLatestInfoHash(channel, publicKey, (err, hash) => {
storedebug("latest name err", err)
storedebug("latest name hash", hash)
if (err && err.notFound) {
this.userInfoView.api.clearName(publicKey)
this.userInfoView.api.clearInfo(publicKey)
sendHash(null)
return done()
}
Expand Down
6 changes: 3 additions & 3 deletions views/channel-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ module.exports = function (lvl, reverseIndex) {
cb(null, hashes)
})
},
// TODO (2023-04-20): remove this file's getLatestNameHash function when user-info.js has a latestNameHash operating without latest key
getLatestNameHash: function (channel, publicKey, cb) {
// TODO (2023-04-20): remove this file's getLatestInfoHash function when user-info.js has a latestNameHash operating without latest key
getLatestInfoHash: function (channel, publicKey, cb) {
// return latest post/info hash for pubkey
ready(async function () {
debug("api.getLatestNameHash")
debug("api.getLatestInfoHash")
const iter = lvl.values({
lt: `name!${channel}!${util.timestamp()}!${util.hex(publicKey)}`,
gt: "name!!",
Expand Down
19 changes: 9 additions & 10 deletions views/user-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function noop () {}
// takes a (sub)level instance
module.exports = function (lvl, reverseIndex) {
const events = new EventEmitter()

// callback processing queue. functions are pushed onto the queue if they are dispatched before the store is ready or
// there are pending transactions in the pipeline
let queue = []
Expand Down Expand Up @@ -96,8 +95,8 @@ module.exports = function (lvl, reverseIndex) {
},

api: {
// return latest post/info name-setting hash for all recorded pubkeys
getLatestNameHashesAllUsers: function (cb) {
// return latest post/info hash for all recorded pubkeys
getLatestInfoHashAllUsers: function (cb) {
ready(async function () {
debug("api.getUsers")
const iter = lvl.values({
Expand All @@ -109,22 +108,22 @@ module.exports = function (lvl, reverseIndex) {
cb(null, hashes)
})
},
// return latest post/info name-setting hash for specified publicKey
getLatestNameHash: function (publicKey, cb) {
// return latest post/info hash for specified publicKey
getLatestInfoHash: function (publicKey, cb) {
ready(function () {
// TODO (2023-03-07): consider converting to using a range query with limit: 1 instead
debug("api.getLatestNameHash")
debug("api.getLatestInfoHash")
lvl.get(`latest!${util.hex(publicKey)}`, (err, hash) => {
if (err) { return cb(err, null) }
return cb(null, hash)
})
})
},
// this function is needed to fulfilling channel state requests, in terms of getting the latest name hashes
getLatestNameHashMany: function (pubkeys, cb) {
getLatestInfoHashMany: function (pubkeys, cb) {
// return latest post/info hash for many pubkeys
ready(function () {
debug("api.getLatestNameHashMany")
debug("api.getLatestInfoHashMany")
const keys = pubkeys.map(publicKey => {
return `latest!${util.hex(publicKey)}`
})
Expand All @@ -138,11 +137,11 @@ module.exports = function (lvl, reverseIndex) {
})
})
},
clearName: function (publicKey, cb) {
clearInfo: function (publicKey, cb) {
if (!cb) { cb = noop }
// remove the name record for this public key
ready(function () {
debug("api.clearNameHash")
debug("api.clearInfoHash")
lvl.del(`latest!${util.hex(publicKey)}`, (err) => {
if (err) { return cb(er) }
return cb(null)
Expand Down

0 comments on commit b69be91

Please sign in to comment.