2020-01-14 14:38:33 +00:00
|
|
|
const constants = require("../constants")
|
|
|
|
const {proxyImage} = require("../utils/proxyurl")
|
2020-01-12 12:50:21 +00:00
|
|
|
const Timeline = require("./Timeline")
|
2020-01-14 14:38:33 +00:00
|
|
|
require("../testimports")(constants, Timeline)
|
2020-01-12 12:50:21 +00:00
|
|
|
|
|
|
|
class User {
|
|
|
|
/**
|
|
|
|
* @param {import("../types").GraphUser} data
|
|
|
|
*/
|
|
|
|
constructor(data) {
|
|
|
|
this.data = data
|
|
|
|
this.following = data.edge_follow.count
|
|
|
|
this.followedBy = data.edge_followed_by.count
|
|
|
|
this.posts = data.edge_owner_to_timeline_media.count
|
|
|
|
this.timeline = new Timeline(this)
|
2020-01-14 14:38:33 +00:00
|
|
|
this.cachedAt = Date.now()
|
|
|
|
this.proxyProfilePicture = proxyImage(this.data.profile_pic_url)
|
|
|
|
}
|
|
|
|
|
|
|
|
getTtl(scale = 1) {
|
|
|
|
const expiresAt = this.cachedAt + constants.resource_cache_time
|
|
|
|
const ttl = expiresAt - Date.now()
|
|
|
|
return Math.ceil(Math.max(ttl, 0) / scale)
|
2020-01-12 12:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export() {
|
|
|
|
return this.data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = User
|