Upgrade for lemmy js client 0.19.0-alpha.16 (#2210)

* Use `auth` cookie set by backend instead of `jwt` (fixes #2193)

Requires https://github.com/LemmyNet/lemmy-js-client/pull/208

* Revert "Use `auth` cookie set by backend instead of `jwt` (fixes #2193)"

This reverts commit 442766c1d8.

* Updating for new lemmy-js-client.

---------

Co-authored-by: Felix Ableitner <me@nutomic.com>
This commit is contained in:
Dessalines 2023-11-03 10:00:25 -04:00 committed by GitHub
parent acfcd86b9b
commit c3a57b114c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 38 additions and 83 deletions

@ -1 +1 @@
Subproject commit 6b373bf7665ed58a81d8285009ad147248acfd7c
Subproject commit abd40d4737fa732321fd7b62e42bbfcd51081cb6

View file

@ -70,7 +70,7 @@
"inferno-router": "^8.2.2",
"inferno-server": "^8.2.2",
"jwt-decode": "^3.1.2",
"lemmy-js-client": "0.19.0-rc.14",
"lemmy-js-client": "0.19.0-alpha.16",
"lodash.isequal": "^4.5.0",
"markdown-it": "^13.0.1",
"markdown-it-bidi": "^0.1.0",

View file

@ -56,6 +56,7 @@ export class CommentReport extends Component<
post: r.post,
community: r.community,
creator_banned_from_community: r.creator_banned_from_community,
creator_is_moderator: false,
counts: r.counts,
subscribed: "NotSubscribed",
saved: false,

View file

@ -57,12 +57,10 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PaginationCursor,
PostResponse,
PurgeComment,
PurgeCommunity,
PurgeItemResponse,
PurgePerson,
PurgePost,
RemoveComment,
@ -71,6 +69,7 @@ import {
SaveComment,
SavePost,
SortType,
SuccessResponse,
TransferCommunity,
} from "lemmy-js-client";
import { fetchLimit, relTags } from "../../config";
@ -198,7 +197,6 @@ export class Community extends Component<
this.handleSavePost = this.handleSavePost.bind(this);
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);
this.mainContentRef = createRef();
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
@ -436,7 +434,7 @@ export class Community extends Component<
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
onMarkPostAsRead={() => {}}
/>
);
}
@ -804,11 +802,6 @@ export class Community extends Component<
await HttpService.client.markPersonMentionAsRead(form);
}
async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.findAndUpdatePost(res);
}
async handleBanFromCommunity(form: BanFromCommunity) {
const banRes = await HttpService.client.banFromCommunity(form);
this.updateBanFromCommunity(banRes);
@ -882,7 +875,7 @@ export class Community extends Component<
});
}
purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
purgeItem(purgeRes: RequestState<SuccessResponse>) {
if (purgeRes.state === "success") {
toast(I18NextService.i18n.t("purge_success"));
this.context.router.history.push(`/`);

View file

@ -359,7 +359,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
async handleDeleteEmoji(form: DeleteCustomEmoji) {
const res = await HttpService.client.deleteCustomEmoji(form);
if (res.state === "success") {
removeFromEmojiDataModel(res.data.id);
removeFromEmojiDataModel(form.id);
}
}

View file

@ -58,11 +58,9 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PaginationCursor,
PostResponse,
PurgeComment,
PurgeItemResponse,
PurgePerson,
PurgePost,
RemoveComment,
@ -70,6 +68,7 @@ import {
SaveComment,
SavePost,
SortType,
SuccessResponse,
TransferCommunity,
} from "lemmy-js-client";
import { fetchLimit, relTags, trendingFetchLimit } from "../../config";
@ -276,7 +275,6 @@ export class Home extends Component<any, HomeState> {
this.handleSavePost = this.handleSavePost.bind(this);
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
@ -713,7 +711,7 @@ export class Home extends Component<any, HomeState> {
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
onMarkPostAsRead={() => {}}
/>
);
}
@ -1043,11 +1041,6 @@ export class Home extends Component<any, HomeState> {
this.updateBan(banRes);
}
async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.findAndUpdatePost(res);
}
updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
// Maybe not necessary
if (banRes.state === "success") {
@ -1090,7 +1083,7 @@ export class Home extends Component<any, HomeState> {
}
}
purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
purgeItem(purgeRes: RequestState<SuccessResponse>) {
if (purgeRes.state === "success") {
toast(I18NextService.i18n.t("purge_success"));
this.context.router.history.push(`/`);

View file

@ -52,11 +52,11 @@ import {
PrivateMessageView,
PrivateMessagesResponse,
PurgeComment,
PurgeItemResponse,
PurgePerson,
PurgePost,
RemoveComment,
SaveComment,
SuccessResponse,
TransferCommunity,
} from "lemmy-js-client";
import { fetchLimit, relTags } from "../../config";
@ -1038,7 +1038,7 @@ export class Inbox extends Component<any, InboxState> {
}
}
purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
purgeItem(purgeRes: RequestState<SuccessResponse>) {
if (purgeRes.state === "success") {
toast(I18NextService.i18n.t("purge_success"));
this.context.router.history.push(`/`);

View file

@ -1,7 +1,7 @@
import { setIsoData } from "@utils/app";
import { capitalizeFirstLetter } from "@utils/helpers";
import { Component, linkEvent } from "inferno";
import { GetSiteResponse, LoginResponse } from "lemmy-js-client";
import { GetSiteResponse, SuccessResponse } from "lemmy-js-client";
import { HttpService, I18NextService, UserService } from "../../services";
import {
EMPTY_REQUEST,
@ -11,9 +11,10 @@ import {
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
import PasswordInput from "../common/password-input";
import { toast } from "../../toast";
interface State {
passwordChangeRes: RequestState<LoginResponse>;
passwordChangeRes: RequestState<SuccessResponse>;
form: {
token: string;
password?: string;
@ -125,10 +126,7 @@ export class PasswordChange extends Component<any, State> {
});
if (i.state.passwordChangeRes.state === "success") {
const data = i.state.passwordChangeRes.data;
UserService.Instance.login({
res: data,
});
toast(I18NextService.i18n.t("password_changed"));
const site = await HttpService.client.getSite();
if (site.state === "success") {

View file

@ -58,11 +58,9 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PersonView,
PostResponse,
PurgeComment,
PurgeItemResponse,
PurgePerson,
PurgePost,
RemoveComment,
@ -70,6 +68,7 @@ import {
SaveComment,
SavePost,
SortType,
SuccessResponse,
TransferCommunity,
} from "lemmy-js-client";
import { fetchLimit, relTags } from "../../config";
@ -222,7 +221,6 @@ export class Profile extends Component<
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleModBanSubmit = this.handleModBanSubmit.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
@ -378,7 +376,7 @@ export class Profile extends Component<
onSavePost={this.handleSavePost}
onPurgePost={this.handlePurgePost}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
onMarkPostAsRead={() => {}}
/>
</div>
@ -947,11 +945,6 @@ export class Profile extends Component<
await HttpService.client.markPersonMentionAsRead(form);
}
async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.findAndUpdatePost(res);
}
async handleBanFromCommunity(form: BanFromCommunity) {
const banRes = await HttpService.client.banFromCommunity(form);
this.updateBanFromCommunity(banRes);
@ -1002,7 +995,7 @@ export class Profile extends Component<
}
}
purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
purgeItem(purgeRes: RequestState<SuccessResponse>) {
if (purgeRes.state === "success") {
toast(I18NextService.i18n.t("purge_success"));
this.context.router.history.push(`/`);

View file

@ -23,7 +23,6 @@ import {
BlockInstanceResponse,
BlockPersonResponse,
CommunityBlockView,
DeleteAccountResponse,
GenerateTotpSecretResponse,
GetFederatedInstancesResponse,
GetSiteResponse,
@ -33,6 +32,7 @@ import {
LoginResponse,
PersonBlockView,
SortType,
SuccessResponse,
UpdateTotpResponse,
} from "lemmy-js-client";
import { elementUrl, emDash, relTags } from "../../config";
@ -66,9 +66,9 @@ type SettingsData = RouteDataResponse<{
}>;
interface SettingsState {
saveRes: RequestState<LoginResponse>;
saveRes: RequestState<SuccessResponse>;
changePasswordRes: RequestState<LoginResponse>;
deleteAccountRes: RequestState<DeleteAccountResponse>;
deleteAccountRes: RequestState<SuccessResponse>;
instancesRes: RequestState<GetFederatedInstancesResponse>;
generateTotpRes: RequestState<GenerateTotpSecretResponse>;
updateTotpRes: RequestState<UpdateTotpResponse>;
@ -1436,11 +1436,6 @@ export class Settings extends Component<any, SettingsState> {
});
if (saveRes.state === "success") {
UserService.Instance.login({
res: saveRes.data,
showToast: false,
});
const siteRes = await HttpService.client.getSite();
if (siteRes.state === "success") {
@ -1471,10 +1466,6 @@ export class Settings extends Component<any, SettingsState> {
old_password,
});
if (changePasswordRes.state === "success") {
UserService.Instance.login({
res: changePasswordRes.data,
showToast: false,
});
window.scrollTo(0, 0);
toast(I18NextService.i18n.t("password_changed"));
}

View file

@ -1,6 +1,6 @@
import { setIsoData } from "@utils/app";
import { Component } from "inferno";
import { GetSiteResponse, VerifyEmailResponse } from "lemmy-js-client";
import { GetSiteResponse, SuccessResponse } from "lemmy-js-client";
import { I18NextService } from "../../services";
import {
EMPTY_REQUEST,
@ -13,7 +13,7 @@ import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
interface State {
verifyRes: RequestState<VerifyEmailResponse>;
verifyRes: RequestState<SuccessResponse>;
siteRes: GetSiteResponse;
}

View file

@ -56,6 +56,7 @@ export class PostReport extends Component<PostReportProps, PostReportState> {
creator_blocked: false,
my_vote: r.my_vote,
unread_comments: 0,
creator_is_moderator: false,
};
return (

View file

@ -61,12 +61,9 @@ import {
GetSiteResponse,
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PostResponse,
PurgeComment,
PurgeCommunity,
PurgeItemResponse,
PurgePerson,
PurgePost,
RemoveComment,
@ -74,6 +71,7 @@ import {
RemovePost,
SaveComment,
SavePost,
SuccessResponse,
TransferCommunity,
} from "lemmy-js-client";
import { commentTreeMaxDepth } from "../../config";
@ -164,7 +162,6 @@ export class Post extends Component<any, PostState> {
this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
this.handleFetchChildren = this.handleFetchChildren.bind(this);
this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
this.handleBanPerson = this.handleBanPerson.bind(this);
this.handlePostEdit = this.handlePostEdit.bind(this);
@ -176,7 +173,6 @@ export class Post extends Component<any, PostState> {
this.handleSavePost = this.handleSavePost.bind(this);
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);
this.state = { ...this.state, commentSectionRef: createRef() };
@ -387,7 +383,7 @@ export class Post extends Component<any, PostState> {
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
onMarkPostAsRead={() => {}}
/>
<div ref={this.state.commentSectionRef} className="mb-2" />
@ -589,7 +585,7 @@ export class Post extends Component<any, PostState> {
onPurgeComment={this.handlePurgeComment}
onPurgePerson={this.handlePurgePerson}
onCommentReplyRead={this.handleCommentReplyRead}
onPersonMentionRead={this.handlePersonMentionRead}
onPersonMentionRead={() => {}}
onBanPersonFromCommunity={this.handleBanFromCommunity}
onBanPerson={this.handleBanPerson}
onCreateComment={this.handleCreateComment}
@ -676,7 +672,7 @@ export class Post extends Component<any, PostState> {
onPurgeComment={this.handlePurgeComment}
onPurgePerson={this.handlePurgePerson}
onCommentReplyRead={this.handleCommentReplyRead}
onPersonMentionRead={this.handlePersonMentionRead}
onPersonMentionRead={() => {}}
onBanPersonFromCommunity={this.handleBanFromCommunity}
onBanPerson={this.handleBanPerson}
onCreateComment={this.handleCreateComment}
@ -936,16 +932,6 @@ export class Post extends Component<any, PostState> {
this.findAndUpdateCommentReply(readRes);
}
async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
// TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
await HttpService.client.markPersonMentionAsRead(form);
}
async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.updatePost(res);
}
async handleBanFromCommunity(form: BanFromCommunity) {
const banRes = await HttpService.client.banFromCommunity(form);
this.updateBan(banRes);
@ -1029,7 +1015,7 @@ export class Post extends Component<any, PostState> {
});
}
purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
purgeItem(purgeRes: RequestState<SuccessResponse>) {
if (purgeRes.state === "success") {
toast(I18NextService.i18n.t("purge_success"));
this.context.router.history.push(`/`);

View file

@ -665,10 +665,10 @@ export class Search extends Component<any, SearchState> {
Number(
((b.data as CommentView | PostView).counts.score |
(b.data as CommunityView).counts.subscribers |
(b.data as PersonView).counts.comment_score) -
(b.data as PersonView).counts.comment_count) -
((a.data as CommentView | PostView).counts.score |
(a.data as CommunityView).counts.subscribers |
(a.data as PersonView).counts.comment_score),
(a.data as PersonView).counts.comment_count),
),
);
}

View file

@ -35,9 +35,6 @@ export class UserService {
res: LoginResponse;
showToast?: boolean;
}) {
const expires = new Date();
expires.setDate(expires.getDate() + 365);
if (isBrowser() && res.jwt) {
showToast && toast(I18NextService.i18n.t("logged_in"));
setAuthCookie(res.jwt);
@ -53,6 +50,8 @@ export class UserService {
clearAuthCookie();
}
HttpService.client.logout();
if (isAuthPath(location.pathname)) {
location.replace("/");
} else {

View file

@ -6069,10 +6069,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.19.0-rc.14:
version "0.19.0-rc.14"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.14.tgz#41885611c2d78e5cb6b01cf167d68205a471c215"
integrity sha512-U0KKFLrU0K+A7UlZr+k4olrXCXBxD+9cwMicu7L/wFyZ2aWHtGPaeO8V6mk6suv9vn2w2PWuimIIC+YICQ5xKg==
lemmy-js-client@0.19.0-alpha.16:
version "0.19.0-alpha.16"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-alpha.16.tgz#4ec26e393856db7ddf86dba83f24633eeacee7c4"
integrity sha512-pmfrkPrHBkhEFhw/BDiTPy2/aQLoURLwBftMa4Lc+ZYiRfVClCOPkbKiqDSYXYlWcPz5MtwM/bjSNxasvVHfTA==
dependencies:
cross-fetch "^3.1.5"
form-data "^4.0.0"