Merge pull request #246 from shocknet/bug/tip-posts

Post tip counter fix
This commit is contained in:
CapDog 2020-11-08 07:59:59 -06:00 committed by GitHub
commit e071fd86f7

View file

@ -36,18 +36,14 @@ const _lookupInvoice = hash =>
}) })
}) })
const _getPostTipInfo = ({ postID, page }) => const _getPostTipInfo = ({ postID }) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
getUser() getUser()
.get(Key.WALL) .get(Key.POSTS_NEW)
.get(Key.PAGES)
.get(page)
.get(Key.POSTS)
.get(postID) .get(postID)
.once(post => { .once(post => {
if (post && post.date) { if (post && post.date) {
const { tipCounter, tipValue } = post const { tipCounter, tipValue } = post
console.log(post)
resolve({ resolve({
tipCounter: typeof tipCounter === 'number' ? tipCounter : 0, tipCounter: typeof tipCounter === 'number' ? tipCounter : 0,
tipValue: typeof tipValue === 'number' ? tipValue : 0 tipValue: typeof tipValue === 'number' ? tipValue : 0
@ -58,7 +54,7 @@ const _getPostTipInfo = ({ postID, page }) =>
}) })
}) })
const _incrementPost = ({ postID, page, orderAmount }) => const _incrementPost = ({ postID, orderAmount }) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const parsedAmount = parseFloat(orderAmount) const parsedAmount = parseFloat(orderAmount)
@ -69,7 +65,7 @@ const _incrementPost = ({ postID, page, orderAmount }) =>
Logger.info('[POST TIP] Getting Post Tip Values...') Logger.info('[POST TIP] Getting Post Tip Values...')
return _getPostTipInfo({ postID, page }) return _getPostTipInfo({ postID })
.then(({ tipValue, tipCounter }) => { .then(({ tipValue, tipCounter }) => {
const updatedTip = { const updatedTip = {
tipCounter: tipCounter + 1, tipCounter: tipCounter + 1,
@ -77,10 +73,7 @@ const _incrementPost = ({ postID, page, orderAmount }) =>
} }
getUser() getUser()
.get(Key.WALL) .get(Key.POSTS_NEW)
.get(Key.PAGES)
.get(page)
.get(Key.POSTS)
.get(postID) .get(postID)
.put(updatedTip, () => { .put(updatedTip, () => {
Logger.info('[POST TIP] Successfully updated Post tip info') Logger.info('[POST TIP] Successfully updated Post tip info')
@ -158,7 +151,6 @@ const executeTipAction = (tip, invoice) => {
if (tip.targetType === 'post') { if (tip.targetType === 'post') {
_incrementPost({ _incrementPost({
postID: tip.postID, postID: tip.postID,
page: tip.postPage,
orderAmount: invoice.amt_paid_sat orderAmount: invoice.amt_paid_sat
}) })
} }