mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-23 04:41:14 +00:00
fix error
This commit is contained in:
parent
1830c3c1ef
commit
fef4af1fcf
1 changed files with 26 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
|||
import { myAuth } from "@utils/app";
|
||||
import { isBrowser } from "@utils/browser";
|
||||
import { poll } from "@utils/helpers";
|
||||
import { amAdmin } from "@utils/roles";
|
||||
import {
|
||||
|
@ -11,27 +12,27 @@ import { HttpService, UserService } from "../services";
|
|||
import { RequestState } from "../services/HttpService";
|
||||
|
||||
export class InboxService {
|
||||
#unreadInboxCountRes: RequestState<GetUnreadCountResponse>;
|
||||
#unreadReportCountRes: RequestState<GetReportCountResponse>;
|
||||
#unreadApplicationCountRes: RequestState<GetUnreadRegistrationApplicationCountResponse>;
|
||||
|
||||
static #instance: InboxService;
|
||||
static #_instance: InboxService;
|
||||
unreadInboxCountRes: RequestState<GetUnreadCountResponse>;
|
||||
unreadReportCountRes: RequestState<GetReportCountResponse>;
|
||||
unreadApplicationCountRes: RequestState<GetUnreadRegistrationApplicationCountResponse>;
|
||||
|
||||
private constructor() {
|
||||
this.#unreadInboxCountRes = { state: "empty" };
|
||||
this.#unreadReportCountRes = { state: "empty" };
|
||||
this.#unreadApplicationCountRes = { state: "empty" };
|
||||
this.unreadInboxCountRes = { state: "empty" };
|
||||
this.unreadReportCountRes = { state: "empty" };
|
||||
this.unreadApplicationCountRes = { state: "empty" };
|
||||
|
||||
this.startPoll();
|
||||
this.fetchUnreadCounts();
|
||||
}
|
||||
|
||||
static get #Instance() {
|
||||
return this.#instance ?? (this.#instance = new this());
|
||||
return this.#_instance ?? (this.#_instance = new this());
|
||||
}
|
||||
|
||||
unreadInboxCount(): number {
|
||||
if (this.#unreadInboxCountRes.state === "success") {
|
||||
const { data } = this.#unreadInboxCountRes;
|
||||
if (this.unreadInboxCountRes.state === "success") {
|
||||
const { data } = this.unreadInboxCountRes;
|
||||
return data.replies + data.mentions + data.private_messages;
|
||||
} else {
|
||||
return 0;
|
||||
|
@ -39,12 +40,12 @@ export class InboxService {
|
|||
}
|
||||
|
||||
public static get unreadInboxCount(): number {
|
||||
return this.#instance.unreadInboxCount();
|
||||
return this.#Instance.unreadInboxCount();
|
||||
}
|
||||
|
||||
unreadReportCount(): number {
|
||||
if (this.#unreadReportCountRes.state === "success") {
|
||||
const { data } = this.#unreadReportCountRes;
|
||||
if (this.unreadReportCountRes.state === "success") {
|
||||
const { data } = this.unreadReportCountRes;
|
||||
return (
|
||||
data.post_reports +
|
||||
data.comment_reports +
|
||||
|
@ -56,19 +57,19 @@ export class InboxService {
|
|||
}
|
||||
|
||||
public static get unreadReportCount(): number {
|
||||
return this.#instance.unreadReportCount();
|
||||
return this.#Instance.unreadReportCount();
|
||||
}
|
||||
|
||||
unreadApplicationCount(): number {
|
||||
if (this.#unreadApplicationCountRes.state === "success") {
|
||||
return this.#unreadApplicationCountRes.data.registration_applications;
|
||||
if (this.unreadApplicationCountRes.state === "success") {
|
||||
return this.unreadApplicationCountRes.data.registration_applications;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static get unreadApplicationCount(): number {
|
||||
return this.#instance.unreadApplicationCount();
|
||||
return this.#Instance.unreadApplicationCount();
|
||||
}
|
||||
|
||||
get isModerator(): boolean {
|
||||
|
@ -78,6 +79,10 @@ export class InboxService {
|
|||
}
|
||||
|
||||
startPoll() {
|
||||
if (!isBrowser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
poll(async () => {
|
||||
if (window.document.visibilityState === "hidden") {
|
||||
return;
|
||||
|
@ -91,18 +96,18 @@ export class InboxService {
|
|||
const auth = myAuth();
|
||||
|
||||
if (auth) {
|
||||
this.#unreadInboxCountRes = await HttpService.client.getUnreadCount({
|
||||
this.unreadInboxCountRes = await HttpService.client.getUnreadCount({
|
||||
auth,
|
||||
});
|
||||
|
||||
if (this.isModerator) {
|
||||
this.#unreadReportCountRes = await HttpService.client.getReportCount({
|
||||
this.unreadReportCountRes = await HttpService.client.getReportCount({
|
||||
auth,
|
||||
});
|
||||
}
|
||||
|
||||
if (amAdmin()) {
|
||||
this.#unreadApplicationCountRes =
|
||||
this.unreadApplicationCountRes =
|
||||
await HttpService.client.getUnreadRegistrationApplicationCount({
|
||||
auth,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue