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 Tabs from "../common/tabs";
58 import { CommunityLink } from "../community/community-link";
59 import { PersonListing } from "./person-listing";
61 interface SettingsState {
62 // TODO redo these forms
63 saveUserSettingsForm: {
66 default_sort_type?: SortType;
67 default_listing_type?: ListingType;
68 interface_language?: string;
71 display_name?: string;
74 matrix_user_id?: string;
75 show_avatars?: boolean;
76 show_scores?: boolean;
77 send_notifications_to_email?: boolean;
78 bot_account?: boolean;
79 show_bot_accounts?: boolean;
80 show_read_posts?: boolean;
81 show_new_post_notifs?: boolean;
82 discussion_languages?: number[];
83 generate_totp_2fa?: boolean;
86 new_password?: string;
87 new_password_verify?: string;
88 old_password?: string;
93 personBlocks: PersonBlockView[];
94 communityBlocks: CommunityBlockView[];
97 saveUserSettingsLoading: boolean;
98 changePasswordLoading: boolean;
99 deleteAccountLoading: boolean;
100 deleteAccountShowConfirm: boolean;
101 siteRes: GetSiteResponse;
102 searchCommunityLoading: boolean;
103 searchCommunityOptions: Choice[];
104 searchPersonLoading: boolean;
105 searchPersonOptions: Choice[];
108 type FilterType = "user" | "community";
117 filterType: FilterType;
119 onSearch: (text: string) => void;
120 onChange: (choice: Choice) => void;
123 <div className="form-group row">
125 className="col-md-4 col-form-label"
126 htmlFor={`block-${filterType}-filter`}
128 {i18n.t(`block_${filterType}` as NoOptionI18nKeys)}
130 <div className="col-md-8">
132 id={`block-${filterType}-filter`}
134 { label: emDash, value: "0", disabled: true } as Choice,
144 export class Settings extends Component<any, SettingsState> {
145 private isoData = setIsoData(this.context);
146 private subscription?: Subscription;
147 state: SettingsState = {
148 saveUserSettingsForm: {},
149 changePasswordForm: {},
150 saveUserSettingsLoading: false,
151 changePasswordLoading: false,
152 deleteAccountLoading: false,
153 deleteAccountShowConfirm: false,
154 deleteAccountForm: {},
157 currentTab: "settings",
158 siteRes: this.isoData.site_res,
160 searchCommunityLoading: false,
161 searchCommunityOptions: [],
162 searchPersonLoading: false,
163 searchPersonOptions: [],
166 constructor(props: any, context: any) {
167 super(props, context);
169 this.handleSortTypeChange = this.handleSortTypeChange.bind(this);
170 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
171 this.handleBioChange = this.handleBioChange.bind(this);
172 this.handleDiscussionLanguageChange =
173 this.handleDiscussionLanguageChange.bind(this);
175 this.handleAvatarUpload = this.handleAvatarUpload.bind(this);
176 this.handleAvatarRemove = this.handleAvatarRemove.bind(this);
178 this.handleBannerUpload = this.handleBannerUpload.bind(this);
179 this.handleBannerRemove = this.handleBannerRemove.bind(this);
180 this.userSettings = this.userSettings.bind(this);
181 this.blockCards = this.blockCards.bind(this);
183 this.parseMessage = this.parseMessage.bind(this);
184 this.subscription = wsSubscribe(this.parseMessage);
186 const mui = UserService.Instance.myUserInfo;
193 default_listing_type,
199 show_new_post_notifs,
200 send_notifications_to_email,
211 } = mui.local_user_view;
215 personBlocks: mui.person_blocks,
216 communityBlocks: mui.community_blocks,
217 saveUserSettingsForm: {
218 ...this.state.saveUserSettingsForm,
220 theme: theme ?? "browser",
222 default_listing_type,
224 discussion_languages: mui.discussion_languages,
233 show_new_post_notifs,
236 send_notifications_to_email,
243 async componentDidMount() {
245 this.setState({ themeList: await fetchThemeList() });
248 componentWillUnmount() {
249 this.subscription?.unsubscribe();
252 get documentTitle(): string {
253 return i18n.t("settings");
258 <div className="container-lg">
260 title={this.documentTitle}
261 path={this.context.router.route.match.url}
262 description={this.documentTitle}
263 image={this.state.saveUserSettingsForm.avatar}
269 label: i18n.t("settings"),
270 getNode: this.userSettings,
274 label: i18n.t("blocks"),
275 getNode: this.blockCards,
285 <div className="row">
286 <div className="col-12 col-md-6">
287 <div className="card border-secondary mb-3">
288 <div className="card-body">{this.saveUserSettingsHtmlForm()}</div>
291 <div className="col-12 col-md-6">
292 <div className="card border-secondary mb-3">
293 <div className="card-body">{this.changePasswordHtmlForm()}</div>
302 <div className="row">
303 <div className="col-12 col-md-6">
304 <div className="card border-secondary mb-3">
305 <div className="card-body">{this.blockUserCard()}</div>
308 <div className="col-12 col-md-6">
309 <div className="card border-secondary mb-3">
310 <div className="card-body">{this.blockCommunityCard()}</div>
317 changePasswordHtmlForm() {
320 <h5>{i18n.t("change_password")}</h5>
321 <form onSubmit={linkEvent(this, this.handleChangePasswordSubmit)}>
322 <div className="form-group row">
323 <label className="col-sm-5 col-form-label" htmlFor="user-password">
324 {i18n.t("new_password")}
326 <div className="col-sm-7">
330 className="form-control"
331 value={this.state.changePasswordForm.new_password}
332 autoComplete="new-password"
334 onInput={linkEvent(this, this.handleNewPasswordChange)}
338 <div className="form-group row">
340 className="col-sm-5 col-form-label"
341 htmlFor="user-verify-password"
343 {i18n.t("verify_password")}
345 <div className="col-sm-7">
348 id="user-verify-password"
349 className="form-control"
350 value={this.state.changePasswordForm.new_password_verify}
351 autoComplete="new-password"
353 onInput={linkEvent(this, this.handleNewPasswordVerifyChange)}
357 <div className="form-group row">
359 className="col-sm-5 col-form-label"
360 htmlFor="user-old-password"
362 {i18n.t("old_password")}
364 <div className="col-sm-7">
367 id="user-old-password"
368 className="form-control"
369 value={this.state.changePasswordForm.old_password}
370 autoComplete="new-password"
372 onInput={linkEvent(this, this.handleOldPasswordChange)}
376 <div className="form-group">
377 <button type="submit" className="btn btn-block btn-secondary mr-4">
378 {this.state.changePasswordLoading ? (
381 capitalizeFirstLetter(i18n.t("save"))
391 const { searchPersonLoading, searchPersonOptions } = this.state;
397 loading={searchPersonLoading}
398 onChange={this.handleBlockPerson}
399 onSearch={this.handlePersonSearch}
400 options={searchPersonOptions}
402 {this.blockedUsersList()}
410 <h5>{i18n.t("blocked_users")}</h5>
411 <ul className="list-unstyled mb-0">
412 {this.state.personBlocks.map(pb => (
413 <li key={pb.target.id}>
415 <PersonListing person={pb.target} />
417 className="btn btn-sm"
419 { ctx: this, recipientId: pb.target.id },
420 this.handleUnblockPerson
422 data-tippy-content={i18n.t("unblock_user")}
424 <Icon icon="x" classes="icon-inline" />
434 blockCommunityCard() {
435 const { searchCommunityLoading, searchCommunityOptions } = this.state;
440 filterType="community"
441 loading={searchCommunityLoading}
442 onChange={this.handleBlockCommunity}
443 onSearch={this.handleCommunitySearch}
444 options={searchCommunityOptions}
446 {this.blockedCommunitiesList()}
451 blockedCommunitiesList() {
454 <h5>{i18n.t("blocked_communities")}</h5>
455 <ul className="list-unstyled mb-0">
456 {this.state.communityBlocks.map(cb => (
457 <li key={cb.community.id}>
459 <CommunityLink community={cb.community} />
461 className="btn btn-sm"
463 { ctx: this, communityId: cb.community.id },
464 this.handleUnblockCommunity
466 data-tippy-content={i18n.t("unblock_community")}
468 <Icon icon="x" classes="icon-inline" />
478 saveUserSettingsHtmlForm() {
479 let selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
483 <h5>{i18n.t("settings")}</h5>
484 <form onSubmit={linkEvent(this, this.handleSaveSettingsSubmit)}>
485 <div className="form-group row">
486 <label className="col-sm-5 col-form-label" htmlFor="display-name">
487 {i18n.t("display_name")}
489 <div className="col-sm-7">
493 className="form-control"
494 placeholder={i18n.t("optional")}
495 value={this.state.saveUserSettingsForm.display_name}
496 onInput={linkEvent(this, this.handleDisplayNameChange)}
497 pattern="^(?!@)(.+)$"
502 <div className="form-group row">
503 <label className="col-sm-3 col-form-label" htmlFor="user-bio">
506 <div className="col-sm-9">
508 initialContent={this.state.saveUserSettingsForm.bio}
509 onContentChange={this.handleBioChange}
511 hideNavigationWarnings
512 allLanguages={this.state.siteRes.all_languages}
513 siteLanguages={this.state.siteRes.discussion_languages}
517 <div className="form-group row">
518 <label className="col-sm-3 col-form-label" htmlFor="user-email">
521 <div className="col-sm-9">
525 className="form-control"
526 placeholder={i18n.t("optional")}
527 value={this.state.saveUserSettingsForm.email}
528 onInput={linkEvent(this, this.handleEmailChange)}
533 <div className="form-group row">
534 <label className="col-sm-5 col-form-label" htmlFor="matrix-user-id">
535 <a href={elementUrl} rel={relTags}>
536 {i18n.t("matrix_user_id")}
539 <div className="col-sm-7">
543 className="form-control"
544 placeholder="@user:example.com"
545 value={this.state.saveUserSettingsForm.matrix_user_id}
546 onInput={linkEvent(this, this.handleMatrixUserIdChange)}
547 pattern="^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"
551 <div className="form-group row">
552 <label className="col-sm-3">{i18n.t("avatar")}</label>
553 <div className="col-sm-9">
555 uploadTitle={i18n.t("upload_avatar")}
556 imageSrc={this.state.saveUserSettingsForm.avatar}
557 onUpload={this.handleAvatarUpload}
558 onRemove={this.handleAvatarRemove}
563 <div className="form-group row">
564 <label className="col-sm-3">{i18n.t("banner")}</label>
565 <div className="col-sm-9">
567 uploadTitle={i18n.t("upload_banner")}
568 imageSrc={this.state.saveUserSettingsForm.banner}
569 onUpload={this.handleBannerUpload}
570 onRemove={this.handleBannerRemove}
574 <div className="form-group row">
575 <label className="col-sm-3" htmlFor="user-language">
576 {i18n.t("interface_language")}
578 <div className="col-sm-9">
581 value={this.state.saveUserSettingsForm.interface_language}
582 onChange={linkEvent(this, this.handleInterfaceLangChange)}
583 className="custom-select w-auto"
585 <option disabled aria-hidden="true">
586 {i18n.t("interface_language")}
588 <option value="browser">{i18n.t("browser_default")}</option>
589 <option disabled aria-hidden="true">
593 .sort((a, b) => a.code.localeCompare(b.code))
595 <option key={lang.code} value={lang.code}>
603 allLanguages={this.state.siteRes.all_languages}
604 siteLanguages={this.state.siteRes.discussion_languages}
605 selectedLanguageIds={selectedLangs}
608 onChange={this.handleDiscussionLanguageChange}
610 <div className="form-group row">
611 <label className="col-sm-3" htmlFor="user-theme">
614 <div className="col-sm-9">
617 value={this.state.saveUserSettingsForm.theme}
618 onChange={linkEvent(this, this.handleThemeChange)}
619 className="custom-select w-auto"
621 <option disabled aria-hidden="true">
624 <option value="browser">{i18n.t("browser_default")}</option>
625 {this.state.themeList.map(theme => (
626 <option key={theme} value={theme}>
633 <form className="form-group row">
634 <label className="col-sm-3">{i18n.t("type")}</label>
635 <div className="col-sm-9">
638 this.state.saveUserSettingsForm.default_listing_type ??
641 showLocal={showLocal(this.isoData)}
643 onChange={this.handleListingTypeChange}
647 <form className="form-group row">
648 <label className="col-sm-3">{i18n.t("sort_type")}</label>
649 <div className="col-sm-9">
652 this.state.saveUserSettingsForm.default_sort_type ?? "Active"
654 onChange={this.handleSortTypeChange}
658 {enableNsfw(this.state.siteRes) && (
659 <div className="form-group">
660 <div className="form-check">
662 className="form-check-input"
665 checked={this.state.saveUserSettingsForm.show_nsfw}
666 onChange={linkEvent(this, this.handleShowNsfwChange)}
668 <label className="form-check-label" htmlFor="user-show-nsfw">
669 {i18n.t("show_nsfw")}
674 <div className="form-group">
675 <div className="form-check">
677 className="form-check-input"
678 id="user-show-scores"
680 checked={this.state.saveUserSettingsForm.show_scores}
681 onChange={linkEvent(this, this.handleShowScoresChange)}
683 <label className="form-check-label" htmlFor="user-show-scores">
684 {i18n.t("show_scores")}
688 <div className="form-group">
689 <div className="form-check">
691 className="form-check-input"
692 id="user-show-avatars"
694 checked={this.state.saveUserSettingsForm.show_avatars}
695 onChange={linkEvent(this, this.handleShowAvatarsChange)}
697 <label className="form-check-label" htmlFor="user-show-avatars">
698 {i18n.t("show_avatars")}
702 <div className="form-group">
703 <div className="form-check">
705 className="form-check-input"
706 id="user-bot-account"
708 checked={this.state.saveUserSettingsForm.bot_account}
709 onChange={linkEvent(this, this.handleBotAccount)}
711 <label className="form-check-label" htmlFor="user-bot-account">
712 {i18n.t("bot_account")}
716 <div className="form-group">
717 <div className="form-check">
719 className="form-check-input"
720 id="user-show-bot-accounts"
722 checked={this.state.saveUserSettingsForm.show_bot_accounts}
723 onChange={linkEvent(this, this.handleShowBotAccounts)}
726 className="form-check-label"
727 htmlFor="user-show-bot-accounts"
729 {i18n.t("show_bot_accounts")}
733 <div className="form-group">
734 <div className="form-check">
736 className="form-check-input"
737 id="user-show-read-posts"
739 checked={this.state.saveUserSettingsForm.show_read_posts}
740 onChange={linkEvent(this, this.handleReadPosts)}
743 className="form-check-label"
744 htmlFor="user-show-read-posts"
746 {i18n.t("show_read_posts")}
750 <div className="form-group">
751 <div className="form-check">
753 className="form-check-input"
754 id="user-show-new-post-notifs"
756 checked={this.state.saveUserSettingsForm.show_new_post_notifs}
757 onChange={linkEvent(this, this.handleShowNewPostNotifs)}
760 className="form-check-label"
761 htmlFor="user-show-new-post-notifs"
763 {i18n.t("show_new_post_notifs")}
767 <div className="form-group">
768 <div className="form-check">
770 className="form-check-input"
771 id="user-send-notifications-to-email"
773 disabled={!this.state.saveUserSettingsForm.email}
775 this.state.saveUserSettingsForm.send_notifications_to_email
779 this.handleSendNotificationsToEmailChange
783 className="form-check-label"
784 htmlFor="user-send-notifications-to-email"
786 {i18n.t("send_notifications_to_email")}
791 <div className="form-group">
792 <button type="submit" className="btn btn-block btn-secondary mr-4">
793 {this.state.saveUserSettingsLoading ? (
796 capitalizeFirstLetter(i18n.t("save"))
801 <div className="form-group">
803 className="btn btn-block btn-danger"
806 this.handleDeleteAccountShowConfirmToggle
809 {i18n.t("delete_account")}
811 {this.state.deleteAccountShowConfirm && (
813 <div className="my-2 alert alert-danger" role="alert">
814 {i18n.t("delete_account_confirm")}
818 value={this.state.deleteAccountForm.password}
819 autoComplete="new-password"
823 this.handleDeleteAccountPasswordChange
825 className="form-control my-2"
828 className="btn btn-danger mr-4"
829 disabled={!this.state.deleteAccountForm.password}
830 onClick={linkEvent(this, this.handleDeleteAccount)}
832 {this.state.deleteAccountLoading ? (
835 capitalizeFirstLetter(i18n.t("delete"))
839 className="btn btn-secondary"
842 this.handleDeleteAccountShowConfirmToggle
857 UserService.Instance.myUserInfo?.local_user_view.local_user.totp_2fa_url;
862 <div className="form-group">
863 <div className="form-check">
865 className="form-check-input"
866 id="user-generate-totp"
868 checked={this.state.saveUserSettingsForm.generate_totp_2fa}
869 onChange={linkEvent(this, this.handleGenerateTotp)}
871 <label className="form-check-label" htmlFor="user-generate-totp">
872 {i18n.t("set_up_two_factor")}
881 <a className="btn btn-secondary mb-2" href={totpUrl}>
882 {i18n.t("two_factor_link")}
885 <div className="form-group">
886 <div className="form-check">
888 className="form-check-input"
889 id="user-remove-totp"
892 this.state.saveUserSettingsForm.generate_totp_2fa == false
894 onChange={linkEvent(this, this.handleRemoveTotp)}
896 <label className="form-check-label" htmlFor="user-remove-totp">
897 {i18n.t("remove_two_factor")}
907 handlePersonSearch = debounce(async (text: string) => {
908 this.setState({ searchPersonLoading: true });
910 const searchPersonOptions: Choice[] = [];
912 if (text.length > 0) {
913 searchPersonOptions.push(
914 ...(await fetchUsers(text)).users.map(personToChoice)
919 searchPersonLoading: false,
924 handleCommunitySearch = debounce(async (text: string) => {
925 this.setState({ searchCommunityLoading: true });
927 const searchCommunityOptions: Choice[] = [];
929 if (text.length > 0) {
930 searchCommunityOptions.push(
931 ...(await fetchCommunities(text)).communities.map(communityToChoice)
936 searchCommunityLoading: false,
937 searchCommunityOptions,
941 handleBlockPerson({ value }: Choice) {
942 const auth = myAuth();
943 if (auth && value !== "0") {
944 const blockUserForm: BlockPerson = {
945 person_id: Number(value),
950 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
954 handleUnblockPerson(i: { ctx: Settings; recipientId: number }) {
955 const auth = myAuth();
957 const blockUserForm: BlockPerson = {
958 person_id: i.recipientId,
962 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
966 handleBlockCommunity({ value }: Choice) {
967 const auth = myAuth();
968 if (auth && value !== "0") {
969 const blockCommunityForm: BlockCommunity = {
970 community_id: Number(value),
974 WebSocketService.Instance.send(
975 wsClient.blockCommunity(blockCommunityForm)
980 handleUnblockCommunity(i: { ctx: Settings; communityId: number }) {
981 const auth = myAuth();
983 const blockCommunityForm: BlockCommunity = {
984 community_id: i.communityId,
988 WebSocketService.Instance.send(
989 wsClient.blockCommunity(blockCommunityForm)
994 handleShowNsfwChange(i: Settings, event: any) {
995 i.state.saveUserSettingsForm.show_nsfw = event.target.checked;
999 handleShowAvatarsChange(i: Settings, event: any) {
1000 i.state.saveUserSettingsForm.show_avatars = event.target.checked;
1001 let mui = UserService.Instance.myUserInfo;
1003 mui.local_user_view.local_user.show_avatars = event.target.checked;
1005 i.setState(i.state);
1008 handleBotAccount(i: Settings, event: any) {
1009 i.state.saveUserSettingsForm.bot_account = event.target.checked;
1010 i.setState(i.state);
1013 handleShowBotAccounts(i: Settings, event: any) {
1014 i.state.saveUserSettingsForm.show_bot_accounts = event.target.checked;
1015 i.setState(i.state);
1018 handleReadPosts(i: Settings, event: any) {
1019 i.state.saveUserSettingsForm.show_read_posts = event.target.checked;
1020 i.setState(i.state);
1023 handleShowNewPostNotifs(i: Settings, event: any) {
1024 i.state.saveUserSettingsForm.show_new_post_notifs = event.target.checked;
1025 i.setState(i.state);
1028 handleShowScoresChange(i: Settings, event: any) {
1029 i.state.saveUserSettingsForm.show_scores = event.target.checked;
1030 let mui = UserService.Instance.myUserInfo;
1032 mui.local_user_view.local_user.show_scores = event.target.checked;
1034 i.setState(i.state);
1037 handleGenerateTotp(i: Settings, event: any) {
1038 // Coerce false to undefined here, so it won't generate it.
1039 let checked: boolean | undefined = event.target.checked || undefined;
1041 toast(i18n.t("two_factor_setup_instructions"));
1043 i.state.saveUserSettingsForm.generate_totp_2fa = checked;
1044 i.setState(i.state);
1047 handleRemoveTotp(i: Settings, event: any) {
1048 // Coerce true to undefined here, so it won't generate it.
1049 let checked: boolean | undefined = !event.target.checked && undefined;
1050 i.state.saveUserSettingsForm.generate_totp_2fa = checked;
1051 i.setState(i.state);
1054 handleSendNotificationsToEmailChange(i: Settings, event: any) {
1055 i.state.saveUserSettingsForm.send_notifications_to_email =
1056 event.target.checked;
1057 i.setState(i.state);
1060 handleThemeChange(i: Settings, event: any) {
1061 i.state.saveUserSettingsForm.theme = event.target.value;
1062 setTheme(event.target.value, true);
1063 i.setState(i.state);
1066 handleInterfaceLangChange(i: Settings, event: any) {
1067 i.state.saveUserSettingsForm.interface_language = event.target.value;
1068 i18n.changeLanguage(
1069 getLanguages(i.state.saveUserSettingsForm.interface_language).at(0)
1071 i.setState(i.state);
1074 handleDiscussionLanguageChange(val: number[]) {
1076 s => ((s.saveUserSettingsForm.discussion_languages = val), s)
1080 handleSortTypeChange(val: SortType) {
1081 this.setState(s => ((s.saveUserSettingsForm.default_sort_type = val), s));
1084 handleListingTypeChange(val: ListingType) {
1086 s => ((s.saveUserSettingsForm.default_listing_type = val), s)
1090 handleEmailChange(i: Settings, event: any) {
1091 i.state.saveUserSettingsForm.email = event.target.value;
1092 i.setState(i.state);
1095 handleBioChange(val: string) {
1096 this.setState(s => ((s.saveUserSettingsForm.bio = val), s));
1099 handleAvatarUpload(url: string) {
1100 this.setState(s => ((s.saveUserSettingsForm.avatar = url), s));
1103 handleAvatarRemove() {
1104 this.setState(s => ((s.saveUserSettingsForm.avatar = ""), s));
1107 handleBannerUpload(url: string) {
1108 this.setState(s => ((s.saveUserSettingsForm.banner = url), s));
1111 handleBannerRemove() {
1112 this.setState(s => ((s.saveUserSettingsForm.banner = ""), s));
1115 handleDisplayNameChange(i: Settings, event: any) {
1116 i.state.saveUserSettingsForm.display_name = event.target.value;
1117 i.setState(i.state);
1120 handleMatrixUserIdChange(i: Settings, event: any) {
1121 i.state.saveUserSettingsForm.matrix_user_id = event.target.value;
1122 i.setState(i.state);
1125 handleNewPasswordChange(i: Settings, event: any) {
1126 i.state.changePasswordForm.new_password = event.target.value;
1127 if (i.state.changePasswordForm.new_password == "") {
1128 i.state.changePasswordForm.new_password = undefined;
1130 i.setState(i.state);
1133 handleNewPasswordVerifyChange(i: Settings, event: any) {
1134 i.state.changePasswordForm.new_password_verify = event.target.value;
1135 if (i.state.changePasswordForm.new_password_verify == "") {
1136 i.state.changePasswordForm.new_password_verify = undefined;
1138 i.setState(i.state);
1141 handleOldPasswordChange(i: Settings, event: any) {
1142 i.state.changePasswordForm.old_password = event.target.value;
1143 if (i.state.changePasswordForm.old_password == "") {
1144 i.state.changePasswordForm.old_password = undefined;
1146 i.setState(i.state);
1149 handleSaveSettingsSubmit(i: Settings, event: any) {
1150 event.preventDefault();
1151 i.setState({ saveUserSettingsLoading: true });
1152 let auth = myAuth();
1154 let form: SaveUserSettings = { ...i.state.saveUserSettingsForm, auth };
1155 WebSocketService.Instance.send(wsClient.saveUserSettings(form));
1159 handleChangePasswordSubmit(i: Settings, event: any) {
1160 event.preventDefault();
1161 i.setState({ changePasswordLoading: true });
1162 let auth = myAuth();
1163 let pForm = i.state.changePasswordForm;
1164 let new_password = pForm.new_password;
1165 let new_password_verify = pForm.new_password_verify;
1166 let old_password = pForm.old_password;
1167 if (auth && new_password && old_password && new_password_verify) {
1168 let form: ChangePassword = {
1170 new_password_verify,
1175 WebSocketService.Instance.send(wsClient.changePassword(form));
1179 handleDeleteAccountShowConfirmToggle(i: Settings, event: any) {
1180 event.preventDefault();
1181 i.setState({ deleteAccountShowConfirm: !i.state.deleteAccountShowConfirm });
1184 handleDeleteAccountPasswordChange(i: Settings, event: any) {
1185 i.state.deleteAccountForm.password = event.target.value;
1186 i.setState(i.state);
1189 handleDeleteAccount(i: Settings, event: any) {
1190 event.preventDefault();
1191 i.setState({ deleteAccountLoading: true });
1192 let auth = myAuth();
1193 let password = i.state.deleteAccountForm.password;
1194 if (auth && password) {
1195 let form: DeleteAccount = {
1199 WebSocketService.Instance.send(wsClient.deleteAccount(form));
1203 handleSwitchTab(i: { ctx: Settings; tab: string }) {
1204 i.ctx.setState({ currentTab: i.tab });
1207 parseMessage(msg: any) {
1208 let op = wsUserOp(msg);
1212 saveUserSettingsLoading: false,
1213 changePasswordLoading: false,
1214 deleteAccountLoading: false,
1216 toast(i18n.t(msg.error), "danger");
1218 } else if (op == UserOperation.SaveUserSettings) {
1219 this.setState({ saveUserSettingsLoading: false });
1220 toast(i18n.t("saved"));
1221 window.scrollTo(0, 0);
1222 } else if (op == UserOperation.ChangePassword) {
1223 let data = wsJsonToRes<LoginResponse>(msg);
1224 UserService.Instance.login(data);
1225 this.setState({ changePasswordLoading: false });
1226 window.scrollTo(0, 0);
1227 toast(i18n.t("password_changed"));
1228 } else if (op == UserOperation.DeleteAccount) {
1230 deleteAccountLoading: false,
1231 deleteAccountShowConfirm: false,
1233 UserService.Instance.logout();
1234 window.location.href = "/";
1235 } else if (op == UserOperation.BlockPerson) {
1236 let data = wsJsonToRes<BlockPersonResponse>(msg);
1237 updatePersonBlock(data);
1238 let mui = UserService.Instance.myUserInfo;
1240 this.setState({ personBlocks: mui.person_blocks });
1242 } else if (op == UserOperation.BlockCommunity) {
1243 let data = wsJsonToRes<BlockCommunityResponse>(msg);
1244 updateCommunityBlock(data);
1245 let mui = UserService.Instance.myUserInfo;
1247 this.setState({ communityBlocks: mui.community_blocks });