1 import { NoOptionI18nKeys } from "i18next";
2 import { Component, linkEvent } from "inferno";
5 BlockCommunityResponse,
20 } from "lemmy-js-client";
21 import { Subscription } from "rxjs";
22 import { i18n, languages } from "../../i18next";
23 import { UserService, WebSocketService } from "../../services";
26 capitalizeFirstLetter,
49 import { HtmlTags } from "../common/html-tags";
50 import { Icon, Spinner } from "../common/icon";
51 import { ImageUploadForm } from "../common/image-upload-form";
52 import { LanguageSelect } from "../common/language-select";
53 import { ListingTypeSelect } from "../common/listing-type-select";
54 import { MarkdownTextArea } from "../common/markdown-textarea";
55 import { SearchableSelect } from "../common/searchable-select";
56 import { SortSelect } from "../common/sort-select";
57 import { CommunityLink } from "../community/community-link";
58 import { PersonListing } from "./person-listing";
60 interface SettingsState {
61 // TODO redo these forms
62 saveUserSettingsForm: {
65 default_sort_type?: SortType;
66 default_listing_type?: ListingType;
67 interface_language?: string;
70 display_name?: string;
73 matrix_user_id?: string;
74 show_avatars?: boolean;
75 show_scores?: boolean;
76 send_notifications_to_email?: boolean;
77 bot_account?: boolean;
78 show_bot_accounts?: boolean;
79 show_read_posts?: boolean;
80 show_new_post_notifs?: boolean;
81 discussion_languages?: number[];
82 generate_totp_2fa?: boolean;
85 new_password?: string;
86 new_password_verify?: string;
87 old_password?: string;
92 personBlocks: PersonBlockView[];
93 communityBlocks: CommunityBlockView[];
96 saveUserSettingsLoading: boolean;
97 changePasswordLoading: boolean;
98 deleteAccountLoading: boolean;
99 deleteAccountShowConfirm: boolean;
100 siteRes: GetSiteResponse;
101 searchCommunityLoading: boolean;
102 searchCommunityOptions: Choice[];
103 searchPersonLoading: boolean;
104 searchPersonOptions: Choice[];
107 type FilterType = "user" | "community";
116 filterType: FilterType;
118 onSearch: (text: string) => void;
119 onChange: (choice: Choice) => void;
122 <div className="form-group row">
124 className="col-md-4 col-form-label"
125 htmlFor={`block-${filterType}-filter`}
127 {i18n.t(`block_${filterType}` as NoOptionI18nKeys)}
129 <div className="col-md-8">
131 id={`block-${filterType}-filter`}
133 { label: emDash, value: "0", disabled: true } as Choice,
143 export class Settings extends Component<any, SettingsState> {
144 private isoData = setIsoData(this.context);
145 private subscription?: Subscription;
146 state: SettingsState = {
147 saveUserSettingsForm: {},
148 changePasswordForm: {},
149 saveUserSettingsLoading: false,
150 changePasswordLoading: false,
151 deleteAccountLoading: false,
152 deleteAccountShowConfirm: false,
153 deleteAccountForm: {},
156 currentTab: "settings",
157 siteRes: this.isoData.site_res,
159 searchCommunityLoading: false,
160 searchCommunityOptions: [],
161 searchPersonLoading: false,
162 searchPersonOptions: [],
165 constructor(props: any, context: any) {
166 super(props, context);
168 this.handleSortTypeChange = this.handleSortTypeChange.bind(this);
169 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
170 this.handleBioChange = this.handleBioChange.bind(this);
171 this.handleDiscussionLanguageChange =
172 this.handleDiscussionLanguageChange.bind(this);
174 this.handleAvatarUpload = this.handleAvatarUpload.bind(this);
175 this.handleAvatarRemove = this.handleAvatarRemove.bind(this);
177 this.handleBannerUpload = this.handleBannerUpload.bind(this);
178 this.handleBannerRemove = this.handleBannerRemove.bind(this);
180 this.parseMessage = this.parseMessage.bind(this);
181 this.subscription = wsSubscribe(this.parseMessage);
183 const mui = UserService.Instance.myUserInfo;
190 default_listing_type,
196 show_new_post_notifs,
197 send_notifications_to_email,
208 } = mui.local_user_view;
212 personBlocks: mui.person_blocks,
213 communityBlocks: mui.community_blocks,
214 saveUserSettingsForm: {
215 ...this.state.saveUserSettingsForm,
217 theme: theme ?? "browser",
219 default_listing_type,
221 discussion_languages: mui.discussion_languages,
230 show_new_post_notifs,
233 send_notifications_to_email,
240 async componentDidMount() {
242 this.setState({ themeList: await fetchThemeList() });
245 componentWillUnmount() {
246 this.subscription?.unsubscribe();
249 get documentTitle(): string {
250 return i18n.t("settings");
255 <div className="container-lg">
258 title={this.documentTitle}
259 path={this.context.router.route.match.url}
260 description={this.documentTitle}
261 image={this.state.saveUserSettingsForm.avatar}
263 <ul className="nav nav-tabs mb-2">
264 <li className="nav-item">
266 className={`nav-link btn ${
267 this.state.currentTab == "settings" && "active"
270 { ctx: this, tab: "settings" },
277 <li className="nav-item">
279 className={`nav-link btn ${
280 this.state.currentTab == "blocks" && "active"
283 { ctx: this, tab: "blocks" },
291 {this.state.currentTab == "settings" && this.userSettings()}
292 {this.state.currentTab == "blocks" && this.blockCards()}
300 <div className="row">
301 <div className="col-12 col-md-6">
302 <div className="card border-secondary mb-3">
303 <div className="card-body">{this.saveUserSettingsHtmlForm()}</div>
306 <div className="col-12 col-md-6">
307 <div className="card border-secondary mb-3">
308 <div className="card-body">{this.changePasswordHtmlForm()}</div>
317 <div className="row">
318 <div className="col-12 col-md-6">
319 <div className="card border-secondary mb-3">
320 <div className="card-body">{this.blockUserCard()}</div>
323 <div className="col-12 col-md-6">
324 <div className="card border-secondary mb-3">
325 <div className="card-body">{this.blockCommunityCard()}</div>
332 changePasswordHtmlForm() {
335 <h5>{i18n.t("change_password")}</h5>
336 <form onSubmit={linkEvent(this, this.handleChangePasswordSubmit)}>
337 <div className="form-group row">
338 <label className="col-sm-5 col-form-label" htmlFor="user-password">
339 {i18n.t("new_password")}
341 <div className="col-sm-7">
345 className="form-control"
346 value={this.state.changePasswordForm.new_password}
347 autoComplete="new-password"
349 onInput={linkEvent(this, this.handleNewPasswordChange)}
353 <div className="form-group row">
355 className="col-sm-5 col-form-label"
356 htmlFor="user-verify-password"
358 {i18n.t("verify_password")}
360 <div className="col-sm-7">
363 id="user-verify-password"
364 className="form-control"
365 value={this.state.changePasswordForm.new_password_verify}
366 autoComplete="new-password"
368 onInput={linkEvent(this, this.handleNewPasswordVerifyChange)}
372 <div className="form-group row">
374 className="col-sm-5 col-form-label"
375 htmlFor="user-old-password"
377 {i18n.t("old_password")}
379 <div className="col-sm-7">
382 id="user-old-password"
383 className="form-control"
384 value={this.state.changePasswordForm.old_password}
385 autoComplete="new-password"
387 onInput={linkEvent(this, this.handleOldPasswordChange)}
391 <div className="form-group">
392 <button type="submit" className="btn btn-block btn-secondary mr-4">
393 {this.state.changePasswordLoading ? (
396 capitalizeFirstLetter(i18n.t("save"))
406 const { searchPersonLoading, searchPersonOptions } = this.state;
412 loading={searchPersonLoading}
413 onChange={this.handleBlockPerson}
414 onSearch={this.handlePersonSearch}
415 options={searchPersonOptions}
417 {this.blockedUsersList()}
425 <h5>{i18n.t("blocked_users")}</h5>
426 <ul className="list-unstyled mb-0">
427 {this.state.personBlocks.map(pb => (
428 <li key={pb.target.id}>
430 <PersonListing person={pb.target} />
432 className="btn btn-sm"
434 { ctx: this, recipientId: pb.target.id },
435 this.handleUnblockPerson
437 data-tippy-content={i18n.t("unblock_user")}
439 <Icon icon="x" classes="icon-inline" />
449 blockCommunityCard() {
450 const { searchCommunityLoading, searchCommunityOptions } = this.state;
455 filterType="community"
456 loading={searchCommunityLoading}
457 onChange={this.handleBlockCommunity}
458 onSearch={this.handleCommunitySearch}
459 options={searchCommunityOptions}
461 {this.blockedCommunitiesList()}
466 blockedCommunitiesList() {
469 <h5>{i18n.t("blocked_communities")}</h5>
470 <ul className="list-unstyled mb-0">
471 {this.state.communityBlocks.map(cb => (
472 <li key={cb.community.id}>
474 <CommunityLink community={cb.community} />
476 className="btn btn-sm"
478 { ctx: this, communityId: cb.community.id },
479 this.handleUnblockCommunity
481 data-tippy-content={i18n.t("unblock_community")}
483 <Icon icon="x" classes="icon-inline" />
493 saveUserSettingsHtmlForm() {
494 let selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
498 <h5>{i18n.t("settings")}</h5>
499 <form onSubmit={linkEvent(this, this.handleSaveSettingsSubmit)}>
500 <div className="form-group row">
501 <label className="col-sm-5 col-form-label" htmlFor="display-name">
502 {i18n.t("display_name")}
504 <div className="col-sm-7">
508 className="form-control"
509 placeholder={i18n.t("optional")}
510 value={this.state.saveUserSettingsForm.display_name}
511 onInput={linkEvent(this, this.handleDisplayNameChange)}
512 pattern="^(?!@)(.+)$"
517 <div className="form-group row">
518 <label className="col-sm-3 col-form-label" htmlFor="user-bio">
521 <div className="col-sm-9">
523 initialContent={this.state.saveUserSettingsForm.bio}
524 onContentChange={this.handleBioChange}
526 hideNavigationWarnings
527 allLanguages={this.state.siteRes.all_languages}
528 siteLanguages={this.state.siteRes.discussion_languages}
532 <div className="form-group row">
533 <label className="col-sm-3 col-form-label" htmlFor="user-email">
536 <div className="col-sm-9">
540 className="form-control"
541 placeholder={i18n.t("optional")}
542 value={this.state.saveUserSettingsForm.email}
543 onInput={linkEvent(this, this.handleEmailChange)}
548 <div className="form-group row">
549 <label className="col-sm-5 col-form-label" htmlFor="matrix-user-id">
550 <a href={elementUrl} rel={relTags}>
551 {i18n.t("matrix_user_id")}
554 <div className="col-sm-7">
558 className="form-control"
559 placeholder="@user:example.com"
560 value={this.state.saveUserSettingsForm.matrix_user_id}
561 onInput={linkEvent(this, this.handleMatrixUserIdChange)}
562 pattern="^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"
566 <div className="form-group row">
567 <label className="col-sm-3">{i18n.t("avatar")}</label>
568 <div className="col-sm-9">
570 uploadTitle={i18n.t("upload_avatar")}
571 imageSrc={this.state.saveUserSettingsForm.avatar}
572 onUpload={this.handleAvatarUpload}
573 onRemove={this.handleAvatarRemove}
578 <div className="form-group row">
579 <label className="col-sm-3">{i18n.t("banner")}</label>
580 <div className="col-sm-9">
582 uploadTitle={i18n.t("upload_banner")}
583 imageSrc={this.state.saveUserSettingsForm.banner}
584 onUpload={this.handleBannerUpload}
585 onRemove={this.handleBannerRemove}
589 <div className="form-group row">
590 <label className="col-sm-3" htmlFor="user-language">
591 {i18n.t("interface_language")}
593 <div className="col-sm-9">
596 value={this.state.saveUserSettingsForm.interface_language}
597 onChange={linkEvent(this, this.handleInterfaceLangChange)}
598 className="custom-select w-auto"
600 <option disabled aria-hidden="true">
601 {i18n.t("interface_language")}
603 <option value="browser">{i18n.t("browser_default")}</option>
604 <option disabled aria-hidden="true">
608 .sort((a, b) => a.code.localeCompare(b.code))
610 <option key={lang.code} value={lang.code}>
618 allLanguages={this.state.siteRes.all_languages}
619 siteLanguages={this.state.siteRes.discussion_languages}
620 selectedLanguageIds={selectedLangs}
623 onChange={this.handleDiscussionLanguageChange}
625 <div className="form-group row">
626 <label className="col-sm-3" htmlFor="user-theme">
629 <div className="col-sm-9">
632 value={this.state.saveUserSettingsForm.theme}
633 onChange={linkEvent(this, this.handleThemeChange)}
634 className="custom-select w-auto"
636 <option disabled aria-hidden="true">
639 <option value="browser">{i18n.t("browser_default")}</option>
640 {this.state.themeList.map(theme => (
641 <option key={theme} value={theme}>
648 <form className="form-group row">
649 <label className="col-sm-3">{i18n.t("type")}</label>
650 <div className="col-sm-9">
653 this.state.saveUserSettingsForm.default_listing_type ??
656 showLocal={showLocal(this.isoData)}
658 onChange={this.handleListingTypeChange}
662 <form className="form-group row">
663 <label className="col-sm-3">{i18n.t("sort_type")}</label>
664 <div className="col-sm-9">
667 this.state.saveUserSettingsForm.default_sort_type ?? "Active"
669 onChange={this.handleSortTypeChange}
673 {enableNsfw(this.state.siteRes) && (
674 <div className="form-group">
675 <div className="form-check">
677 className="form-check-input"
680 checked={this.state.saveUserSettingsForm.show_nsfw}
681 onChange={linkEvent(this, this.handleShowNsfwChange)}
683 <label className="form-check-label" htmlFor="user-show-nsfw">
684 {i18n.t("show_nsfw")}
689 <div className="form-group">
690 <div className="form-check">
692 className="form-check-input"
693 id="user-show-scores"
695 checked={this.state.saveUserSettingsForm.show_scores}
696 onChange={linkEvent(this, this.handleShowScoresChange)}
698 <label className="form-check-label" htmlFor="user-show-scores">
699 {i18n.t("show_scores")}
703 <div className="form-group">
704 <div className="form-check">
706 className="form-check-input"
707 id="user-show-avatars"
709 checked={this.state.saveUserSettingsForm.show_avatars}
710 onChange={linkEvent(this, this.handleShowAvatarsChange)}
712 <label className="form-check-label" htmlFor="user-show-avatars">
713 {i18n.t("show_avatars")}
717 <div className="form-group">
718 <div className="form-check">
720 className="form-check-input"
721 id="user-bot-account"
723 checked={this.state.saveUserSettingsForm.bot_account}
724 onChange={linkEvent(this, this.handleBotAccount)}
726 <label className="form-check-label" htmlFor="user-bot-account">
727 {i18n.t("bot_account")}
731 <div className="form-group">
732 <div className="form-check">
734 className="form-check-input"
735 id="user-show-bot-accounts"
737 checked={this.state.saveUserSettingsForm.show_bot_accounts}
738 onChange={linkEvent(this, this.handleShowBotAccounts)}
741 className="form-check-label"
742 htmlFor="user-show-bot-accounts"
744 {i18n.t("show_bot_accounts")}
748 <div className="form-group">
749 <div className="form-check">
751 className="form-check-input"
752 id="user-show-read-posts"
754 checked={this.state.saveUserSettingsForm.show_read_posts}
755 onChange={linkEvent(this, this.handleReadPosts)}
758 className="form-check-label"
759 htmlFor="user-show-read-posts"
761 {i18n.t("show_read_posts")}
765 <div className="form-group">
766 <div className="form-check">
768 className="form-check-input"
769 id="user-show-new-post-notifs"
771 checked={this.state.saveUserSettingsForm.show_new_post_notifs}
772 onChange={linkEvent(this, this.handleShowNewPostNotifs)}
775 className="form-check-label"
776 htmlFor="user-show-new-post-notifs"
778 {i18n.t("show_new_post_notifs")}
782 <div className="form-group">
783 <div className="form-check">
785 className="form-check-input"
786 id="user-send-notifications-to-email"
788 disabled={!this.state.saveUserSettingsForm.email}
790 this.state.saveUserSettingsForm.send_notifications_to_email
794 this.handleSendNotificationsToEmailChange
798 className="form-check-label"
799 htmlFor="user-send-notifications-to-email"
801 {i18n.t("send_notifications_to_email")}
806 <div className="form-group">
807 <button type="submit" className="btn btn-block btn-secondary mr-4">
808 {this.state.saveUserSettingsLoading ? (
811 capitalizeFirstLetter(i18n.t("save"))
816 <div className="form-group">
818 className="btn btn-block btn-danger"
821 this.handleDeleteAccountShowConfirmToggle
824 {i18n.t("delete_account")}
826 {this.state.deleteAccountShowConfirm && (
828 <div className="my-2 alert alert-danger" role="alert">
829 {i18n.t("delete_account_confirm")}
833 value={this.state.deleteAccountForm.password}
834 autoComplete="new-password"
838 this.handleDeleteAccountPasswordChange
840 className="form-control my-2"
843 className="btn btn-danger mr-4"
844 disabled={!this.state.deleteAccountForm.password}
845 onClick={linkEvent(this, this.handleDeleteAccount)}
847 {this.state.deleteAccountLoading ? (
850 capitalizeFirstLetter(i18n.t("delete"))
854 className="btn btn-secondary"
857 this.handleDeleteAccountShowConfirmToggle
872 UserService.Instance.myUserInfo?.local_user_view.local_user.totp_2fa_url;
877 <div className="form-group">
878 <div className="form-check">
880 className="form-check-input"
881 id="user-generate-totp"
883 checked={this.state.saveUserSettingsForm.generate_totp_2fa}
884 onChange={linkEvent(this, this.handleGenerateTotp)}
886 <label className="form-check-label" htmlFor="user-generate-totp">
887 {i18n.t("set_up_two_factor")}
896 <a className="btn btn-secondary mb-2" href={totpUrl}>
897 {i18n.t("two_factor_link")}
900 <div className="form-group">
901 <div className="form-check">
903 className="form-check-input"
904 id="user-remove-totp"
907 this.state.saveUserSettingsForm.generate_totp_2fa == false
909 onChange={linkEvent(this, this.handleRemoveTotp)}
911 <label className="form-check-label" htmlFor="user-remove-totp">
912 {i18n.t("remove_two_factor")}
922 handlePersonSearch = debounce(async (text: string) => {
923 this.setState({ searchPersonLoading: true });
925 const searchPersonOptions: Choice[] = [];
927 if (text.length > 0) {
928 searchPersonOptions.push(
929 ...(await fetchUsers(text)).users.map(personToChoice)
934 searchPersonLoading: false,
939 handleCommunitySearch = debounce(async (text: string) => {
940 this.setState({ searchCommunityLoading: true });
942 const searchCommunityOptions: Choice[] = [];
944 if (text.length > 0) {
945 searchCommunityOptions.push(
946 ...(await fetchCommunities(text)).communities.map(communityToChoice)
951 searchCommunityLoading: false,
952 searchCommunityOptions,
956 handleBlockPerson({ value }: Choice) {
957 const auth = myAuth();
958 if (auth && value !== "0") {
959 const blockUserForm: BlockPerson = {
960 person_id: Number(value),
965 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
969 handleUnblockPerson(i: { ctx: Settings; recipientId: number }) {
970 const auth = myAuth();
972 const blockUserForm: BlockPerson = {
973 person_id: i.recipientId,
977 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
981 handleBlockCommunity({ value }: Choice) {
982 const auth = myAuth();
983 if (auth && value !== "0") {
984 const blockCommunityForm: BlockCommunity = {
985 community_id: Number(value),
989 WebSocketService.Instance.send(
990 wsClient.blockCommunity(blockCommunityForm)
995 handleUnblockCommunity(i: { ctx: Settings; communityId: number }) {
996 const auth = myAuth();
998 const blockCommunityForm: BlockCommunity = {
999 community_id: i.communityId,
1003 WebSocketService.Instance.send(
1004 wsClient.blockCommunity(blockCommunityForm)
1009 handleShowNsfwChange(i: Settings, event: any) {
1010 i.state.saveUserSettingsForm.show_nsfw = event.target.checked;
1011 i.setState(i.state);
1014 handleShowAvatarsChange(i: Settings, event: any) {
1015 i.state.saveUserSettingsForm.show_avatars = event.target.checked;
1016 let mui = UserService.Instance.myUserInfo;
1018 mui.local_user_view.local_user.show_avatars = event.target.checked;
1020 i.setState(i.state);
1023 handleBotAccount(i: Settings, event: any) {
1024 i.state.saveUserSettingsForm.bot_account = event.target.checked;
1025 i.setState(i.state);
1028 handleShowBotAccounts(i: Settings, event: any) {
1029 i.state.saveUserSettingsForm.show_bot_accounts = event.target.checked;
1030 i.setState(i.state);
1033 handleReadPosts(i: Settings, event: any) {
1034 i.state.saveUserSettingsForm.show_read_posts = event.target.checked;
1035 i.setState(i.state);
1038 handleShowNewPostNotifs(i: Settings, event: any) {
1039 i.state.saveUserSettingsForm.show_new_post_notifs = event.target.checked;
1040 i.setState(i.state);
1043 handleShowScoresChange(i: Settings, event: any) {
1044 i.state.saveUserSettingsForm.show_scores = event.target.checked;
1045 let mui = UserService.Instance.myUserInfo;
1047 mui.local_user_view.local_user.show_scores = event.target.checked;
1049 i.setState(i.state);
1052 handleGenerateTotp(i: Settings, event: any) {
1053 // Coerce false to undefined here, so it won't generate it.
1054 let checked: boolean | undefined = event.target.checked || undefined;
1056 toast(i18n.t("two_factor_setup_instructions"));
1058 i.state.saveUserSettingsForm.generate_totp_2fa = checked;
1059 i.setState(i.state);
1062 handleRemoveTotp(i: Settings, event: any) {
1063 // Coerce true to undefined here, so it won't generate it.
1064 let checked: boolean | undefined = !event.target.checked && undefined;
1065 i.state.saveUserSettingsForm.generate_totp_2fa = checked;
1066 i.setState(i.state);
1069 handleSendNotificationsToEmailChange(i: Settings, event: any) {
1070 i.state.saveUserSettingsForm.send_notifications_to_email =
1071 event.target.checked;
1072 i.setState(i.state);
1075 handleThemeChange(i: Settings, event: any) {
1076 i.state.saveUserSettingsForm.theme = event.target.value;
1077 setTheme(event.target.value, true);
1078 i.setState(i.state);
1081 handleInterfaceLangChange(i: Settings, event: any) {
1082 i.state.saveUserSettingsForm.interface_language = event.target.value;
1083 i18n.changeLanguage(
1084 getLanguages(i.state.saveUserSettingsForm.interface_language).at(0)
1086 i.setState(i.state);
1089 handleDiscussionLanguageChange(val: number[]) {
1091 s => ((s.saveUserSettingsForm.discussion_languages = val), s)
1095 handleSortTypeChange(val: SortType) {
1096 this.setState(s => ((s.saveUserSettingsForm.default_sort_type = val), s));
1099 handleListingTypeChange(val: ListingType) {
1101 s => ((s.saveUserSettingsForm.default_listing_type = val), s)
1105 handleEmailChange(i: Settings, event: any) {
1106 i.state.saveUserSettingsForm.email = event.target.value;
1107 i.setState(i.state);
1110 handleBioChange(val: string) {
1111 this.setState(s => ((s.saveUserSettingsForm.bio = val), s));
1114 handleAvatarUpload(url: string) {
1115 this.setState(s => ((s.saveUserSettingsForm.avatar = url), s));
1118 handleAvatarRemove() {
1119 this.setState(s => ((s.saveUserSettingsForm.avatar = ""), s));
1122 handleBannerUpload(url: string) {
1123 this.setState(s => ((s.saveUserSettingsForm.banner = url), s));
1126 handleBannerRemove() {
1127 this.setState(s => ((s.saveUserSettingsForm.banner = ""), s));
1130 handleDisplayNameChange(i: Settings, event: any) {
1131 i.state.saveUserSettingsForm.display_name = event.target.value;
1132 i.setState(i.state);
1135 handleMatrixUserIdChange(i: Settings, event: any) {
1136 i.state.saveUserSettingsForm.matrix_user_id = event.target.value;
1137 i.setState(i.state);
1140 handleNewPasswordChange(i: Settings, event: any) {
1141 i.state.changePasswordForm.new_password = event.target.value;
1142 if (i.state.changePasswordForm.new_password == "") {
1143 i.state.changePasswordForm.new_password = undefined;
1145 i.setState(i.state);
1148 handleNewPasswordVerifyChange(i: Settings, event: any) {
1149 i.state.changePasswordForm.new_password_verify = event.target.value;
1150 if (i.state.changePasswordForm.new_password_verify == "") {
1151 i.state.changePasswordForm.new_password_verify = undefined;
1153 i.setState(i.state);
1156 handleOldPasswordChange(i: Settings, event: any) {
1157 i.state.changePasswordForm.old_password = event.target.value;
1158 if (i.state.changePasswordForm.old_password == "") {
1159 i.state.changePasswordForm.old_password = undefined;
1161 i.setState(i.state);
1164 handleSaveSettingsSubmit(i: Settings, event: any) {
1165 event.preventDefault();
1166 i.setState({ saveUserSettingsLoading: true });
1167 let auth = myAuth();
1169 let form: SaveUserSettings = { ...i.state.saveUserSettingsForm, auth };
1170 WebSocketService.Instance.send(wsClient.saveUserSettings(form));
1174 handleChangePasswordSubmit(i: Settings, event: any) {
1175 event.preventDefault();
1176 i.setState({ changePasswordLoading: true });
1177 let auth = myAuth();
1178 let pForm = i.state.changePasswordForm;
1179 let new_password = pForm.new_password;
1180 let new_password_verify = pForm.new_password_verify;
1181 let old_password = pForm.old_password;
1182 if (auth && new_password && old_password && new_password_verify) {
1183 let form: ChangePassword = {
1185 new_password_verify,
1190 WebSocketService.Instance.send(wsClient.changePassword(form));
1194 handleDeleteAccountShowConfirmToggle(i: Settings, event: any) {
1195 event.preventDefault();
1196 i.setState({ deleteAccountShowConfirm: !i.state.deleteAccountShowConfirm });
1199 handleDeleteAccountPasswordChange(i: Settings, event: any) {
1200 i.state.deleteAccountForm.password = event.target.value;
1201 i.setState(i.state);
1204 handleDeleteAccount(i: Settings, event: any) {
1205 event.preventDefault();
1206 i.setState({ deleteAccountLoading: true });
1207 let auth = myAuth();
1208 let password = i.state.deleteAccountForm.password;
1209 if (auth && password) {
1210 let form: DeleteAccount = {
1214 WebSocketService.Instance.send(wsClient.deleteAccount(form));
1218 handleSwitchTab(i: { ctx: Settings; tab: string }) {
1219 i.ctx.setState({ currentTab: i.tab });
1222 parseMessage(msg: any) {
1223 let op = wsUserOp(msg);
1227 saveUserSettingsLoading: false,
1228 changePasswordLoading: false,
1229 deleteAccountLoading: false,
1231 toast(i18n.t(msg.error), "danger");
1233 } else if (op == UserOperation.SaveUserSettings) {
1234 this.setState({ saveUserSettingsLoading: false });
1235 toast(i18n.t("saved"));
1236 window.scrollTo(0, 0);
1237 } else if (op == UserOperation.ChangePassword) {
1238 let data = wsJsonToRes<LoginResponse>(msg);
1239 UserService.Instance.login(data);
1240 this.setState({ changePasswordLoading: false });
1241 window.scrollTo(0, 0);
1242 toast(i18n.t("password_changed"));
1243 } else if (op == UserOperation.DeleteAccount) {
1245 deleteAccountLoading: false,
1246 deleteAccountShowConfirm: false,
1248 UserService.Instance.logout();
1249 window.location.href = "/";
1250 } else if (op == UserOperation.BlockPerson) {
1251 let data = wsJsonToRes<BlockPersonResponse>(msg);
1252 updatePersonBlock(data);
1253 let mui = UserService.Instance.myUserInfo;
1255 this.setState({ personBlocks: mui.person_blocks });
1257 } else if (op == UserOperation.BlockCommunity) {
1258 let data = wsJsonToRes<BlockCommunityResponse>(msg);
1259 updateCommunityBlock(data);
1260 let mui = UserService.Instance.myUserInfo;
1262 this.setState({ communityBlocks: mui.community_blocks });