Add support for private users
parent
b26c5de21b
commit
7dcb49c6a5
|
@ -7,7 +7,7 @@ import luxon from "luxon";
|
||||||
// Modules from files
|
// Modules from files
|
||||||
import { urls } from "../../constants/url.js";
|
import { urls } from "../../constants/url.js";
|
||||||
import { fetchHTML } from "../../network-helper.js";
|
import { fetchHTML } from "../../network-helper.js";
|
||||||
import { MEMBER } from "../../constants/css-selector.js";
|
import { GENERIC, MEMBER } from "../../constants/css-selector.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a generic user registered on the platform.
|
* Represents a generic user registered on the platform.
|
||||||
|
@ -28,6 +28,7 @@ export default class PlatformUser {
|
||||||
private _lastSeen: Date;
|
private _lastSeen: Date;
|
||||||
private _followed: boolean;
|
private _followed: boolean;
|
||||||
private _ignored: boolean;
|
private _ignored: boolean;
|
||||||
|
private _private: boolean;
|
||||||
private _avatar: string;
|
private _avatar: string;
|
||||||
private _amountDonated: number;
|
private _amountDonated: number;
|
||||||
|
|
||||||
|
@ -83,6 +84,10 @@ export default class PlatformUser {
|
||||||
* Indicates whether the user is ignored by the currently logged on user.
|
* Indicates whether the user is ignored by the currently logged on user.
|
||||||
*/
|
*/
|
||||||
public get ignored() { return this._ignored; }
|
public get ignored() { return this._ignored; }
|
||||||
|
/**
|
||||||
|
* Indicates that the profile is private and not viewable by the user.
|
||||||
|
*/
|
||||||
|
public get private() { return this._private; }
|
||||||
/**
|
/**
|
||||||
* URL of the image used as the user's avatar.
|
* URL of the image used as the user's avatar.
|
||||||
*/
|
*/
|
||||||
|
@ -116,29 +121,35 @@ export default class PlatformUser {
|
||||||
// Prepare cheerio
|
// Prepare cheerio
|
||||||
const $ = cheerio.load(htmlResponse.value);
|
const $ = cheerio.load(htmlResponse.value);
|
||||||
|
|
||||||
// Parse the elements
|
// Check if the profile is private
|
||||||
this._name = $(MEMBER.NAME).text();
|
this._private = $(GENERIC.ERROR_BANNER)
|
||||||
this._title = $(MEMBER.TITLE).text();
|
?.text()
|
||||||
this._banners = $(MEMBER.BANNERS).toArray().map((el, idx) => $(el).text().trim()).filter(el => el);
|
.trim() === "This member limits who may view their full profile.";
|
||||||
this._avatar = $(MEMBER.AVATAR).attr("src");
|
|
||||||
this._followed = $(MEMBER.FOLLOWED).text() === "Unfollow";
|
|
||||||
this._ignored = $(MEMBER.IGNORED).text() === "Unignore";
|
|
||||||
this._messages = parseInt($(MEMBER.MESSAGES).text());
|
|
||||||
this._reactionScore = parseInt($(MEMBER.REACTION_SCORE).text());
|
|
||||||
this._points = parseInt($(MEMBER.POINTS).text());
|
|
||||||
this._ratingsReceived = parseInt($(MEMBER.RATINGS_RECEIVED).text());
|
|
||||||
|
|
||||||
// Parse date
|
|
||||||
const joined = $(MEMBER.JOINED)?.attr("datetime");
|
|
||||||
if (luxon.DateTime.fromISO(joined).isValid) this._joined = new Date(joined);
|
|
||||||
|
|
||||||
const lastSeen = $(MEMBER.LAST_SEEN)?.attr("datetime");
|
if (!this._private) {
|
||||||
if (luxon.DateTime.fromISO(lastSeen).isValid) this._joined = new Date(lastSeen);
|
// Parse the elements
|
||||||
|
this._name = $(MEMBER.NAME).text();
|
||||||
|
this._title = $(MEMBER.TITLE).text();
|
||||||
|
this._banners = $(MEMBER.BANNERS).toArray().map((el, idx) => $(el).text().trim()).filter(el => el);
|
||||||
|
this._avatar = $(MEMBER.AVATAR).attr("src");
|
||||||
|
this._followed = $(MEMBER.FOLLOWED).text() === "Unfollow";
|
||||||
|
this._ignored = $(MEMBER.IGNORED).text() === "Unignore";
|
||||||
|
this._messages = parseInt($(MEMBER.MESSAGES).text());
|
||||||
|
this._reactionScore = parseInt($(MEMBER.REACTION_SCORE).text());
|
||||||
|
this._points = parseInt($(MEMBER.POINTS).text());
|
||||||
|
this._ratingsReceived = parseInt($(MEMBER.RATINGS_RECEIVED).text());
|
||||||
|
|
||||||
// Parse donation
|
// Parse date
|
||||||
const donation = $(MEMBER.AMOUNT_DONATED)?.text().replace("$", "");
|
const joined = $(MEMBER.JOINED)?.attr("datetime");
|
||||||
this._amountDonated = donation ? parseInt(donation) : 0;
|
if (luxon.DateTime.fromISO(joined).isValid) this._joined = new Date(joined);
|
||||||
|
|
||||||
|
const lastSeen = $(MEMBER.LAST_SEEN)?.attr("datetime");
|
||||||
|
if (luxon.DateTime.fromISO(lastSeen).isValid) this._joined = new Date(lastSeen);
|
||||||
|
|
||||||
|
// Parse donation
|
||||||
|
const donation = $(MEMBER.AMOUNT_DONATED)?.text().replace("$", "");
|
||||||
|
this._amountDonated = donation ? parseInt(donation) : 0;
|
||||||
|
}
|
||||||
} else throw htmlResponse.value;
|
} else throw htmlResponse.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@ export const GENERIC = {
|
||||||
* the platform in the attribute `data-user-id`.
|
* the platform in the attribute `data-user-id`.
|
||||||
*/
|
*/
|
||||||
CURRENT_USER_ID: "span.avatar[data-user-id]",
|
CURRENT_USER_ID: "span.avatar[data-user-id]",
|
||||||
|
/**
|
||||||
|
* Banner containing any error messages as text.
|
||||||
|
*/
|
||||||
|
ERROR_BANNER: "div.p-body-pageContent > div.blockMessage",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WATCHED_THREAD = {
|
export const WATCHED_THREAD = {
|
||||||
|
|
Loading…
Reference in New Issue