Automatically update whether profiles are private

This commit is contained in:
Cadence Ember 2020-06-16 02:09:40 +12:00
parent 3cbe4647e1
commit a8ca233027
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412
2 changed files with 19 additions and 13 deletions

View File

@ -1,6 +1,6 @@
const {Feed} = require("feed")
const constants = require("../constants")
const config = require("../../../config")
const db = require("../db")
const TimelineEntry = require("./TimelineEntry")
const InstaCache = require("../cache")
const collectors = require("../collectors")
@ -50,6 +50,15 @@ class Timeline {
}
addPage(page) {
// update whether the user should be private
if (this.pages.length === 0 && page.count > 0) { // this is the first page, and user has posted
const shouldBePrivate = page.edges.length === 0
if (shouldBePrivate !== this.user.data.is_private) {
db.prepare("UPDATE Users SET is_private = ? WHERE user_id = ?").run(+shouldBePrivate, this.user.data.id)
this.user.data.is_private = shouldBePrivate
}
}
// add the page
this.pages.push(transformEdges(page.edges))
this.page_info = page.page_info
this.user.posts = page.count

View File

@ -78,18 +78,15 @@ html
- const hasPosts = !user.data.is_private && user.timeline.pages.length && user.timeline.pages[0].length
main(class=hasPosts ? "" : "no-posts")#timeline.timeline
if !user.data.is_private
if hasPosts
each page, pageIndex in user.timeline.pages
+timeline_page(page, pageIndex)
+next_page_button(user, url)
else
div
div.page-number
span.number No posts.
if hasPosts
each page, pageIndex in user.timeline.pages
+timeline_page(page, pageIndex)
+next_page_button(user, url)
else
div
div.page-number
span.number Profile is private.
span.number
if user.data.is_private
| Profile is private.
else
| No posts.