switched voting from generalData to applicationData

This commit is contained in:
sairaj mote 2022-06-04 03:33:40 +05:30
parent 0336b322ef
commit cb9f2d8bda

View File

@ -1345,16 +1345,10 @@
// implement live voting // implement live voting
getRef('like_count').textContent = floGlobals.appObjects.rmTimes.articles[articleID].votes getRef('like_count').textContent = floGlobals.appObjects.rmTimes.articles[articleID].votes
if (!openedArticles.hasOwnProperty(articleID)) { if (!openedArticles.hasOwnProperty(articleID)) {
floCloudAPI.requestGeneralData(`article_${articleID}_votes`, { floCloudAPI.requestApplicationData(`article_${articleID}_votes`, {
lowerVectorClock: floGlobals.appObjects.rmTimes.articles[articleID].lastCountedVC + 1, lowerVectorClock: floGlobals.appObjects.rmTimes.articles[articleID].lastCountedVC + 1,
callback: (allVotes, e) => { callback: (allVotes, e) => {
console.log(allVotes)
if (firstLoad) { if (firstLoad) {
const votesAfterLastCount = floDapps.getNextGeneralData(`article_${articleID}_votes`)
for (const vote in votesAfterLastCount) {
floGlobals.appObjects.rmTimes.articles[articleID].votes += votesAfterLastCount[vote].message.voteCount || 1
}
for (const vote in allVotes) { for (const vote in allVotes) {
floGlobals.appObjects.rmTimes.articles[articleID].votes += allVotes[vote].message.voteCount || 1 floGlobals.appObjects.rmTimes.articles[articleID].votes += allVotes[vote].message.voteCount || 1
} }
@ -1757,7 +1751,7 @@
}) })
getRef('upvote_button').addEventListener('click', debounce(() => { getRef('upvote_button').addEventListener('click', debounce(() => {
if (typeof myFloID !== 'undefined') { if (typeof myFloID !== 'undefined') {
floCloudAPI.sendGeneralData({ floCloudAPI.sendApplicationData({
voteCount: tempVoteCount, voteCount: tempVoteCount,
}, `article_${pagesData.params.articleID}_votes`) }, `article_${pagesData.params.articleID}_votes`)
.then(res => { .then(res => {
@ -2230,13 +2224,13 @@
for (const articleKey in floGlobals.appObjects.rmTimes.articles) { for (const articleKey in floGlobals.appObjects.rmTimes.articles) {
if (floGlobals.appObjects.adminData.articleVotes.hasOwnProperty(articleKey) && floGlobals.appObjects.rmTimes.articles[articleKey].lastCountedVC !== '') { if (floGlobals.appObjects.adminData.articleVotes.hasOwnProperty(articleKey) && floGlobals.appObjects.rmTimes.articles[articleKey].lastCountedVC !== '') {
articlesVotesProm.push( articlesVotesProm.push(
floCloudAPI.requestGeneralData(`article_${articleKey}_votes`, { floCloudAPI.requestApplicationData(`article_${articleKey}_votes`, {
lowerVectorClock: floGlobals.appObjects.rmTimes.articles[articleKey].lastCountedVC + 1 lowerVectorClock: floGlobals.appObjects.rmTimes.articles[articleKey].lastCountedVC + 1
}) })
) )
} else { } else {
articlesVotesProm.push( articlesVotesProm.push(
floCloudAPI.requestGeneralData(`article_${articleKey}_votes`) floCloudAPI.requestApplicationData(`article_${articleKey}_votes`)
) )
} }
articleIDs.push(articleKey) articleIDs.push(articleKey)
@ -2246,11 +2240,10 @@
if (!floGlobals.appObjects.adminData.articleVotes.hasOwnProperty(articleIDs[index])) { if (!floGlobals.appObjects.adminData.articleVotes.hasOwnProperty(articleIDs[index])) {
floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes = {} floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes = {}
} }
if (floGlobals.appObjects.rmTimes.articles[articleIDs[index]].lastCountedVC === '') { articleVotes.forEach(vote => {
articleVotes = floGlobals.generalData[`article_${articleIDs[index]}_votes|${floGlobals.adminID}|${floGlobals.application}`] console.log(vote)
} const { senderID, message, type, vectorClock, time } = vote;
for (const voteKey in articleVotes) { const { voteCount } = floCloudAPI.util.decodeMessage(message)
const { senderID, message: { voteCount }, type, vectorClock, time } = articleVotes[voteKey]
const { votes } = floGlobals.appObjects.adminData.articleVotes[articleIDs[index]]; const { votes } = floGlobals.appObjects.adminData.articleVotes[articleIDs[index]];
if (votes[senderID]) { if (votes[senderID]) {
floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[senderID] += voteCount || 1 floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[senderID] += voteCount || 1
@ -2258,7 +2251,7 @@
floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[senderID] = voteCount || 1 floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[senderID] = voteCount || 1
} }
floGlobals.appObjects.rmTimes.articles[articleIDs[index]].lastCountedVC = vectorClock floGlobals.appObjects.rmTimes.articles[articleIDs[index]].lastCountedVC = vectorClock
} })
let totalArticleVotes = 0 let totalArticleVotes = 0
for (const voter in floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes) { for (const voter in floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes) {
totalArticleVotes += floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[voter] totalArticleVotes += floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[voter]
@ -2273,10 +2266,14 @@
}).catch(err => { }).catch(err => {
console.error(err) console.error(err)
}) })
}).catch(err => {
console.error(err)
}) })
Promise.all([compactIDB.readData('appObjects', 'articlesContent'), compactIDB.readData('appObjects', 'heroImages')]).then(res => { Promise.all([compactIDB.readData('appObjects', 'articlesContent'), compactIDB.readData('appObjects', 'heroImages')]).then(([articlesContent, heroImages]) => {
floGlobals.appObjects.articlesContent = res[0]; floGlobals.appObjects.articlesContent = articlesContent;
floGlobals.appObjects.heroImages = res[1]; floGlobals.appObjects.heroImages = heroImages;
}).catch(err => {
console.error(err)
}) })
} }