From 0a3da2abc9c0a9da6039f38f9b6d0b9c323ea1e9 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 23 Jul 2021 09:09:24 -0400 Subject: [PATCH] Remove old create post fn --- services/gunDB/contact-api/actions.js | 157 -------------------------- 1 file changed, 157 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index 9312f864..4433c150 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -752,162 +752,6 @@ const createPostNew = async (tags, title, content) => { return [postID, newPost] } -/** - * @param {string[]} tags - * @param {string} title - * @param {Common.Schema.ContentItem[]} content - * @returns {Promise} - */ -const createPost = async (tags, title, content) => { - if (content.length === 0) { - throw new Error(`A post must contain at least one paragraph/image/video`) - } - - const numOfPages = await (async () => { - const maybeNumOfPages = await Utils.tryAndWait( - (_, user) => - user - .get(Key.WALL) - .get(Key.NUM_OF_PAGES) - .then(), - v => typeof v !== 'number' - ) - - if (typeof maybeNumOfPages !== 'number') { - throw new TypeError( - `Could not fetch number of pages from wall, instead got: ${JSON.stringify( - maybeNumOfPages - )}` - ) - } - - return maybeNumOfPages - })() - - let pageIdx = Math.max(0, numOfPages - 1).toString() - - const count = await (async () => { - if (numOfPages === 0) { - return 0 - } - - const maybeCount = await Utils.tryAndWait( - (_, user) => - user - .get(Key.WALL) - .get(Key.PAGES) - .get(pageIdx) - .get(Key.COUNT) - .then(), - v => typeof v !== 'number' - ) - - return typeof maybeCount === 'number' ? maybeCount : 0 - })() - - const shouldBeNewPage = - count >= Common.Constants.Misc.NUM_OF_POSTS_PER_WALL_PAGE - - if (shouldBeNewPage) { - pageIdx = Number(pageIdx + 1).toString() - } - - await /** @type {Promise} */ (new Promise((res, rej) => { - require('../Mediator') - .getUser() - .get(Key.WALL) - .get(Key.PAGES) - .get(pageIdx) - .put( - { - [Key.COUNT]: shouldBeNewPage ? 1 : count + 1, - posts: { - unused: null - } - }, - ack => { - if (ack.err && typeof ack.err !== 'number') { - rej(new Error(ack.err)) - } - - res() - } - ) - })) - - const [postID, newPost] = await createPostNew(tags, title, content) - - await Common.makePromise((res, rej) => { - require('../Mediator') - .getUser() - .get(Key.WALL) - .get(Key.PAGES) - .get(pageIdx) - .get(Key.POSTS) - .get(postID) - .put( - // @ts-expect-error - newPost, - ack => { - if (ack.err && typeof ack.err !== 'number') { - rej(new Error(ack.err)) - } else { - res() - } - } - ) - }) - - if (shouldBeNewPage || numOfPages === 0) { - await /** @type {Promise} */ (new Promise(res => { - require('../Mediator') - .getUser() - .get(Key.WALL) - .get(Key.NUM_OF_PAGES) - .put(numOfPages + 1, ack => { - if (ack.err && typeof ack.err !== 'number') { - throw new Error(ack.err) - } - - res() - }) - })) - } - - const loadedPost = await new Promise(res => { - require('../Mediator') - .getUser() - .get(Key.WALL) - .get(Key.PAGES) - .get(pageIdx) - .get(Key.POSTS) - .get(postID) - .load(data => { - res(data) - }) - }) - - /** @type {Common.Schema.User} */ - const userForPost = await Getters.getMyUser() - - /** @type {Common.Schema.Post} */ - const completePost = { - ...loadedPost, - author: userForPost, - id: postID - } - - if (!Common.Schema.isPost(completePost)) { - throw new Error( - `completePost not a Post inside Actions.createPost(): ${JSON.stringify( - completePost - )}` - ) - } - - return completePost -} - /** * @param {string} postId * @param {string} page @@ -1058,7 +902,6 @@ module.exports = { saveSeedBackup, saveChannelsBackup, setLastSeenApp, - createPost, deletePost, follow, unfollow,