diff --git a/services/gunDB/contact-api/getters/user.js b/services/gunDB/contact-api/getters/user.js index fdcd7dfb..8f1d9cf2 100644 --- a/services/gunDB/contact-api/getters/user.js +++ b/services/gunDB/contact-api/getters/user.js @@ -12,8 +12,8 @@ const Utils = require('../utils') */ const getAnUser = async publicKey => { const oldProfile = await Utils.tryAndWait( - g => { - const user = g.get(`~${publicKey}`) + (g, u) => { + const user = u._.sea.pub === publicKey ? u : g.user(publicKey) return new Promise(res => user.get(Key.PROFILE).load(res)) }, @@ -21,25 +21,29 @@ const getAnUser = async publicKey => { ) const bio = await Utils.tryAndWait( - g => - g - .get(`~${publicKey}`) - .get(Key.BIO) - .then(), + (g, u) => { + const user = u._.sea.pub === publicKey ? u : g.user(publicKey) + + return user.get(Key.BIO).then() + }, v => typeof v !== 'string' ) const lastSeenApp = await Utils.tryAndWait( - g => - g - .get(`~${publicKey}`) - .get(Key.LAST_SEEN_APP) - .then(), + (g, u) => { + const user = u._.sea.pub === publicKey ? u : g.user(publicKey) + + return user.get(Key.LAST_SEEN_APP).then() + }, v => typeof v !== 'number' ) const lastSeenNode = await Utils.tryAndWait( - (_, user) => user.get(Key.LAST_SEEN_NODE).then(), + (g, u) => { + const user = u._.sea.pub === publicKey ? u : g.user(publicKey) + + return user.get(Key.LAST_SEEN_NODE).then() + }, v => typeof v !== 'number' ) diff --git a/services/gunDB/contact-api/getters/wall.js b/services/gunDB/contact-api/getters/wall.js index 6a4b2aa5..aeb00746 100644 --- a/services/gunDB/contact-api/getters/wall.js +++ b/services/gunDB/contact-api/getters/wall.js @@ -15,7 +15,14 @@ const Wall = require('./user') const getWallTotalPages = async publicKey => { const totalPages = await Utils.tryAndWait( (gun, u) => { - const user = publicKey ? gun.get(`~${publicKey}`) : u + /** + * @type {import('../SimpleGUN').GUNNode} + */ + let user = u + + if (publicKey && u._.sea.pub !== publicKey) { + user = gun.user(publicKey) + } return user .get(Key.WALL) @@ -65,7 +72,14 @@ const getWallPage = async (page, publicKey) => { // @ts-ignore const count = await Utils.tryAndWait( (g, u) => { - const user = publicKey ? g.get(`~${publicKey}`) : u + /** + * @type {import('../SimpleGUN').GUNNode} + */ + let user = u + + if (publicKey && u._.sea.pub === publicKey) { + user = g.user(publicKey) + } return user .get(Key.WALL) @@ -86,7 +100,14 @@ const getWallPage = async (page, publicKey) => { */ const thePage = await Utils.tryAndWait( (g, u) => { - const user = publicKey ? g.get(`~${publicKey}`) : u + /** + * @type {import('../SimpleGUN').GUNNode} + */ + let user = u + + if (publicKey && u._.sea.pub) { + user = g.user(publicKey) + } return new Promise(res => { user