Add support for private users
parent
b26c5de21b
commit
7dcb49c6a5
|
@ -7,7 +7,7 @@ import luxon from "luxon";
|
|||
// Modules from files
|
||||
import { urls } from "../../constants/url.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.
|
||||
|
@ -28,6 +28,7 @@ export default class PlatformUser {
|
|||
private _lastSeen: Date;
|
||||
private _followed: boolean;
|
||||
private _ignored: boolean;
|
||||
private _private: boolean;
|
||||
private _avatar: string;
|
||||
private _amountDonated: number;
|
||||
|
||||
|
@ -83,6 +84,10 @@ export default class PlatformUser {
|
|||
* Indicates whether the user is ignored by the currently logged on user.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -116,6 +121,12 @@ export default class PlatformUser {
|
|||
// Prepare cheerio
|
||||
const $ = cheerio.load(htmlResponse.value);
|
||||
|
||||
// Check if the profile is private
|
||||
this._private = $(GENERIC.ERROR_BANNER)
|
||||
?.text()
|
||||
.trim() === "This member limits who may view their full profile.";
|
||||
|
||||
if (!this._private) {
|
||||
// Parse the elements
|
||||
this._name = $(MEMBER.NAME).text();
|
||||
this._title = $(MEMBER.TITLE).text();
|
||||
|
@ -138,7 +149,7 @@ export default class PlatformUser {
|
|||
// Parse donation
|
||||
const donation = $(MEMBER.AMOUNT_DONATED)?.text().replace("$", "");
|
||||
this._amountDonated = donation ? parseInt(donation) : 0;
|
||||
|
||||
}
|
||||
} else throw htmlResponse.value;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@ export const GENERIC = {
|
|||
* the platform in the attribute `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 = {
|
||||
|
|
Loading…
Reference in New Issue