bibliogram/src/lib/structures/ReelUser.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-02-02 13:24:14 +00:00
const constants = require("../constants")
2020-04-04 14:57:31 +00:00
const {proxyProfilePic} = require("../utils/proxyurl")
const {structure} = require("../utils/structuretext")
2020-02-02 13:24:14 +00:00
const Timeline = require("./Timeline")
require("../testimports")(constants, Timeline)
class ReelUser {
constructor(data) {
/** @type {import("../types").GraphUser} */
2020-02-02 13:24:14 +00:00
this.data = data
this.fromReel = true
this.posts = 0
this.following = data.edge_follow ? data.edge_follow.count : 0
this.followedBy = data.edge_followed_by ? data.edge_followed_by.count : 0
2020-02-18 00:39:20 +00:00
/** @type {import("./Timeline")} */
2020-02-02 13:24:14 +00:00
this.timeline = new Timeline(this)
this.cachedAt = Date.now()
2020-04-04 14:57:31 +00:00
this.computeProxyProfilePic()
}
computeProxyProfilePic() {
this.proxyProfilePicture = proxyProfilePic(this.data.profile_pic_url, this.data.id)
2020-02-02 13:24:14 +00:00
}
2020-02-18 00:39:20 +00:00
getStructuredBio() {
if (!this.data.biography) return null
return structure(this.data.biography)
2020-02-18 00:39:20 +00:00
}
2020-02-02 13:24:14 +00:00
getTtl(scale = 1) {
const expiresAt = this.cachedAt + constants.caching.resource_cache_time
const ttl = expiresAt - Date.now()
return Math.ceil(Math.max(ttl, 0) / scale)
}
export() {
return this.data
}
}
module.exports = ReelUser