diff --git a/services/gunDB/contact-api/getters/wall.js b/services/gunDB/contact-api/getters/wall.js index f55e7b1e..cff14b84 100644 --- a/services/gunDB/contact-api/getters/wall.js +++ b/services/gunDB/contact-api/getters/wall.js @@ -6,15 +6,19 @@ const Utils = require('../utils') const Key = require('../key') /** + * @param {string=} publicKey * @returns {Promise} */ -const getWallTotalPages = async () => { +const getWallTotalPages = async publicKey => { const totalPages = await Utils.tryAndWait( - (_, user) => - user + (gun, u) => { + const user = publicKey ? gun.get(`~${publicKey}`) : u + + return user .get(Key.WALL) .get(Key.NUM_OF_PAGES) - .then(), + .then() + }, v => typeof v !== 'number' ) @@ -23,12 +27,13 @@ const getWallTotalPages = async () => { /** * @param {number} page + * @param {string=} publicKey * @throws {TypeError} * @throws {RangeError} * @returns {Promise} */ -const getWallPage = async page => { - const totalPages = await getWallTotalPages() +const getWallPage = async (page, publicKey) => { + const totalPages = await getWallTotalPages(publicKey) if (page === 0 || totalPages === 0) { return { @@ -47,15 +52,18 @@ const getWallPage = async page => { * @type {Common.SchemaTypes.WallPage} */ const thePage = await Utils.tryAndWait( - (_, user) => - new Promise(res => { + (g, u) => { + const user = publicKey ? g.get(`~${publicKey}`) : u + + return new Promise(res => { user .get(Key.WALL) .get(Key.PAGES) .get(actualPageIdx.toString()) // @ts-ignore .load(res) - }), + }) + }, maybePage => { if (typeof maybePage !== 'object' || maybePage === null) { return true diff --git a/src/routes.js b/src/routes.js index 5c4e99de..fcaeb879 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1842,9 +1842,10 @@ module.exports = async ( }) //////////////////////////////////////////////////////////////////////////////// - app.get(`/api/gun/wall`, async (req, res) => { + app.get(`/api/gun/wall/:publicKey`, async (req, res) => { try { const { page } = req.query; + const {publicKey} = req.params const pageNum = Number(page) @@ -1855,8 +1856,8 @@ module.exports = async ( }) } - const totalPages = await GunGetters.getWallTotalPages() - const fetchedPage = await GunGetters.getWallPage(pageNum) + const totalPages = await GunGetters.getWallTotalPages(publicKey) + const fetchedPage = await GunGetters.getWallPage(pageNum, publicKey) return res.status(200).json({ ...fetchedPage,