1 import { Component, linkEvent } from "inferno";
4 BlockCommunityResponse,
19 } from "lemmy-js-client";
20 import { Subscription } from "rxjs";
21 import { i18n } from "../../i18next";
22 import { UserService, WebSocketService } from "../../services";
25 capitalizeFirstLetter,
34 getNativeLanguageName,
52 import { HtmlTags } from "../common/html-tags";
53 import { Icon, Spinner } from "../common/icon";
54 import { ImageUploadForm } from "../common/image-upload-form";
55 import { ListingTypeSelect } from "../common/listing-type-select";
56 import { MarkdownTextArea } from "../common/markdown-textarea";
57 import { SortSelect } from "../common/sort-select";
58 import { CommunityLink } from "../community/community-link";
59 import { PersonListing } from "./person-listing";
63 Choices = require("choices.js");
66 interface SettingsState {
67 saveUserSettingsForm: SaveUserSettings;
68 changePasswordForm: ChangePassword;
69 saveUserSettingsLoading: boolean;
70 changePasswordLoading: boolean;
71 deleteAccountLoading: boolean;
72 deleteAccountShowConfirm: boolean;
73 deleteAccountForm: DeleteAccount;
74 personBlocks: PersonBlockView[];
75 blockPersonId: number;
76 blockPerson?: PersonViewSafe;
77 communityBlocks: CommunityBlockView[];
78 blockCommunityId: number;
79 blockCommunity?: CommunityView;
81 siteRes: GetSiteResponse;
84 export class Settings extends Component<any, SettingsState> {
85 private isoData = setIsoData(this.context);
86 private blockPersonChoices: any;
87 private blockCommunityChoices: any;
88 private subscription: Subscription;
89 private emptyState: SettingsState = {
90 saveUserSettingsForm: {
91 auth: authField(false),
95 new_password_verify: null,
97 auth: authField(false),
99 saveUserSettingsLoading: null,
100 changePasswordLoading: false,
101 deleteAccountLoading: null,
102 deleteAccountShowConfirm: false,
105 auth: authField(false),
111 currentTab: "settings",
112 siteRes: this.isoData.site_res,
115 constructor(props: any, context: any) {
116 super(props, context);
118 this.state = this.emptyState;
119 this.handleSortTypeChange = this.handleSortTypeChange.bind(this);
120 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
121 this.handleBioChange = this.handleBioChange.bind(this);
123 this.handleAvatarUpload = this.handleAvatarUpload.bind(this);
124 this.handleAvatarRemove = this.handleAvatarRemove.bind(this);
126 this.handleBannerUpload = this.handleBannerUpload.bind(this);
127 this.handleBannerRemove = this.handleBannerRemove.bind(this);
129 this.parseMessage = this.parseMessage.bind(this);
130 this.subscription = wsSubscribe(this.parseMessage);
135 componentDidMount() {
139 componentWillUnmount() {
140 this.subscription.unsubscribe();
143 get documentTitle(): string {
144 return i18n.t("settings");
149 <div class="container">
152 title={this.documentTitle}
153 path={this.context.router.route.match.url}
154 description={this.documentTitle}
155 image={this.state.saveUserSettingsForm.avatar}
157 <ul class="nav nav-tabs mb-2">
158 <li class="nav-item">
160 class={`nav-link btn ${
161 this.state.currentTab == "settings" && "active"
164 { ctx: this, tab: "settings" },
171 <li class="nav-item">
173 class={`nav-link btn ${
174 this.state.currentTab == "blocks" && "active"
177 { ctx: this, tab: "blocks" },
185 {this.state.currentTab == "settings" && this.userSettings()}
186 {this.state.currentTab == "blocks" && this.blockCards()}
195 <div class="col-12 col-md-6">
196 <div class="card border-secondary mb-3">
197 <div class="card-body">{this.saveUserSettingsHtmlForm()}</div>
200 <div class="col-12 col-md-6">
201 <div class="card border-secondary mb-3">
202 <div class="card-body">{this.changePasswordHtmlForm()}</div>
212 <div class="col-12 col-md-6">
213 <div class="card border-secondary mb-3">
214 <div class="card-body">{this.blockUserCard()}</div>
217 <div class="col-12 col-md-6">
218 <div class="card border-secondary mb-3">
219 <div class="card-body">{this.blockCommunityCard()}</div>
226 changePasswordHtmlForm() {
229 <h5>{i18n.t("change_password")}</h5>
230 <form onSubmit={linkEvent(this, this.handleChangePasswordSubmit)}>
231 <div class="form-group row">
232 <label class="col-sm-5 col-form-label" htmlFor="user-password">
233 {i18n.t("new_password")}
235 <div class="col-sm-7">
240 value={this.state.changePasswordForm.new_password}
241 autoComplete="new-password"
243 onInput={linkEvent(this, this.handleNewPasswordChange)}
247 <div class="form-group row">
249 class="col-sm-5 col-form-label"
250 htmlFor="user-verify-password"
252 {i18n.t("verify_password")}
254 <div class="col-sm-7">
257 id="user-verify-password"
259 value={this.state.changePasswordForm.new_password_verify}
260 autoComplete="new-password"
262 onInput={linkEvent(this, this.handleNewPasswordVerifyChange)}
266 <div class="form-group row">
267 <label class="col-sm-5 col-form-label" htmlFor="user-old-password">
268 {i18n.t("old_password")}
270 <div class="col-sm-7">
273 id="user-old-password"
275 value={this.state.changePasswordForm.old_password}
276 autoComplete="new-password"
278 onInput={linkEvent(this, this.handleOldPasswordChange)}
282 <div class="form-group">
283 <button type="submit" class="btn btn-block btn-secondary mr-4">
284 {this.state.changePasswordLoading ? (
287 capitalizeFirstLetter(i18n.t("save"))
299 {this.blockUserForm()}
300 {this.blockedUsersList()}
308 <h5>{i18n.t("blocked_users")}</h5>
309 <ul class="list-unstyled mb-0">
310 {this.state.personBlocks.map(pb => (
313 <PersonListing person={pb.target} />
315 className="btn btn-sm"
317 { ctx: this, recipientId: pb.target.id },
318 this.handleUnblockPerson
320 data-tippy-content={i18n.t("unblock_user")}
322 <Icon icon="x" classes="icon-inline" />
334 <div class="form-group row">
335 <label class="col-md-4 col-form-label" htmlFor="block-person-filter">
336 {i18n.t("block_user")}
338 <div class="col-md-8">
341 id="block-person-filter"
342 value={this.state.blockPersonId}
344 <option value="0">—</option>
345 {this.state.blockPerson && (
346 <option value={this.state.blockPerson.person.id}>
347 {personSelectName(this.state.blockPerson)}
356 blockCommunityCard() {
359 {this.blockCommunityForm()}
360 {this.blockedCommunitiesList()}
365 blockedCommunitiesList() {
368 <h5>{i18n.t("blocked_communities")}</h5>
369 <ul class="list-unstyled mb-0">
370 {this.state.communityBlocks.map(cb => (
373 <CommunityLink community={cb.community} />
375 className="btn btn-sm"
377 { ctx: this, communityId: cb.community.id },
378 this.handleUnblockCommunity
380 data-tippy-content={i18n.t("unblock_community")}
382 <Icon icon="x" classes="icon-inline" />
392 blockCommunityForm() {
394 <div class="form-group row">
395 <label class="col-md-4 col-form-label" htmlFor="block-community-filter">
396 {i18n.t("block_community")}
398 <div class="col-md-8">
401 id="block-community-filter"
402 value={this.state.blockCommunityId}
404 <option value="0">—</option>
405 {this.state.blockCommunity && (
406 <option value={this.state.blockCommunity.community.id}>
407 {communitySelectName(this.state.blockCommunity)}
416 saveUserSettingsHtmlForm() {
419 <h5>{i18n.t("settings")}</h5>
420 <form onSubmit={linkEvent(this, this.handleSaveSettingsSubmit)}>
421 <div class="form-group row">
422 <label class="col-sm-5 col-form-label" htmlFor="display-name">
423 {i18n.t("display_name")}
425 <div class="col-sm-7">
430 placeholder={i18n.t("optional")}
431 value={this.state.saveUserSettingsForm.display_name}
432 onInput={linkEvent(this, this.handleDisplayNameChange)}
433 pattern="^(?!@)(.+)$"
438 <div class="form-group row">
439 <label class="col-sm-3 col-form-label" htmlFor="user-bio">
442 <div class="col-sm-9">
444 initialContent={this.state.saveUserSettingsForm.bio}
445 onContentChange={this.handleBioChange}
447 hideNavigationWarnings
451 <div class="form-group row">
452 <label class="col-sm-3 col-form-label" htmlFor="user-email">
455 <div class="col-sm-9">
460 placeholder={i18n.t("optional")}
461 value={this.state.saveUserSettingsForm.email}
462 onInput={linkEvent(this, this.handleEmailChange)}
467 <div class="form-group row">
468 <label class="col-sm-5 col-form-label" htmlFor="matrix-user-id">
469 <a href={elementUrl} rel="noopener">
470 {i18n.t("matrix_user_id")}
473 <div class="col-sm-7">
478 placeholder="@user:example.com"
479 value={this.state.saveUserSettingsForm.matrix_user_id}
480 onInput={linkEvent(this, this.handleMatrixUserIdChange)}
481 pattern="^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"
485 <div class="form-group row">
486 <label class="col-sm-3">{i18n.t("avatar")}</label>
487 <div class="col-sm-9">
489 uploadTitle={i18n.t("upload_avatar")}
490 imageSrc={this.state.saveUserSettingsForm.avatar}
491 onUpload={this.handleAvatarUpload}
492 onRemove={this.handleAvatarRemove}
497 <div class="form-group row">
498 <label class="col-sm-3">{i18n.t("banner")}</label>
499 <div class="col-sm-9">
501 uploadTitle={i18n.t("upload_banner")}
502 imageSrc={this.state.saveUserSettingsForm.banner}
503 onUpload={this.handleBannerUpload}
504 onRemove={this.handleBannerRemove}
508 <div class="form-group row">
509 <label class="col-sm-3" htmlFor="user-language">
512 <div class="col-sm-9">
515 value={this.state.saveUserSettingsForm.lang}
516 onChange={linkEvent(this, this.handleLangChange)}
517 class="custom-select w-auto"
519 <option disabled aria-hidden="true">
522 <option value="browser">{i18n.t("browser_default")}</option>
523 <option disabled aria-hidden="true">
527 .sort((a, b) => a.code.localeCompare(b.code))
529 <option value={lang.code}>
530 {getNativeLanguageName(lang.code)}
536 <div class="form-group row">
537 <label class="col-sm-3" htmlFor="user-theme">
540 <div class="col-sm-9">
543 value={this.state.saveUserSettingsForm.theme}
544 onChange={linkEvent(this, this.handleThemeChange)}
545 class="custom-select w-auto"
547 <option disabled aria-hidden="true">
550 <option value="browser">{i18n.t("browser_default")}</option>
551 {themes.map(theme => (
552 <option value={theme}>{theme}</option>
557 <form className="form-group row">
558 <label class="col-sm-3">{i18n.t("type")}</label>
559 <div class="col-sm-9">
562 Object.values(ListingType)[
563 this.state.saveUserSettingsForm.default_listing_type
566 showLocal={showLocal(this.isoData)}
567 onChange={this.handleListingTypeChange}
571 <form className="form-group row">
572 <label class="col-sm-3">{i18n.t("sort_type")}</label>
573 <div class="col-sm-9">
576 Object.values(SortType)[
577 this.state.saveUserSettingsForm.default_sort_type
580 onChange={this.handleSortTypeChange}
584 {this.state.siteRes.site_view.site.enable_nsfw && (
585 <div class="form-group">
586 <div class="form-check">
588 class="form-check-input"
591 checked={this.state.saveUserSettingsForm.show_nsfw}
592 onChange={linkEvent(this, this.handleShowNsfwChange)}
594 <label class="form-check-label" htmlFor="user-show-nsfw">
595 {i18n.t("show_nsfw")}
600 <div class="form-group">
601 <div class="form-check">
603 class="form-check-input"
604 id="user-show-scores"
606 checked={this.state.saveUserSettingsForm.show_scores}
607 onChange={linkEvent(this, this.handleShowScoresChange)}
609 <label class="form-check-label" htmlFor="user-show-scores">
610 {i18n.t("show_scores")}
614 <div class="form-group">
615 <div class="form-check">
617 class="form-check-input"
618 id="user-show-avatars"
620 checked={this.state.saveUserSettingsForm.show_avatars}
621 onChange={linkEvent(this, this.handleShowAvatarsChange)}
623 <label class="form-check-label" htmlFor="user-show-avatars">
624 {i18n.t("show_avatars")}
628 <div class="form-group">
629 <div class="form-check">
631 class="form-check-input"
632 id="user-bot-account"
634 checked={this.state.saveUserSettingsForm.bot_account}
635 onChange={linkEvent(this, this.handleBotAccount)}
637 <label class="form-check-label" htmlFor="user-bot-account">
638 {i18n.t("bot_account")}
642 <div class="form-group">
643 <div class="form-check">
645 class="form-check-input"
646 id="user-show-bot-accounts"
648 checked={this.state.saveUserSettingsForm.show_bot_accounts}
649 onChange={linkEvent(this, this.handleShowBotAccounts)}
651 <label class="form-check-label" htmlFor="user-show-bot-accounts">
652 {i18n.t("show_bot_accounts")}
656 <div class="form-group">
657 <div class="form-check">
659 class="form-check-input"
660 id="user-show-read-posts"
662 checked={this.state.saveUserSettingsForm.show_read_posts}
663 onChange={linkEvent(this, this.handleReadPosts)}
665 <label class="form-check-label" htmlFor="user-show-read-posts">
666 {i18n.t("show_read_posts")}
670 <div class="form-group">
671 <div class="form-check">
673 class="form-check-input"
674 id="user-show-new-post-notifs"
676 checked={this.state.saveUserSettingsForm.show_new_post_notifs}
677 onChange={linkEvent(this, this.handleShowNewPostNotifs)}
680 class="form-check-label"
681 htmlFor="user-show-new-post-notifs"
683 {i18n.t("show_new_post_notifs")}
687 <div class="form-group">
688 <div class="form-check">
690 class="form-check-input"
691 id="user-send-notifications-to-email"
693 disabled={!this.state.saveUserSettingsForm.email}
695 this.state.saveUserSettingsForm.send_notifications_to_email
699 this.handleSendNotificationsToEmailChange
703 class="form-check-label"
704 htmlFor="user-send-notifications-to-email"
706 {i18n.t("send_notifications_to_email")}
710 <div class="form-group">
711 <button type="submit" class="btn btn-block btn-secondary mr-4">
712 {this.state.saveUserSettingsLoading ? (
715 capitalizeFirstLetter(i18n.t("save"))
720 <div class="form-group">
722 class="btn btn-block btn-danger"
725 this.handleDeleteAccountShowConfirmToggle
728 {i18n.t("delete_account")}
730 {this.state.deleteAccountShowConfirm && (
732 <div class="my-2 alert alert-danger" role="alert">
733 {i18n.t("delete_account_confirm")}
737 value={this.state.deleteAccountForm.password}
738 autoComplete="new-password"
742 this.handleDeleteAccountPasswordChange
744 class="form-control my-2"
747 class="btn btn-danger mr-4"
748 disabled={!this.state.deleteAccountForm.password}
749 onClick={linkEvent(this, this.handleDeleteAccount)}
751 {this.state.deleteAccountLoading ? (
754 capitalizeFirstLetter(i18n.t("delete"))
758 class="btn btn-secondary"
761 this.handleDeleteAccountShowConfirmToggle
774 setupBlockPersonChoices() {
776 let selectId: any = document.getElementById("block-person-filter");
778 this.blockPersonChoices = new Choices(selectId, choicesConfig);
779 this.blockPersonChoices.passedElement.element.addEventListener(
782 this.handleBlockPerson(Number(e.detail.choice.value));
786 this.blockPersonChoices.passedElement.element.addEventListener(
788 debounce(async (e: any) => {
790 let persons = (await fetchUsers(e.detail.value)).users;
791 let choices = persons.map(pvs => personToChoice(pvs));
792 this.blockPersonChoices.setChoices(
808 setupBlockCommunityChoices() {
810 let selectId: any = document.getElementById("block-community-filter");
812 this.blockCommunityChoices = new Choices(selectId, choicesConfig);
813 this.blockCommunityChoices.passedElement.element.addEventListener(
816 this.handleBlockCommunity(Number(e.detail.choice.value));
820 this.blockCommunityChoices.passedElement.element.addEventListener(
822 debounce(async (e: any) => {
824 let communities = (await fetchCommunities(e.detail.value))
826 let choices = communities.map(cv => communityToChoice(cv));
827 this.blockCommunityChoices.setChoices(
843 handleBlockPerson(personId: number) {
845 let blockUserForm: BlockPerson = {
850 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
854 handleUnblockPerson(i: { ctx: Settings; recipientId: number }) {
855 let blockUserForm: BlockPerson = {
856 person_id: i.recipientId,
860 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
863 handleBlockCommunity(community_id: number) {
864 if (community_id != 0) {
865 let blockCommunityForm: BlockCommunity = {
870 WebSocketService.Instance.send(
871 wsClient.blockCommunity(blockCommunityForm)
876 handleUnblockCommunity(i: { ctx: Settings; communityId: number }) {
877 let blockCommunityForm: BlockCommunity = {
878 community_id: i.communityId,
882 WebSocketService.Instance.send(wsClient.blockCommunity(blockCommunityForm));
885 handleShowNsfwChange(i: Settings, event: any) {
886 i.state.saveUserSettingsForm.show_nsfw = event.target.checked;
890 handleShowAvatarsChange(i: Settings, event: any) {
891 i.state.saveUserSettingsForm.show_avatars = event.target.checked;
892 UserService.Instance.myUserInfo.local_user_view.local_user.show_avatars =
893 event.target.checked; // Just for instant updates
897 handleBotAccount(i: Settings, event: any) {
898 i.state.saveUserSettingsForm.bot_account = event.target.checked;
902 handleShowBotAccounts(i: Settings, event: any) {
903 i.state.saveUserSettingsForm.show_bot_accounts = event.target.checked;
907 handleReadPosts(i: Settings, event: any) {
908 i.state.saveUserSettingsForm.show_read_posts = event.target.checked;
912 handleShowNewPostNotifs(i: Settings, event: any) {
913 i.state.saveUserSettingsForm.show_new_post_notifs = event.target.checked;
917 handleShowScoresChange(i: Settings, event: any) {
918 i.state.saveUserSettingsForm.show_scores = event.target.checked;
919 UserService.Instance.myUserInfo.local_user_view.local_user.show_scores =
920 event.target.checked; // Just for instant updates
924 handleSendNotificationsToEmailChange(i: Settings, event: any) {
925 i.state.saveUserSettingsForm.send_notifications_to_email =
926 event.target.checked;
930 handleThemeChange(i: Settings, event: any) {
931 i.state.saveUserSettingsForm.theme = event.target.value;
932 setTheme(event.target.value, true);
936 handleLangChange(i: Settings, event: any) {
937 i.state.saveUserSettingsForm.lang = event.target.value;
938 i18n.changeLanguage(getLanguage(i.state.saveUserSettingsForm.lang));
942 handleSortTypeChange(val: SortType) {
943 this.state.saveUserSettingsForm.default_sort_type =
944 Object.keys(SortType).indexOf(val);
945 this.setState(this.state);
948 handleListingTypeChange(val: ListingType) {
949 this.state.saveUserSettingsForm.default_listing_type =
950 Object.keys(ListingType).indexOf(val);
951 this.setState(this.state);
954 handleEmailChange(i: Settings, event: any) {
955 i.state.saveUserSettingsForm.email = event.target.value;
959 handleBioChange(val: string) {
960 this.state.saveUserSettingsForm.bio = val;
961 this.setState(this.state);
964 handleAvatarUpload(url: string) {
965 this.state.saveUserSettingsForm.avatar = url;
966 this.setState(this.state);
969 handleAvatarRemove() {
970 this.state.saveUserSettingsForm.avatar = "";
971 this.setState(this.state);
974 handleBannerUpload(url: string) {
975 this.state.saveUserSettingsForm.banner = url;
976 this.setState(this.state);
979 handleBannerRemove() {
980 this.state.saveUserSettingsForm.banner = "";
981 this.setState(this.state);
984 handleDisplayNameChange(i: Settings, event: any) {
985 i.state.saveUserSettingsForm.display_name = event.target.value;
989 handleMatrixUserIdChange(i: Settings, event: any) {
990 i.state.saveUserSettingsForm.matrix_user_id = event.target.value;
992 i.state.saveUserSettingsForm.matrix_user_id == "" &&
993 !UserService.Instance.myUserInfo.local_user_view.person.matrix_user_id
995 i.state.saveUserSettingsForm.matrix_user_id = undefined;
1000 handleNewPasswordChange(i: Settings, event: any) {
1001 i.state.changePasswordForm.new_password = event.target.value;
1002 if (i.state.changePasswordForm.new_password == "") {
1003 i.state.changePasswordForm.new_password = undefined;
1005 i.setState(i.state);
1008 handleNewPasswordVerifyChange(i: Settings, event: any) {
1009 i.state.changePasswordForm.new_password_verify = event.target.value;
1010 if (i.state.changePasswordForm.new_password_verify == "") {
1011 i.state.changePasswordForm.new_password_verify = undefined;
1013 i.setState(i.state);
1016 handleOldPasswordChange(i: Settings, event: any) {
1017 i.state.changePasswordForm.old_password = event.target.value;
1018 if (i.state.changePasswordForm.old_password == "") {
1019 i.state.changePasswordForm.old_password = undefined;
1021 i.setState(i.state);
1024 handleSaveSettingsSubmit(i: Settings, event: any) {
1025 event.preventDefault();
1026 i.state.saveUserSettingsLoading = true;
1027 i.setState(i.state);
1029 WebSocketService.Instance.send(
1030 wsClient.saveUserSettings(i.state.saveUserSettingsForm)
1034 handleChangePasswordSubmit(i: Settings, event: any) {
1035 event.preventDefault();
1036 i.state.changePasswordLoading = true;
1037 i.setState(i.state);
1039 WebSocketService.Instance.send(
1040 wsClient.changePassword(i.state.changePasswordForm)
1044 handleDeleteAccountShowConfirmToggle(i: Settings, event: any) {
1045 event.preventDefault();
1046 i.state.deleteAccountShowConfirm = !i.state.deleteAccountShowConfirm;
1047 i.setState(i.state);
1050 handleDeleteAccountPasswordChange(i: Settings, event: any) {
1051 i.state.deleteAccountForm.password = event.target.value;
1052 i.setState(i.state);
1055 handleDeleteAccount(i: Settings, event: any) {
1056 event.preventDefault();
1057 i.state.deleteAccountLoading = true;
1058 i.setState(i.state);
1060 WebSocketService.Instance.send(
1061 wsClient.deleteAccount(i.state.deleteAccountForm)
1065 handleSwitchTab(i: { ctx: Settings; tab: string }) {
1066 i.ctx.setState({ currentTab: i.tab });
1068 if (i.ctx.state.currentTab == "blocks") {
1069 i.ctx.setupBlockPersonChoices();
1070 i.ctx.setupBlockCommunityChoices();
1075 let luv = UserService.Instance.myUserInfo.local_user_view;
1076 this.state.saveUserSettingsForm.show_nsfw = luv.local_user.show_nsfw;
1077 this.state.saveUserSettingsForm.theme = luv.local_user.theme
1078 ? luv.local_user.theme
1080 this.state.saveUserSettingsForm.default_sort_type =
1081 luv.local_user.default_sort_type;
1082 this.state.saveUserSettingsForm.default_listing_type =
1083 luv.local_user.default_listing_type;
1084 this.state.saveUserSettingsForm.lang = luv.local_user.lang;
1085 this.state.saveUserSettingsForm.avatar = luv.person.avatar;
1086 this.state.saveUserSettingsForm.banner = luv.person.banner;
1087 this.state.saveUserSettingsForm.display_name = luv.person.display_name;
1088 this.state.saveUserSettingsForm.show_avatars = luv.local_user.show_avatars;
1089 this.state.saveUserSettingsForm.bot_account = luv.person.bot_account;
1090 this.state.saveUserSettingsForm.show_bot_accounts =
1091 luv.local_user.show_bot_accounts;
1092 this.state.saveUserSettingsForm.show_scores = luv.local_user.show_scores;
1093 this.state.saveUserSettingsForm.show_read_posts =
1094 luv.local_user.show_read_posts;
1095 this.state.saveUserSettingsForm.show_new_post_notifs =
1096 luv.local_user.show_new_post_notifs;
1097 this.state.saveUserSettingsForm.email = luv.local_user.email;
1098 this.state.saveUserSettingsForm.bio = luv.person.bio;
1099 this.state.saveUserSettingsForm.send_notifications_to_email =
1100 luv.local_user.send_notifications_to_email;
1101 this.state.saveUserSettingsForm.matrix_user_id = luv.person.matrix_user_id;
1102 this.state.personBlocks = UserService.Instance.myUserInfo.person_blocks;
1103 this.state.communityBlocks =
1104 UserService.Instance.myUserInfo.community_blocks;
1107 parseMessage(msg: any) {
1108 let op = wsUserOp(msg);
1112 saveUserSettingsLoading: false,
1113 changePasswordLoading: false,
1114 deleteAccountLoading: false,
1116 toast(i18n.t(msg.error), "danger");
1118 } else if (op == UserOperation.SaveUserSettings) {
1119 let data = wsJsonToRes<LoginResponse>(msg).data;
1120 UserService.Instance.login(data);
1121 this.state.saveUserSettingsLoading = false;
1122 this.setState(this.state);
1124 window.scrollTo(0, 0);
1125 } else if (op == UserOperation.ChangePassword) {
1126 let data = wsJsonToRes<LoginResponse>(msg).data;
1127 UserService.Instance.login(data);
1128 this.state.changePasswordLoading = false;
1129 this.setState(this.state);
1130 window.scrollTo(0, 0);
1131 toast(i18n.t("password_changed"));
1132 } else if (op == UserOperation.DeleteAccount) {
1134 deleteAccountLoading: false,
1135 deleteAccountShowConfirm: false,
1137 UserService.Instance.logout();
1138 window.location.href = "/";
1140 } else if (op == UserOperation.BlockPerson) {
1141 let data = wsJsonToRes<BlockPersonResponse>(msg).data;
1142 this.setState({ personBlocks: updatePersonBlock(data) });
1143 } else if (op == UserOperation.BlockCommunity) {
1144 let data = wsJsonToRes<BlockCommunityResponse>(msg).data;
1145 this.setState({ communityBlocks: updateCommunityBlock(data) });