1 import { Component, linkEvent } from "inferno";
4 BlockCommunityResponse,
19 } from "lemmy-js-client";
20 import { Subscription } from "rxjs";
21 import { i18n, languages } from "../../i18next";
22 import { UserService, WebSocketService } from "../../services";
25 capitalizeFirstLetter,
51 import { HtmlTags } from "../common/html-tags";
52 import { Icon, Spinner } from "../common/icon";
53 import { ImageUploadForm } from "../common/image-upload-form";
54 import { ListingTypeSelect } from "../common/listing-type-select";
55 import { MarkdownTextArea } from "../common/markdown-textarea";
56 import { SortSelect } from "../common/sort-select";
57 import { CommunityLink } from "../community/community-link";
58 import { PersonListing } from "./person-listing";
62 Choices = require("choices.js");
65 interface SettingsState {
66 saveUserSettingsForm: SaveUserSettings;
67 changePasswordForm: ChangePassword;
68 saveUserSettingsLoading: boolean;
69 changePasswordLoading: boolean;
70 deleteAccountLoading: boolean;
71 deleteAccountShowConfirm: boolean;
72 deleteAccountForm: DeleteAccount;
73 personBlocks: PersonBlockView[];
74 blockPersonId: number;
75 blockPerson?: PersonViewSafe;
76 communityBlocks: CommunityBlockView[];
77 blockCommunityId: number;
78 blockCommunity?: CommunityView;
80 siteRes: GetSiteResponse;
83 export class Settings extends Component<any, SettingsState> {
84 private isoData = setIsoData(this.context);
85 private blockPersonChoices: any;
86 private blockCommunityChoices: any;
87 private subscription: Subscription;
88 private emptyState: SettingsState = {
89 saveUserSettingsForm: {
90 auth: authField(false),
94 new_password_verify: null,
96 auth: authField(false),
98 saveUserSettingsLoading: null,
99 changePasswordLoading: false,
100 deleteAccountLoading: null,
101 deleteAccountShowConfirm: false,
104 auth: authField(false),
110 currentTab: "settings",
111 siteRes: this.isoData.site_res,
114 constructor(props: any, context: any) {
115 super(props, context);
117 this.state = this.emptyState;
118 this.handleSortTypeChange = this.handleSortTypeChange.bind(this);
119 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
120 this.handleBioChange = this.handleBioChange.bind(this);
122 this.handleAvatarUpload = this.handleAvatarUpload.bind(this);
123 this.handleAvatarRemove = this.handleAvatarRemove.bind(this);
125 this.handleBannerUpload = this.handleBannerUpload.bind(this);
126 this.handleBannerRemove = this.handleBannerRemove.bind(this);
128 this.parseMessage = this.parseMessage.bind(this);
129 this.subscription = wsSubscribe(this.parseMessage);
134 componentDidMount() {
138 componentWillUnmount() {
139 this.subscription.unsubscribe();
142 get documentTitle(): string {
143 return i18n.t("settings");
148 <div class="container">
151 title={this.documentTitle}
152 path={this.context.router.route.match.url}
153 description={this.documentTitle}
154 image={this.state.saveUserSettingsForm.avatar}
156 <ul class="nav nav-tabs mb-2">
157 <li class="nav-item">
159 class={`nav-link btn ${
160 this.state.currentTab == "settings" && "active"
163 { ctx: this, tab: "settings" },
170 <li class="nav-item">
172 class={`nav-link btn ${
173 this.state.currentTab == "blocks" && "active"
176 { ctx: this, tab: "blocks" },
184 {this.state.currentTab == "settings" && this.userSettings()}
185 {this.state.currentTab == "blocks" && this.blockCards()}
194 <div class="col-12 col-md-6">
195 <div class="card border-secondary mb-3">
196 <div class="card-body">{this.saveUserSettingsHtmlForm()}</div>
199 <div class="col-12 col-md-6">
200 <div class="card border-secondary mb-3">
201 <div class="card-body">{this.changePasswordHtmlForm()}</div>
211 <div class="col-12 col-md-6">
212 <div class="card border-secondary mb-3">
213 <div class="card-body">{this.blockUserCard()}</div>
216 <div class="col-12 col-md-6">
217 <div class="card border-secondary mb-3">
218 <div class="card-body">{this.blockCommunityCard()}</div>
225 changePasswordHtmlForm() {
228 <h5>{i18n.t("change_password")}</h5>
229 <form onSubmit={linkEvent(this, this.handleChangePasswordSubmit)}>
230 <div class="form-group row">
231 <label class="col-sm-5 col-form-label" htmlFor="user-password">
232 {i18n.t("new_password")}
234 <div class="col-sm-7">
239 value={this.state.changePasswordForm.new_password}
240 autoComplete="new-password"
242 onInput={linkEvent(this, this.handleNewPasswordChange)}
246 <div class="form-group row">
248 class="col-sm-5 col-form-label"
249 htmlFor="user-verify-password"
251 {i18n.t("verify_password")}
253 <div class="col-sm-7">
256 id="user-verify-password"
258 value={this.state.changePasswordForm.new_password_verify}
259 autoComplete="new-password"
261 onInput={linkEvent(this, this.handleNewPasswordVerifyChange)}
265 <div class="form-group row">
266 <label class="col-sm-5 col-form-label" htmlFor="user-old-password">
267 {i18n.t("old_password")}
269 <div class="col-sm-7">
272 id="user-old-password"
274 value={this.state.changePasswordForm.old_password}
275 autoComplete="new-password"
277 onInput={linkEvent(this, this.handleOldPasswordChange)}
281 <div class="form-group">
282 <button type="submit" class="btn btn-block btn-secondary mr-4">
283 {this.state.changePasswordLoading ? (
286 capitalizeFirstLetter(i18n.t("save"))
298 {this.blockUserForm()}
299 {this.blockedUsersList()}
307 <h5>{i18n.t("blocked_users")}</h5>
308 <ul class="list-unstyled mb-0">
309 {this.state.personBlocks.map(pb => (
312 <PersonListing person={pb.target} />
314 className="btn btn-sm"
316 { ctx: this, recipientId: pb.target.id },
317 this.handleUnblockPerson
319 data-tippy-content={i18n.t("unblock_user")}
321 <Icon icon="x" classes="icon-inline" />
333 <div class="form-group row">
334 <label class="col-md-4 col-form-label" htmlFor="block-person-filter">
335 {i18n.t("block_user")}
337 <div class="col-md-8">
340 id="block-person-filter"
341 value={this.state.blockPersonId}
343 <option value="0">—</option>
344 {this.state.blockPerson && (
345 <option value={this.state.blockPerson.person.id}>
346 {personSelectName(this.state.blockPerson)}
355 blockCommunityCard() {
358 {this.blockCommunityForm()}
359 {this.blockedCommunitiesList()}
364 blockedCommunitiesList() {
367 <h5>{i18n.t("blocked_communities")}</h5>
368 <ul class="list-unstyled mb-0">
369 {this.state.communityBlocks.map(cb => (
372 <CommunityLink community={cb.community} />
374 className="btn btn-sm"
376 { ctx: this, communityId: cb.community.id },
377 this.handleUnblockCommunity
379 data-tippy-content={i18n.t("unblock_community")}
381 <Icon icon="x" classes="icon-inline" />
391 blockCommunityForm() {
393 <div class="form-group row">
394 <label class="col-md-4 col-form-label" htmlFor="block-community-filter">
395 {i18n.t("block_community")}
397 <div class="col-md-8">
400 id="block-community-filter"
401 value={this.state.blockCommunityId}
403 <option value="0">—</option>
404 {this.state.blockCommunity && (
405 <option value={this.state.blockCommunity.community.id}>
406 {communitySelectName(this.state.blockCommunity)}
415 saveUserSettingsHtmlForm() {
418 <h5>{i18n.t("settings")}</h5>
419 <form onSubmit={linkEvent(this, this.handleSaveSettingsSubmit)}>
420 <div class="form-group row">
421 <label class="col-sm-5 col-form-label" htmlFor="display-name">
422 {i18n.t("display_name")}
424 <div class="col-sm-7">
429 placeholder={i18n.t("optional")}
430 value={this.state.saveUserSettingsForm.display_name}
431 onInput={linkEvent(this, this.handleDisplayNameChange)}
432 pattern="^(?!@)(.+)$"
437 <div class="form-group row">
438 <label class="col-sm-3 col-form-label" htmlFor="user-bio">
441 <div class="col-sm-9">
443 initialContent={this.state.saveUserSettingsForm.bio}
444 onContentChange={this.handleBioChange}
446 hideNavigationWarnings
450 <div class="form-group row">
451 <label class="col-sm-3 col-form-label" htmlFor="user-email">
454 <div class="col-sm-9">
459 placeholder={i18n.t("optional")}
460 value={this.state.saveUserSettingsForm.email}
461 onInput={linkEvent(this, this.handleEmailChange)}
466 <div class="form-group row">
467 <label class="col-sm-5 col-form-label" htmlFor="matrix-user-id">
468 <a href={elementUrl} rel={relTags}>
469 {i18n.t("matrix_user_id")}
472 <div class="col-sm-7">
477 placeholder="@user:example.com"
478 value={this.state.saveUserSettingsForm.matrix_user_id}
479 onInput={linkEvent(this, this.handleMatrixUserIdChange)}
480 pattern="^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"
484 <div class="form-group row">
485 <label class="col-sm-3">{i18n.t("avatar")}</label>
486 <div class="col-sm-9">
488 uploadTitle={i18n.t("upload_avatar")}
489 imageSrc={this.state.saveUserSettingsForm.avatar}
490 onUpload={this.handleAvatarUpload}
491 onRemove={this.handleAvatarRemove}
496 <div class="form-group row">
497 <label class="col-sm-3">{i18n.t("banner")}</label>
498 <div class="col-sm-9">
500 uploadTitle={i18n.t("upload_banner")}
501 imageSrc={this.state.saveUserSettingsForm.banner}
502 onUpload={this.handleBannerUpload}
503 onRemove={this.handleBannerRemove}
507 <div class="form-group row">
508 <label class="col-sm-3" htmlFor="user-language">
511 <div class="col-sm-9">
514 value={this.state.saveUserSettingsForm.lang}
515 onChange={linkEvent(this, this.handleLangChange)}
516 class="custom-select w-auto"
518 <option disabled aria-hidden="true">
521 <option value="browser">{i18n.t("browser_default")}</option>
522 <option disabled aria-hidden="true">
526 .sort((a, b) => a.code.localeCompare(b.code))
528 <option value={lang.code}>{lang.name}</option>
533 <div class="form-group row">
534 <label class="col-sm-3" htmlFor="user-theme">
537 <div class="col-sm-9">
540 value={this.state.saveUserSettingsForm.theme}
541 onChange={linkEvent(this, this.handleThemeChange)}
542 class="custom-select w-auto"
544 <option disabled aria-hidden="true">
547 <option value="browser">{i18n.t("browser_default")}</option>
548 {themes.map(theme => (
549 <option value={theme}>{theme}</option>
554 <form className="form-group row">
555 <label class="col-sm-3">{i18n.t("type")}</label>
556 <div class="col-sm-9">
559 Object.values(ListingType)[
560 this.state.saveUserSettingsForm.default_listing_type
563 showLocal={showLocal(this.isoData)}
564 onChange={this.handleListingTypeChange}
568 <form className="form-group row">
569 <label class="col-sm-3">{i18n.t("sort_type")}</label>
570 <div class="col-sm-9">
573 Object.values(SortType)[
574 this.state.saveUserSettingsForm.default_sort_type
577 onChange={this.handleSortTypeChange}
581 {this.state.siteRes.site_view.site.enable_nsfw && (
582 <div class="form-group">
583 <div class="form-check">
585 class="form-check-input"
588 checked={this.state.saveUserSettingsForm.show_nsfw}
589 onChange={linkEvent(this, this.handleShowNsfwChange)}
591 <label class="form-check-label" htmlFor="user-show-nsfw">
592 {i18n.t("show_nsfw")}
597 <div class="form-group">
598 <div class="form-check">
600 class="form-check-input"
601 id="user-show-scores"
603 checked={this.state.saveUserSettingsForm.show_scores}
604 onChange={linkEvent(this, this.handleShowScoresChange)}
606 <label class="form-check-label" htmlFor="user-show-scores">
607 {i18n.t("show_scores")}
611 <div class="form-group">
612 <div class="form-check">
614 class="form-check-input"
615 id="user-show-avatars"
617 checked={this.state.saveUserSettingsForm.show_avatars}
618 onChange={linkEvent(this, this.handleShowAvatarsChange)}
620 <label class="form-check-label" htmlFor="user-show-avatars">
621 {i18n.t("show_avatars")}
625 <div class="form-group">
626 <div class="form-check">
628 class="form-check-input"
629 id="user-bot-account"
631 checked={this.state.saveUserSettingsForm.bot_account}
632 onChange={linkEvent(this, this.handleBotAccount)}
634 <label class="form-check-label" htmlFor="user-bot-account">
635 {i18n.t("bot_account")}
639 <div class="form-group">
640 <div class="form-check">
642 class="form-check-input"
643 id="user-show-bot-accounts"
645 checked={this.state.saveUserSettingsForm.show_bot_accounts}
646 onChange={linkEvent(this, this.handleShowBotAccounts)}
648 <label class="form-check-label" htmlFor="user-show-bot-accounts">
649 {i18n.t("show_bot_accounts")}
653 <div class="form-group">
654 <div class="form-check">
656 class="form-check-input"
657 id="user-show-read-posts"
659 checked={this.state.saveUserSettingsForm.show_read_posts}
660 onChange={linkEvent(this, this.handleReadPosts)}
662 <label class="form-check-label" htmlFor="user-show-read-posts">
663 {i18n.t("show_read_posts")}
667 <div class="form-group">
668 <div class="form-check">
670 class="form-check-input"
671 id="user-show-new-post-notifs"
673 checked={this.state.saveUserSettingsForm.show_new_post_notifs}
674 onChange={linkEvent(this, this.handleShowNewPostNotifs)}
677 class="form-check-label"
678 htmlFor="user-show-new-post-notifs"
680 {i18n.t("show_new_post_notifs")}
684 <div class="form-group">
685 <div class="form-check">
687 class="form-check-input"
688 id="user-send-notifications-to-email"
690 disabled={!this.state.saveUserSettingsForm.email}
692 this.state.saveUserSettingsForm.send_notifications_to_email
696 this.handleSendNotificationsToEmailChange
700 class="form-check-label"
701 htmlFor="user-send-notifications-to-email"
703 {i18n.t("send_notifications_to_email")}
707 <div class="form-group">
708 <button type="submit" class="btn btn-block btn-secondary mr-4">
709 {this.state.saveUserSettingsLoading ? (
712 capitalizeFirstLetter(i18n.t("save"))
717 <div class="form-group">
719 class="btn btn-block btn-danger"
722 this.handleDeleteAccountShowConfirmToggle
725 {i18n.t("delete_account")}
727 {this.state.deleteAccountShowConfirm && (
729 <div class="my-2 alert alert-danger" role="alert">
730 {i18n.t("delete_account_confirm")}
734 value={this.state.deleteAccountForm.password}
735 autoComplete="new-password"
739 this.handleDeleteAccountPasswordChange
741 class="form-control my-2"
744 class="btn btn-danger mr-4"
745 disabled={!this.state.deleteAccountForm.password}
746 onClick={linkEvent(this, this.handleDeleteAccount)}
748 {this.state.deleteAccountLoading ? (
751 capitalizeFirstLetter(i18n.t("delete"))
755 class="btn btn-secondary"
758 this.handleDeleteAccountShowConfirmToggle
771 setupBlockPersonChoices() {
773 let selectId: any = document.getElementById("block-person-filter");
775 this.blockPersonChoices = new Choices(selectId, choicesConfig);
776 this.blockPersonChoices.passedElement.element.addEventListener(
779 this.handleBlockPerson(Number(e.detail.choice.value));
783 this.blockPersonChoices.passedElement.element.addEventListener(
785 debounce(async (e: any) => {
787 let persons = (await fetchUsers(e.detail.value)).users;
788 let choices = persons.map(pvs => personToChoice(pvs));
789 this.blockPersonChoices.setChoices(
805 setupBlockCommunityChoices() {
807 let selectId: any = document.getElementById("block-community-filter");
809 this.blockCommunityChoices = new Choices(selectId, choicesConfig);
810 this.blockCommunityChoices.passedElement.element.addEventListener(
813 this.handleBlockCommunity(Number(e.detail.choice.value));
817 this.blockCommunityChoices.passedElement.element.addEventListener(
819 debounce(async (e: any) => {
821 let communities = (await fetchCommunities(e.detail.value))
823 let choices = communities.map(cv => communityToChoice(cv));
824 this.blockCommunityChoices.setChoices(
840 handleBlockPerson(personId: number) {
842 let blockUserForm: BlockPerson = {
847 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
851 handleUnblockPerson(i: { ctx: Settings; recipientId: number }) {
852 let blockUserForm: BlockPerson = {
853 person_id: i.recipientId,
857 WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
860 handleBlockCommunity(community_id: number) {
861 if (community_id != 0) {
862 let blockCommunityForm: BlockCommunity = {
867 WebSocketService.Instance.send(
868 wsClient.blockCommunity(blockCommunityForm)
873 handleUnblockCommunity(i: { ctx: Settings; communityId: number }) {
874 let blockCommunityForm: BlockCommunity = {
875 community_id: i.communityId,
879 WebSocketService.Instance.send(wsClient.blockCommunity(blockCommunityForm));
882 handleShowNsfwChange(i: Settings, event: any) {
883 i.state.saveUserSettingsForm.show_nsfw = event.target.checked;
887 handleShowAvatarsChange(i: Settings, event: any) {
888 i.state.saveUserSettingsForm.show_avatars = event.target.checked;
889 UserService.Instance.myUserInfo.local_user_view.local_user.show_avatars =
890 event.target.checked; // Just for instant updates
894 handleBotAccount(i: Settings, event: any) {
895 i.state.saveUserSettingsForm.bot_account = event.target.checked;
899 handleShowBotAccounts(i: Settings, event: any) {
900 i.state.saveUserSettingsForm.show_bot_accounts = event.target.checked;
904 handleReadPosts(i: Settings, event: any) {
905 i.state.saveUserSettingsForm.show_read_posts = event.target.checked;
909 handleShowNewPostNotifs(i: Settings, event: any) {
910 i.state.saveUserSettingsForm.show_new_post_notifs = event.target.checked;
914 handleShowScoresChange(i: Settings, event: any) {
915 i.state.saveUserSettingsForm.show_scores = event.target.checked;
916 UserService.Instance.myUserInfo.local_user_view.local_user.show_scores =
917 event.target.checked; // Just for instant updates
921 handleSendNotificationsToEmailChange(i: Settings, event: any) {
922 i.state.saveUserSettingsForm.send_notifications_to_email =
923 event.target.checked;
927 handleThemeChange(i: Settings, event: any) {
928 i.state.saveUserSettingsForm.theme = event.target.value;
929 setTheme(event.target.value, true);
933 handleLangChange(i: Settings, event: any) {
934 i.state.saveUserSettingsForm.lang = event.target.value;
935 i18n.changeLanguage(getLanguages(i.state.saveUserSettingsForm.lang)[0]);
939 handleSortTypeChange(val: SortType) {
940 this.state.saveUserSettingsForm.default_sort_type =
941 Object.keys(SortType).indexOf(val);
942 this.setState(this.state);
945 handleListingTypeChange(val: ListingType) {
946 this.state.saveUserSettingsForm.default_listing_type =
947 Object.keys(ListingType).indexOf(val);
948 this.setState(this.state);
951 handleEmailChange(i: Settings, event: any) {
952 i.state.saveUserSettingsForm.email = event.target.value;
956 handleBioChange(val: string) {
957 this.state.saveUserSettingsForm.bio = val;
958 this.setState(this.state);
961 handleAvatarUpload(url: string) {
962 this.state.saveUserSettingsForm.avatar = url;
963 this.setState(this.state);
966 handleAvatarRemove() {
967 this.state.saveUserSettingsForm.avatar = "";
968 this.setState(this.state);
971 handleBannerUpload(url: string) {
972 this.state.saveUserSettingsForm.banner = url;
973 this.setState(this.state);
976 handleBannerRemove() {
977 this.state.saveUserSettingsForm.banner = "";
978 this.setState(this.state);
981 handleDisplayNameChange(i: Settings, event: any) {
982 i.state.saveUserSettingsForm.display_name = event.target.value;
986 handleMatrixUserIdChange(i: Settings, event: any) {
987 i.state.saveUserSettingsForm.matrix_user_id = event.target.value;
989 i.state.saveUserSettingsForm.matrix_user_id == "" &&
990 !UserService.Instance.myUserInfo.local_user_view.person.matrix_user_id
992 i.state.saveUserSettingsForm.matrix_user_id = undefined;
997 handleNewPasswordChange(i: Settings, event: any) {
998 i.state.changePasswordForm.new_password = event.target.value;
999 if (i.state.changePasswordForm.new_password == "") {
1000 i.state.changePasswordForm.new_password = undefined;
1002 i.setState(i.state);
1005 handleNewPasswordVerifyChange(i: Settings, event: any) {
1006 i.state.changePasswordForm.new_password_verify = event.target.value;
1007 if (i.state.changePasswordForm.new_password_verify == "") {
1008 i.state.changePasswordForm.new_password_verify = undefined;
1010 i.setState(i.state);
1013 handleOldPasswordChange(i: Settings, event: any) {
1014 i.state.changePasswordForm.old_password = event.target.value;
1015 if (i.state.changePasswordForm.old_password == "") {
1016 i.state.changePasswordForm.old_password = undefined;
1018 i.setState(i.state);
1021 handleSaveSettingsSubmit(i: Settings, event: any) {
1022 event.preventDefault();
1023 i.state.saveUserSettingsLoading = true;
1024 i.setState(i.state);
1026 WebSocketService.Instance.send(
1027 wsClient.saveUserSettings(i.state.saveUserSettingsForm)
1031 handleChangePasswordSubmit(i: Settings, event: any) {
1032 event.preventDefault();
1033 i.state.changePasswordLoading = true;
1034 i.setState(i.state);
1036 WebSocketService.Instance.send(
1037 wsClient.changePassword(i.state.changePasswordForm)
1041 handleDeleteAccountShowConfirmToggle(i: Settings, event: any) {
1042 event.preventDefault();
1043 i.state.deleteAccountShowConfirm = !i.state.deleteAccountShowConfirm;
1044 i.setState(i.state);
1047 handleDeleteAccountPasswordChange(i: Settings, event: any) {
1048 i.state.deleteAccountForm.password = event.target.value;
1049 i.setState(i.state);
1052 handleDeleteAccount(i: Settings, event: any) {
1053 event.preventDefault();
1054 i.state.deleteAccountLoading = true;
1055 i.setState(i.state);
1057 WebSocketService.Instance.send(
1058 wsClient.deleteAccount(i.state.deleteAccountForm)
1062 handleSwitchTab(i: { ctx: Settings; tab: string }) {
1063 i.ctx.setState({ currentTab: i.tab });
1065 if (i.ctx.state.currentTab == "blocks") {
1066 i.ctx.setupBlockPersonChoices();
1067 i.ctx.setupBlockCommunityChoices();
1072 let luv = UserService.Instance.myUserInfo.local_user_view;
1073 this.state.saveUserSettingsForm.show_nsfw = luv.local_user.show_nsfw;
1074 this.state.saveUserSettingsForm.theme = luv.local_user.theme
1075 ? luv.local_user.theme
1077 this.state.saveUserSettingsForm.default_sort_type =
1078 luv.local_user.default_sort_type;
1079 this.state.saveUserSettingsForm.default_listing_type =
1080 luv.local_user.default_listing_type;
1081 this.state.saveUserSettingsForm.lang = luv.local_user.lang;
1082 this.state.saveUserSettingsForm.avatar = luv.person.avatar;
1083 this.state.saveUserSettingsForm.banner = luv.person.banner;
1084 this.state.saveUserSettingsForm.display_name = luv.person.display_name;
1085 this.state.saveUserSettingsForm.show_avatars = luv.local_user.show_avatars;
1086 this.state.saveUserSettingsForm.bot_account = luv.person.bot_account;
1087 this.state.saveUserSettingsForm.show_bot_accounts =
1088 luv.local_user.show_bot_accounts;
1089 this.state.saveUserSettingsForm.show_scores = luv.local_user.show_scores;
1090 this.state.saveUserSettingsForm.show_read_posts =
1091 luv.local_user.show_read_posts;
1092 this.state.saveUserSettingsForm.show_new_post_notifs =
1093 luv.local_user.show_new_post_notifs;
1094 this.state.saveUserSettingsForm.email = luv.local_user.email;
1095 this.state.saveUserSettingsForm.bio = luv.person.bio;
1096 this.state.saveUserSettingsForm.send_notifications_to_email =
1097 luv.local_user.send_notifications_to_email;
1098 this.state.saveUserSettingsForm.matrix_user_id = luv.person.matrix_user_id;
1099 this.state.personBlocks = UserService.Instance.myUserInfo.person_blocks;
1100 this.state.communityBlocks =
1101 UserService.Instance.myUserInfo.community_blocks;
1104 parseMessage(msg: any) {
1105 let op = wsUserOp(msg);
1109 saveUserSettingsLoading: false,
1110 changePasswordLoading: false,
1111 deleteAccountLoading: false,
1113 toast(i18n.t(msg.error), "danger");
1115 } else if (op == UserOperation.SaveUserSettings) {
1116 let data = wsJsonToRes<LoginResponse>(msg).data;
1117 UserService.Instance.login(data);
1118 this.state.saveUserSettingsLoading = false;
1119 this.setState(this.state);
1121 window.scrollTo(0, 0);
1122 } else if (op == UserOperation.ChangePassword) {
1123 let data = wsJsonToRes<LoginResponse>(msg).data;
1124 UserService.Instance.login(data);
1125 this.state.changePasswordLoading = false;
1126 this.setState(this.state);
1127 window.scrollTo(0, 0);
1128 toast(i18n.t("password_changed"));
1129 } else if (op == UserOperation.DeleteAccount) {
1131 deleteAccountLoading: false,
1132 deleteAccountShowConfirm: false,
1134 UserService.Instance.logout();
1135 window.location.href = "/";
1137 } else if (op == UserOperation.BlockPerson) {
1138 let data = wsJsonToRes<BlockPersonResponse>(msg).data;
1139 this.setState({ personBlocks: updatePersonBlock(data) });
1140 } else if (op == UserOperation.BlockCommunity) {
1141 let data = wsJsonToRes<BlockCommunityResponse>(msg).data;
1142 this.setState({ communityBlocks: updateCommunityBlock(data) });