From d56d20d0beae9401a9131a367201fef435387b26 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Mon, 15 May 2023 15:22:35 +0000 Subject: [PATCH 1/3] Redirect from pages that require auth on logout (#1016) * Redirect fomr pages that require auth on logout * Extract helper function --------- Co-authored-by: Dessalines --- src/shared/services/UserService.ts | 8 ++++++-- src/shared/utils.ts | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index e4ec5f98..16540f23 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -5,7 +5,7 @@ import { LoginResponse, MyUserInfo } from "lemmy-js-client"; import { BehaviorSubject } from "rxjs"; import { isHttps } from "../env"; import { i18n } from "../i18next"; -import { isBrowser, toast } from "../utils"; +import { isAuthPath, isBrowser, toast } from "../utils"; interface Claims { sub: number; @@ -48,7 +48,11 @@ export class UserService { this.myUserInfo = undefined; IsomorphicCookie.remove("jwt"); // TODO is sometimes unreliable for some reason document.cookie = "jwt=; Max-Age=0; path=/; domain=" + location.hostname; - location.reload(); + if (isAuthPath(location.pathname)) { + location.replace("/"); + } else { + location.reload(); + } } public auth(throwErr = true): string | undefined { diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 4e5f74b4..d65d2d37 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -1589,3 +1589,9 @@ export function getQueryString>( "?" ); } + +export function isAuthPath(pathname: string) { + return /create_.*|inbox|settings|setup|admin|reports|registration_applications/g.test( + pathname + ); +} From 6ac5435fe9f53bbbb8843d08220fa677b8247cc3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 15 May 2023 14:39:11 -0400 Subject: [PATCH 2/3] Upgrade lemmy-js-client to work with bigints. Fixes #1018 (#1022) --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 332b888d..c9a19c2f 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "inferno-server": "^8.1.1", "isomorphic-cookie": "^1.2.4", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.17.2-rc.15", + "lemmy-js-client": "0.17.2-rc.16", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^2.0.2", diff --git a/yarn.lock b/yarn.lock index 62da0d1e..476dab1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5334,10 +5334,10 @@ leac@^0.6.0: resolved "https://registry.yarnpkg.com/leac/-/leac-0.6.0.tgz#dcf136e382e666bd2475f44a1096061b70dc0912" integrity sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg== -lemmy-js-client@0.17.2-rc.15: - version "0.17.2-rc.15" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.15.tgz#a3b10227913c4dc12fa7b69cdc777e429d030721" - integrity sha512-hnHW/570mQGoGNdnUaNp20+KVkyUnosaFLmWxlZyyhL7fiSbcIXM+GXsjTCqmc1JEnqASc6MdMMpYuZaBKVQtQ== +lemmy-js-client@0.17.2-rc.16: + version "0.17.2-rc.16" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.16.tgz#404c02917291e7e89fdece75b49e7dc68c73492a" + integrity sha512-plAZn7ClopgjcTGTfh4b19jF894ucMfQh54J0P2DhQIG0k1Ic0ubq0rY1WZ+9yDyup6vCXF1i5MCylfNAs5Gxw== dependencies: cross-fetch "^3.1.5" form-data "^4.0.0" From 3143788d19472b470e441f4196e56918c116a6d7 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 15 May 2023 15:53:29 -0400 Subject: [PATCH 3/3] Changing all bigints to numbers --- package.json | 2 +- src/shared/components/app/navbar.tsx | 18 +++---- .../components/comment/comment-node.tsx | 40 +++++++-------- src/shared/components/common/paginator.tsx | 10 ++-- .../components/community/communities.tsx | 8 +-- src/shared/components/community/community.tsx | 14 ++---- src/shared/components/community/sidebar.tsx | 2 +- src/shared/components/home/emojis-form.tsx | 49 ++++++++----------- src/shared/components/home/home.tsx | 18 +++---- src/shared/components/home/site-sidebar.tsx | 2 +- src/shared/components/modlog.tsx | 10 ++-- src/shared/components/person/inbox.tsx | 24 ++++----- .../components/person/person-details.tsx | 10 ++-- src/shared/components/person/profile.tsx | 8 +-- .../person/registration-applications.tsx | 12 ++--- src/shared/components/person/reports.tsx | 24 ++++----- src/shared/components/post/post-form.tsx | 4 +- src/shared/components/post/post-listing.tsx | 40 +++++++-------- src/shared/components/post/post-report.tsx | 2 +- src/shared/components/post/post.tsx | 2 +- src/shared/components/search.tsx | 18 +++---- src/shared/services/UserService.ts | 12 ++--- src/shared/utils.ts | 32 ++++++------ yarn.lock | 8 +-- 24 files changed, 175 insertions(+), 194 deletions(-) diff --git a/package.json b/package.json index c9a19c2f..2f16b8d3 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "inferno-server": "^8.1.1", "isomorphic-cookie": "^1.2.4", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.17.2-rc.16", + "lemmy-js-client": "0.17.2-rc.17", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^2.0.2", diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 448e92cb..128d4023 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -40,9 +40,9 @@ interface NavbarProps { interface NavbarState { expanded: boolean; - unreadInboxCount: bigint; - unreadReportCount: bigint; - unreadApplicationCount: bigint; + unreadInboxCount: number; + unreadReportCount: number; + unreadApplicationCount: number; showDropdown: boolean; onSiteBanner?(url: string): any; } @@ -54,9 +54,9 @@ export class Navbar extends Component { private unreadReportCountSub: Subscription; private unreadApplicationCountSub: Subscription; state: NavbarState = { - unreadInboxCount: 0n, - unreadReportCount: 0n, - unreadApplicationCount: 0n, + unreadInboxCount: 0, + unreadReportCount: 0, + unreadApplicationCount: 0, expanded: false, showDropdown: false, }; @@ -512,7 +512,7 @@ export class Navbar extends Component { unreadReportCount: data.post_reports + data.comment_reports + - (data.private_message_reports ?? 0n), + (data.private_message_reports ?? 0), }); this.sendReportUnread(); } else if (op == UserOperation.GetUnreadRegistrationApplicationCount) { @@ -528,7 +528,7 @@ export class Navbar extends Component { data.recipient_ids.includes(mui.local_user_view.local_user.id) ) { this.setState({ - unreadInboxCount: this.state.unreadInboxCount + 1n, + unreadInboxCount: this.state.unreadInboxCount + 1, }); this.sendUnreadCount(); notifyComment(data.comment_view, this.context.router); @@ -541,7 +541,7 @@ export class Navbar extends Component { UserService.Instance.myUserInfo?.local_user_view.person.id ) { this.setState({ - unreadInboxCount: this.state.unreadInboxCount + 1n, + unreadInboxCount: this.state.unreadInboxCount + 1, }); this.sendUnreadCount(); notifyPrivateMessage(data.private_message_view, this.context.router); diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index d6fe0862..d68c5b30 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -84,9 +84,9 @@ interface CommentNodeState { showReportDialog: boolean; reportReason?: string; my_vote?: number; - score: bigint; - upvotes: bigint; - downvotes: bigint; + score: number; + upvotes: number; + downvotes: number; readLoading: boolean; saveLoading: boolean; } @@ -833,9 +833,7 @@ export class CommentNode extends Component { > {i18n.t("x_more_replies", { count: node.comment_view.counts.child_count, - formattedCount: numToSI( - BigInt(node.comment_view.counts.child_count) - ), + formattedCount: numToSI(node.comment_view.counts.child_count), })}{" "} ➔ @@ -1152,19 +1150,19 @@ export class CommentNode extends Component { if (myVote == 1) { this.setState({ - score: this.state.score - 1n, - upvotes: this.state.upvotes - 1n, + score: this.state.score - 1, + upvotes: this.state.upvotes - 1, }); } else if (myVote == -1) { this.setState({ - downvotes: this.state.downvotes - 1n, - upvotes: this.state.upvotes + 1n, - score: this.state.score + 2n, + downvotes: this.state.downvotes - 1, + upvotes: this.state.upvotes + 1, + score: this.state.score + 2, }); } else { this.setState({ - score: this.state.score + 1n, - upvotes: this.state.upvotes + 1n, + score: this.state.score + 1, + upvotes: this.state.upvotes + 1, }); } @@ -1189,19 +1187,19 @@ export class CommentNode extends Component { if (myVote == 1) { this.setState({ - downvotes: this.state.downvotes + 1n, - upvotes: this.state.upvotes - 1n, - score: this.state.score - 2n, + downvotes: this.state.downvotes + 1, + upvotes: this.state.upvotes - 1, + score: this.state.score - 2, }); } else if (myVote == -1) { this.setState({ - downvotes: this.state.downvotes - 1n, - score: this.state.score + 1n, + downvotes: this.state.downvotes - 1, + score: this.state.score + 1, }); } else { this.setState({ - downvotes: this.state.downvotes + 1n, - score: this.state.score - 1n, + downvotes: this.state.downvotes + 1, + score: this.state.score - 1, }); } @@ -1542,7 +1540,7 @@ export class CommentNode extends Component { post_id: i.props.node.comment_view.post.id, parent_id: i.props.node.comment_view.comment.id, max_depth: commentTreeMaxDepth, - limit: 999n, // TODO + limit: 999, // TODO type_: "All", saved_only: false, auth: myAuth(false), diff --git a/src/shared/components/common/paginator.tsx b/src/shared/components/common/paginator.tsx index 2c877575..75acde3e 100644 --- a/src/shared/components/common/paginator.tsx +++ b/src/shared/components/common/paginator.tsx @@ -2,8 +2,8 @@ import { Component, linkEvent } from "inferno"; import { i18n } from "../../i18next"; interface PaginatorProps { - page: bigint; - onChange(val: bigint): any; + page: number; + onChange(val: number): any; } export class Paginator extends Component { @@ -15,7 +15,7 @@ export class Paginator extends Component {