1 import { Component, linkEvent } from "inferno";
2 import ISO6391 from "iso-639-1";
5 BlockCommunityResponse,
20 } from "lemmy-js-client";
21 import { Subscription } from "rxjs";
22 import { i18n } from "../../i18next";
23 import { UserService, WebSocketService } from "../../services";
26 capitalizeFirstLetter,
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">
526 {languages.sort().map(lang => (
527 <option value={lang.code}>
528 {ISO6391.getNativeName(lang.code) || lang.code}
534 <div class="form-group row">
535 <label class="col-sm-3" htmlFor="user-theme">
538 <div class="col-sm-9">
541 value={this.state.saveUserSettingsForm.theme}
542 onChange={linkEvent(this, this.handleThemeChange)}
543 class="custom-select w-auto"
545 <option disabled aria-hidden="true">
548 <option value="browser">{i18n.t("browser_default")}</option>
549 {themes.map(theme => (
550 <option value={theme}>{theme}</option>
555 <form className="form-group row">
556 <label class="col-sm-3">{i18n.t("type")}</label>
557 <div class="col-sm-9">
560 Object.values(ListingType)[
561 this.state.saveUserSettingsForm.default_listing_type
564 showLocal={showLocal(this.isoData)}
565 onChange={this.handleListingTypeChange}
569 <form className="form-group row">
570 <label class="col-sm-3">{i18n.t("sort_type")}</label>
571 <div class="col-sm-9">
574 Object.values(SortType)[
575 this.state.saveUserSettingsForm.default_sort_type
578 onChange={this.handleSortTypeChange}
582 {this.state.siteRes.site_view.site.enable_nsfw && (
583 <div class="form-group">
584 <div class="form-check">
586 class="form-check-input"
589 checked={this.state.saveUserSettingsForm.show_nsfw}
590 onChange={linkEvent(this, this.handleShowNsfwChange)}
592 <label class="form-check-label" htmlFor="user-show-nsfw">
593 {i18n.t("show_nsfw")}
598 <div class="form-group">
599 <div class="form-check">
601 class="form-check-input"
602 id="user-show-scores"
604 checked={this.state.saveUserSettingsForm.show_scores}
605 onChange={linkEvent(this, this.handleShowScoresChange)}
607 <label class="form-check-label" htmlFor="user-show-scores">
608 {i18n.t("show_scores")}
612 <div class="form-group">
613 <div class="form-check">
615 class="form-check-input"
616 id="user-show-avatars"
618 checked={this.state.saveUserSettingsForm.show_avatars}
619 onChange={linkEvent(this, this.handleShowAvatarsChange)}
621 <label class="form-check-label" htmlFor="user-show-avatars">
622 {i18n.t("show_avatars")}
626 <div class="form-group">
627 <div class="form-check">
629 class="form-check-input"
630 id="user-bot-account"
632 checked={this.state.saveUserSettingsForm.bot_account}
633 onChange={linkEvent(this, this.handleBotAccount)}
635 <label class="form-check-label" htmlFor="user-bot-account">
636 {i18n.t("bot_account")}
640 <div class="form-group">
641 <div class="form-check">
643 class="form-check-input"
644 id="user-show-bot-accounts"
646 checked={this.state.saveUserSettingsForm.show_bot_accounts}
647 onChange={linkEvent(this, this.handleShowBotAccounts)}
649 <label class="form-check-label" htmlFor="user-show-bot-accounts">
650 {i18n.t("show_bot_accounts")}
654 <div class="form-group">
655 <div class="form-check">
657 class="form-check-input"
658 id="user-show-read-posts"
660 checked={this.state.saveUserSettingsForm.show_read_posts}
661 onChange={linkEvent(this, this.handleReadPosts)}
663 <label class="form-check-label" htmlFor="user-show-read-posts">
664 {i18n.t("show_read_posts")}
668 <div class="form-group">
669 <div class="form-check">
671 class="form-check-input"
672 id="user-show-new-post-notifs"
674 checked={this.state.saveUserSettingsForm.show_new_post_notifs}
675 onChange={linkEvent(this, this.handleShowNewPostNotifs)}
678 class="form-check-label"
679 htmlFor="user-show-new-post-notifs"
681 {i18n.t("show_new_post_notifs")}
685 <div class="form-group">
686 <div class="form-check">
688 class="form-check-input"
689 id="user-send-notifications-to-email"
691 disabled={!this.state.saveUserSettingsForm.email}
693 this.state.saveUserSettingsForm.send_notifications_to_email
697 this.handleSendNotificationsToEmailChange
701 class="form-check-label"
702 htmlFor="user-send-notifications-to-email"
704 {i18n.t("send_notifications_to_email")}
708 <div class="form-group">
709 <button type="submit" class="btn btn-block btn-secondary mr-4">
710 {this.state.saveUserSettingsLoading ? (
713 capitalizeFirstLetter(i18n.t("save"))
718 <div class="form-group">
720 class="btn btn-block btn-danger"
723 this.handleDeleteAccountShowConfirmToggle
726 {i18n.t("delete_account")}
728 {this.state.deleteAccountShowConfirm && (
730 <div class="my-2 alert alert-danger" role="alert">
731 {i18n.t("delete_account_confirm")}
735 value={this.state.deleteAccountForm.password}
736 autoComplete="new-password"
740 this.handleDeleteAccountPasswordChange
742 class="form-control my-2"
745 class="btn btn-danger mr-4"
746 disabled={!this.state.deleteAccountForm.password}
747 onClick={linkEvent(this, this.handleDeleteAccount)}
749 {this.state.deleteAccountLoading ? (
752 capitalizeFirstLetter(i18n.t("delete"))
756 class="btn btn-secondary"
759 this.handleDeleteAccountShowConfirmToggle
772 setupBlockPersonChoices() {
774 let selectId: any = document.getElementById("block-person-filter");
776 this.blockPersonChoices = new Choices(selectId, choicesConfig);
777 this.blockPersonChoices.passedElement.element.addEventListener(
780 this.handleBlockPerson(Number(e.detail.choice.value));
784 this.blockPersonChoices.passedElement.element.addEventListener(
786 debounce(async (e: any) => {
788 let persons = (await fetchUsers(e.detail.value)).users;
789 let choices = persons.map(pvs => personToChoice(pvs));
790 this.blockPersonChoices.setChoices(
806 setupBlockCommunityChoices() {
808 let selectId: any = document.getElementById("block-community-filter");
810 this.blockCommunityChoices = new Choices(selectId, choicesConfig);
811 this.blockCommunityChoices.passedElement.element.addEventListener(
814 this.handleBlockCommunity(Number(e.detail.choice.value));
818 this.blockCommunityChoices.passedElement.element.addEventListener(
820 debounce(async (e: any) => {
822 let communities = (await fetchCommunities(e.detail.value))
824 let choices = communities.map(cv => communityToChoice(cv));
825 this.blockCommunityChoices.setChoices(
841 handleBlockPerson(personId: number) {
843 let blockUserForm: BlockPerson = {
848 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
852 handleUnblockPerson(i: { ctx: Settings; recipientId: number }) {
853 let blockUserForm: BlockPerson = {
854 person_id: i.recipientId,
858 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
861 handleBlockCommunity(community_id: number) {
862 if (community_id != 0) {
863 let blockCommunityForm: BlockCommunity = {
868 WebSocketService.Instance.send(
869 wsClient.blockCommunity(blockCommunityForm)
874 handleUnblockCommunity(i: { ctx: Settings; communityId: number }) {
875 let blockCommunityForm: BlockCommunity = {
876 community_id: i.communityId,
880 WebSocketService.Instance.send(wsClient.blockCommunity(blockCommunityForm));
883 handleShowNsfwChange(i: Settings, event: any) {
884 i.state.saveUserSettingsForm.show_nsfw = event.target.checked;
888 handleShowAvatarsChange(i: Settings, event: any) {
889 i.state.saveUserSettingsForm.show_avatars = event.target.checked;
890 UserService.Instance.myUserInfo.local_user_view.local_user.show_avatars =
891 event.target.checked; // Just for instant updates
895 handleBotAccount(i: Settings, event: any) {
896 i.state.saveUserSettingsForm.bot_account = event.target.checked;
900 handleShowBotAccounts(i: Settings, event: any) {
901 i.state.saveUserSettingsForm.show_bot_accounts = event.target.checked;
905 handleReadPosts(i: Settings, event: any) {
906 i.state.saveUserSettingsForm.show_read_posts = event.target.checked;
910 handleShowNewPostNotifs(i: Settings, event: any) {
911 i.state.saveUserSettingsForm.show_new_post_notifs = event.target.checked;
915 handleShowScoresChange(i: Settings, event: any) {
916 i.state.saveUserSettingsForm.show_scores = event.target.checked;
917 UserService.Instance.myUserInfo.local_user_view.local_user.show_scores =
918 event.target.checked; // Just for instant updates
922 handleSendNotificationsToEmailChange(i: Settings, event: any) {
923 i.state.saveUserSettingsForm.send_notifications_to_email =
924 event.target.checked;
928 handleThemeChange(i: Settings, event: any) {
929 i.state.saveUserSettingsForm.theme = event.target.value;
930 setTheme(event.target.value, true);
934 handleLangChange(i: Settings, event: any) {
935 i.state.saveUserSettingsForm.lang = event.target.value;
936 i18n.changeLanguage(getLanguage(i.state.saveUserSettingsForm.lang));
940 handleSortTypeChange(val: SortType) {
941 this.state.saveUserSettingsForm.default_sort_type =
942 Object.keys(SortType).indexOf(val);
943 this.setState(this.state);
946 handleListingTypeChange(val: ListingType) {
947 this.state.saveUserSettingsForm.default_listing_type =
948 Object.keys(ListingType).indexOf(val);
949 this.setState(this.state);
952 handleEmailChange(i: Settings, event: any) {
953 i.state.saveUserSettingsForm.email = event.target.value;
957 handleBioChange(val: string) {
958 this.state.saveUserSettingsForm.bio = val;
959 this.setState(this.state);
962 handleAvatarUpload(url: string) {
963 this.state.saveUserSettingsForm.avatar = url;
964 this.setState(this.state);
967 handleAvatarRemove() {
968 this.state.saveUserSettingsForm.avatar = "";
969 this.setState(this.state);
972 handleBannerUpload(url: string) {
973 this.state.saveUserSettingsForm.banner = url;
974 this.setState(this.state);
977 handleBannerRemove() {
978 this.state.saveUserSettingsForm.banner = "";
979 this.setState(this.state);
982 handleDisplayNameChange(i: Settings, event: any) {
983 i.state.saveUserSettingsForm.display_name = event.target.value;
987 handleMatrixUserIdChange(i: Settings, event: any) {
988 i.state.saveUserSettingsForm.matrix_user_id = event.target.value;
990 i.state.saveUserSettingsForm.matrix_user_id == "" &&
991 !UserService.Instance.myUserInfo.local_user_view.person.matrix_user_id
993 i.state.saveUserSettingsForm.matrix_user_id = undefined;
998 handleNewPasswordChange(i: Settings, event: any) {
999 i.state.changePasswordForm.new_password = event.target.value;
1000 if (i.state.changePasswordForm.new_password == "") {
1001 i.state.changePasswordForm.new_password = undefined;
1003 i.setState(i.state);
1006 handleNewPasswordVerifyChange(i: Settings, event: any) {
1007 i.state.changePasswordForm.new_password_verify = event.target.value;
1008 if (i.state.changePasswordForm.new_password_verify == "") {
1009 i.state.changePasswordForm.new_password_verify = undefined;
1011 i.setState(i.state);
1014 handleOldPasswordChange(i: Settings, event: any) {
1015 i.state.changePasswordForm.old_password = event.target.value;
1016 if (i.state.changePasswordForm.old_password == "") {
1017 i.state.changePasswordForm.old_password = undefined;
1019 i.setState(i.state);
1022 handleSaveSettingsSubmit(i: Settings, event: any) {
1023 event.preventDefault();
1024 i.state.saveUserSettingsLoading = true;
1025 i.setState(i.state);
1027 WebSocketService.Instance.send(
1028 wsClient.saveUserSettings(i.state.saveUserSettingsForm)
1032 handleChangePasswordSubmit(i: Settings, event: any) {
1033 event.preventDefault();
1034 i.state.changePasswordLoading = true;
1035 i.setState(i.state);
1037 WebSocketService.Instance.send(
1038 wsClient.changePassword(i.state.changePasswordForm)
1042 handleDeleteAccountShowConfirmToggle(i: Settings, event: any) {
1043 event.preventDefault();
1044 i.state.deleteAccountShowConfirm = !i.state.deleteAccountShowConfirm;
1045 i.setState(i.state);
1048 handleDeleteAccountPasswordChange(i: Settings, event: any) {
1049 i.state.deleteAccountForm.password = event.target.value;
1050 i.setState(i.state);
1053 handleDeleteAccount(i: Settings, event: any) {
1054 event.preventDefault();
1055 i.state.deleteAccountLoading = true;
1056 i.setState(i.state);
1058 WebSocketService.Instance.send(
1059 wsClient.deleteAccount(i.state.deleteAccountForm)
1063 handleSwitchTab(i: { ctx: Settings; tab: string }) {
1064 i.ctx.setState({ currentTab: i.tab });
1066 if (i.ctx.state.currentTab == "blocks") {
1067 i.ctx.setupBlockPersonChoices();
1068 i.ctx.setupBlockCommunityChoices();
1073 let luv = UserService.Instance.myUserInfo.local_user_view;
1074 this.state.saveUserSettingsForm.show_nsfw = luv.local_user.show_nsfw;
1075 this.state.saveUserSettingsForm.theme = luv.local_user.theme
1076 ? luv.local_user.theme
1078 this.state.saveUserSettingsForm.default_sort_type =
1079 luv.local_user.default_sort_type;
1080 this.state.saveUserSettingsForm.default_listing_type =
1081 luv.local_user.default_listing_type;
1082 this.state.saveUserSettingsForm.lang = luv.local_user.lang;
1083 this.state.saveUserSettingsForm.avatar = luv.person.avatar;
1084 this.state.saveUserSettingsForm.banner = luv.person.banner;
1085 this.state.saveUserSettingsForm.display_name = luv.person.display_name;
1086 this.state.saveUserSettingsForm.show_avatars = luv.local_user.show_avatars;
1087 this.state.saveUserSettingsForm.bot_account = luv.person.bot_account;
1088 this.state.saveUserSettingsForm.show_bot_accounts =
1089 luv.local_user.show_bot_accounts;
1090 this.state.saveUserSettingsForm.show_scores = luv.local_user.show_scores;
1091 this.state.saveUserSettingsForm.show_read_posts =
1092 luv.local_user.show_read_posts;
1093 this.state.saveUserSettingsForm.show_new_post_notifs =
1094 luv.local_user.show_new_post_notifs;
1095 this.state.saveUserSettingsForm.email = luv.local_user.email;
1096 this.state.saveUserSettingsForm.bio = luv.person.bio;
1097 this.state.saveUserSettingsForm.send_notifications_to_email =
1098 luv.local_user.send_notifications_to_email;
1099 this.state.saveUserSettingsForm.matrix_user_id = luv.person.matrix_user_id;
1100 this.state.personBlocks = UserService.Instance.myUserInfo.person_blocks;
1101 this.state.communityBlocks =
1102 UserService.Instance.myUserInfo.community_blocks;
1105 parseMessage(msg: any) {
1106 let op = wsUserOp(msg);
1109 toast(i18n.t(msg.error), "danger");
1111 } else if (op == UserOperation.SaveUserSettings) {
1112 let data = wsJsonToRes<LoginResponse>(msg).data;
1113 UserService.Instance.login(data);
1114 this.state.saveUserSettingsLoading = false;
1115 this.setState(this.state);
1117 window.scrollTo(0, 0);
1118 } else if (op == UserOperation.ChangePassword) {
1119 let data = wsJsonToRes<LoginResponse>(msg).data;
1120 UserService.Instance.login(data);
1121 this.state.changePasswordLoading = false;
1122 this.setState(this.state);
1123 window.scrollTo(0, 0);
1124 toast(i18n.t("password_changed"));
1125 } else if (op == UserOperation.DeleteAccount) {
1127 deleteAccountLoading: false,
1128 deleteAccountShowConfirm: false,
1130 UserService.Instance.logout();
1131 window.location.href = "/";
1133 } else if (op == UserOperation.BlockPerson) {
1134 let data = wsJsonToRes<BlockPersonResponse>(msg).data;
1135 this.setState({ personBlocks: updatePersonBlock(data) });
1136 } else if (op == UserOperation.BlockCommunity) {
1137 let data = wsJsonToRes<BlockCommunityResponse>(msg).data;
1138 this.setState({ communityBlocks: updateCommunityBlock(data) });