Remove old create post fn
This commit is contained in:
parent
233452e59b
commit
0a3da2abc9
1 changed files with 0 additions and 157 deletions
|
|
@ -752,162 +752,6 @@ const createPostNew = async (tags, title, content) => {
|
||||||
return [postID, newPost]
|
return [postID, newPost]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string[]} tags
|
|
||||||
* @param {string} title
|
|
||||||
* @param {Common.Schema.ContentItem[]} content
|
|
||||||
* @returns {Promise<Common.Schema.Post>}
|
|
||||||
*/
|
|
||||||
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<void>} */ (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<void>} */ (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} postId
|
||||||
* @param {string} page
|
* @param {string} page
|
||||||
|
|
@ -1058,7 +902,6 @@ module.exports = {
|
||||||
saveSeedBackup,
|
saveSeedBackup,
|
||||||
saveChannelsBackup,
|
saveChannelsBackup,
|
||||||
setLastSeenApp,
|
setLastSeenApp,
|
||||||
createPost,
|
|
||||||
deletePost,
|
deletePost,
|
||||||
follow,
|
follow,
|
||||||
unfollow,
|
unfollow,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue