13 import { restoreScrollPosition, saveScrollPosition } from "@utils/browser";
15 capitalizeFirstLetter,
21 } from "@utils/helpers";
22 import { canMod, isAdmin, isBanned } from "@utils/roles";
23 import type { QueryParams } from "@utils/types";
24 import { RouteDataResponse } from "@utils/types";
25 import classNames from "classnames";
26 import { NoOptionI18nKeys } from "i18next";
27 import { Component, linkEvent } from "inferno";
28 import { Link } from "inferno-router";
29 import { RouteComponentProps } from "inferno-router/dist/Route";
34 BanFromCommunityResponse,
42 CommunityModeratorView,
55 GetPersonDetailsResponse,
58 MarkCommentReplyAsRead,
59 MarkPersonMentionAsRead,
72 } from "lemmy-js-client";
73 import moment from "moment";
74 import { fetchLimit, relTags } from "../../config";
75 import { InitialFetchRequest, PersonDetailsView } from "../../interfaces";
76 import { mdToHtml } from "../../markdown";
77 import { FirstLoadService, I18NextService, UserService } from "../../services";
78 import { HttpService, RequestState } from "../../services/HttpService";
79 import { setupTippy } from "../../tippy";
80 import { toast } from "../../toast";
81 import { BannerIconHeader } from "../common/banner-icon-header";
82 import { HtmlTags } from "../common/html-tags";
83 import { Icon, Spinner } from "../common/icon";
84 import { MomentTime } from "../common/moment-time";
85 import { SortSelect } from "../common/sort-select";
86 import { CommunityLink } from "../community/community-link";
87 import { PersonDetails } from "./person-details";
88 import { PersonListing } from "./person-listing";
90 type ProfileData = RouteDataResponse<{
91 personResponse: GetPersonDetailsResponse;
94 interface ProfileState {
95 personRes: RequestState<GetPersonDetailsResponse>;
96 personBlocked: boolean;
98 banExpireDays?: number;
99 showBanDialog: boolean;
101 siteRes: GetSiteResponse;
102 finished: Map<CommentId, boolean | undefined>;
103 isIsomorphic: boolean;
106 interface ProfileProps {
107 view: PersonDetailsView;
112 function getProfileQueryParams() {
113 return getQueryParams<ProfileProps>({
114 view: getViewFromProps,
115 page: getPageFromString,
116 sort: getSortTypeFromQuery,
120 function getSortTypeFromQuery(sort?: string): SortType {
121 return sort ? (sort as SortType) : "New";
124 function getViewFromProps(view?: string): PersonDetailsView {
126 ? PersonDetailsView[view] ?? PersonDetailsView.Overview
127 : PersonDetailsView.Overview;
130 const getCommunitiesListing = (
131 translationKey: NoOptionI18nKeys,
132 communityViews?: { community: Community }[]
135 communityViews.length > 0 && (
136 <div className="card border-secondary mb-3">
137 <div className="card-body">
138 <h5>{I18NextService.i18n.t(translationKey)}</h5>
139 <ul className="list-unstyled mb-0">
140 {communityViews.map(({ community }) => (
141 <li key={community.id}>
142 <CommunityLink community={community} />
150 const Moderates = ({ moderates }: { moderates?: CommunityModeratorView[] }) =>
151 getCommunitiesListing("moderates", moderates);
153 const Follows = () =>
154 getCommunitiesListing("subscribed", UserService.Instance.myUserInfo?.follows);
156 export class Profile extends Component<
157 RouteComponentProps<{ username: string }>,
160 private isoData = setIsoData<ProfileData>(this.context);
161 state: ProfileState = {
162 personRes: { state: "empty" },
163 personBlocked: false,
164 siteRes: this.isoData.site_res,
165 showBanDialog: false,
171 constructor(props: RouteComponentProps<{ username: string }>, context: any) {
172 super(props, context);
174 this.handleSortChange = this.handleSortChange.bind(this);
175 this.handlePageChange = this.handlePageChange.bind(this);
177 this.handleBlockPerson = this.handleBlockPerson.bind(this);
178 this.handleUnblockPerson = this.handleUnblockPerson.bind(this);
180 this.handleCreateComment = this.handleCreateComment.bind(this);
181 this.handleEditComment = this.handleEditComment.bind(this);
182 this.handleSaveComment = this.handleSaveComment.bind(this);
183 this.handleBlockPersonAlt = this.handleBlockPersonAlt.bind(this);
184 this.handleDeleteComment = this.handleDeleteComment.bind(this);
185 this.handleRemoveComment = this.handleRemoveComment.bind(this);
186 this.handleCommentVote = this.handleCommentVote.bind(this);
187 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
188 this.handleAddAdmin = this.handleAddAdmin.bind(this);
189 this.handlePurgePerson = this.handlePurgePerson.bind(this);
190 this.handlePurgeComment = this.handlePurgeComment.bind(this);
191 this.handleCommentReport = this.handleCommentReport.bind(this);
192 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
193 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
194 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
195 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
196 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
197 this.handleBanPerson = this.handleBanPerson.bind(this);
198 this.handlePostVote = this.handlePostVote.bind(this);
199 this.handlePostEdit = this.handlePostEdit.bind(this);
200 this.handlePostReport = this.handlePostReport.bind(this);
201 this.handleLockPost = this.handleLockPost.bind(this);
202 this.handleDeletePost = this.handleDeletePost.bind(this);
203 this.handleRemovePost = this.handleRemovePost.bind(this);
204 this.handleSavePost = this.handleSavePost.bind(this);
205 this.handlePurgePost = this.handlePurgePost.bind(this);
206 this.handleFeaturePost = this.handleFeaturePost.bind(this);
208 // Only fetch the data if coming from another route
209 if (FirstLoadService.isFirstLoad) {
212 personRes: this.isoData.routeData.personResponse,
218 async componentDidMount() {
219 if (!this.state.isIsomorphic) {
220 await this.fetchUserData();
225 componentWillUnmount() {
226 saveScrollPosition(this.context);
229 async fetchUserData() {
230 const { page, sort, view } = getProfileQueryParams();
232 this.setState({ personRes: { state: "empty" } });
234 personRes: await HttpService.client.getPersonDetails({
235 username: this.props.match.params.username,
237 saved_only: view === PersonDetailsView.Saved,
243 restoreScrollPosition(this.context);
244 this.setPersonBlock();
247 get amCurrentUser() {
248 if (this.state.personRes.state === "success") {
250 UserService.Instance.myUserInfo?.local_user_view.person.id ===
251 this.state.personRes.data.person_view.person.id
259 const mui = UserService.Instance.myUserInfo;
260 const res = this.state.personRes;
262 if (mui && res.state === "success") {
264 personBlocked: mui.person_blocks.some(
265 ({ target: { id } }) => id === res.data.person_view.person.id
271 static async fetchInitialData({
274 query: { page, sort, view: urlView },
276 }: InitialFetchRequest<QueryParams<ProfileProps>>): Promise<ProfileData> {
277 const pathSplit = path.split("/");
279 const username = pathSplit[2];
280 const view = getViewFromProps(urlView);
282 const form: GetPersonDetails = {
284 sort: getSortTypeFromQuery(sort),
285 saved_only: view === PersonDetailsView.Saved,
286 page: getPageFromString(page),
292 personResponse: await client.getPersonDetails(form),
296 get documentTitle(): string {
297 const siteName = this.state.siteRes.site_view.site.name;
298 const res = this.state.personRes;
299 return res.state == "success"
300 ? `@${res.data.person_view.person.name} - ${siteName}`
305 switch (this.state.personRes.state) {
313 const siteRes = this.state.siteRes;
314 const personRes = this.state.personRes.data;
315 const { page, sort, view } = getProfileQueryParams();
318 <div className="row">
319 <div className="col-12 col-md-8">
321 title={this.documentTitle}
322 path={this.context.router.route.match.url}
323 description={personRes.person_view.person.bio}
324 image={personRes.person_view.person.avatar}
327 {this.userInfo(personRes.person_view)}
334 personRes={personRes}
335 admins={siteRes.admins}
339 finished={this.state.finished}
340 enableDownvotes={enableDownvotes(siteRes)}
341 enableNsfw={enableNsfw(siteRes)}
343 onPageChange={this.handlePageChange}
344 allLanguages={siteRes.all_languages}
345 siteLanguages={siteRes.discussion_languages}
346 // TODO all the forms here
347 onSaveComment={this.handleSaveComment}
348 onBlockPerson={this.handleBlockPersonAlt}
349 onDeleteComment={this.handleDeleteComment}
350 onRemoveComment={this.handleRemoveComment}
351 onCommentVote={this.handleCommentVote}
352 onCommentReport={this.handleCommentReport}
353 onDistinguishComment={this.handleDistinguishComment}
354 onAddModToCommunity={this.handleAddModToCommunity}
355 onAddAdmin={this.handleAddAdmin}
356 onTransferCommunity={this.handleTransferCommunity}
357 onPurgeComment={this.handlePurgeComment}
358 onPurgePerson={this.handlePurgePerson}
359 onCommentReplyRead={this.handleCommentReplyRead}
360 onPersonMentionRead={this.handlePersonMentionRead}
361 onBanPersonFromCommunity={this.handleBanFromCommunity}
362 onBanPerson={this.handleBanPerson}
363 onCreateComment={this.handleCreateComment}
364 onEditComment={this.handleEditComment}
365 onPostEdit={this.handlePostEdit}
366 onPostVote={this.handlePostVote}
367 onPostReport={this.handlePostReport}
368 onLockPost={this.handleLockPost}
369 onDeletePost={this.handleDeletePost}
370 onRemovePost={this.handleRemovePost}
371 onSavePost={this.handleSavePost}
372 onPurgePost={this.handlePurgePost}
373 onFeaturePost={this.handleFeaturePost}
377 <div className="col-12 col-md-4">
378 <Moderates moderates={personRes.moderates} />
379 {this.amCurrentUser && <Follows />}
389 <div className="person-profile container-lg">
390 {this.renderPersonRes()}
397 <div className="btn-group btn-group-toggle flex-wrap mb-2">
398 {this.getRadio(PersonDetailsView.Overview)}
399 {this.getRadio(PersonDetailsView.Comments)}
400 {this.getRadio(PersonDetailsView.Posts)}
401 {this.amCurrentUser && this.getRadio(PersonDetailsView.Saved)}
406 getRadio(view: PersonDetailsView) {
407 const { view: urlView } = getProfileQueryParams();
408 const active = view === urlView;
412 className={classNames("btn btn-outline-secondary pointer", {
418 className="btn-check"
421 onChange={linkEvent(this, this.handleViewChange)}
423 {I18NextService.i18n.t(view.toLowerCase() as NoOptionI18nKeys)}
429 const { sort } = getProfileQueryParams();
430 const { username } = this.props.match.params;
432 const profileRss = `/feeds/u/${username}.xml?sort=${sort}`;
435 <div className="mb-2">
436 <span className="me-3">{this.viewRadios}</span>
439 onChange={this.handleSortChange}
443 <a href={profileRss} rel={relTags} title="RSS">
444 <Icon icon="rss" classes="text-muted small mx-2" />
446 <link rel="alternate" type="application/atom+xml" href={profileRss} />
451 userInfo(pv: PersonView) {
461 {!isBanned(pv.person) && (
463 banner={pv.person.banner}
464 icon={pv.person.avatar}
467 <div className="mb-3">
469 <div className="mb-0 d-flex flex-wrap">
471 {pv.person.display_name && (
472 <h5 className="mb-0">{pv.person.display_name}</h5>
474 <ul className="list-inline mb-2">
475 <li className="list-inline-item">
484 {isBanned(pv.person) && (
485 <li className="list-inline-item badge text-bg-danger">
486 {I18NextService.i18n.t("banned")}
489 {pv.person.deleted && (
490 <li className="list-inline-item badge text-bg-danger">
491 {I18NextService.i18n.t("deleted")}
494 {pv.person.admin && (
495 <li className="list-inline-item badge text-bg-light">
496 {I18NextService.i18n.t("admin")}
499 {pv.person.bot_account && (
500 <li className="list-inline-item badge text-bg-light">
501 {I18NextService.i18n.t("bot_account").toLowerCase()}
507 <div className="flex-grow-1 unselectable pointer mx-2"></div>
508 {!this.amCurrentUser && UserService.Instance.myUserInfo && (
511 className={`d-flex align-self-start btn btn-secondary me-2 ${
512 !pv.person.matrix_user_id && "invisible"
515 href={`https://matrix.to/#/${pv.person.matrix_user_id}`}
517 {I18NextService.i18n.t("send_secure_message")}
521 "d-flex align-self-start btn btn-secondary me-2"
523 to={`/create_private_message/${pv.person.id}`}
525 {I18NextService.i18n.t("send_message")}
530 "d-flex align-self-start btn btn-secondary me-2"
534 this.handleUnblockPerson
537 {I18NextService.i18n.t("unblock_user")}
542 "d-flex align-self-start btn btn-secondary me-2"
546 this.handleBlockPerson
549 {I18NextService.i18n.t("block_user")}
555 {canMod(pv.person.id, undefined, admins) &&
556 !isAdmin(pv.person.id, admins) &&
558 (!isBanned(pv.person) ? (
561 "d-flex align-self-start btn btn-secondary me-2"
563 onClick={linkEvent(this, this.handleModBanShow)}
564 aria-label={I18NextService.i18n.t("ban")}
566 {capitalizeFirstLetter(I18NextService.i18n.t("ban"))}
571 "d-flex align-self-start btn btn-secondary me-2"
573 onClick={linkEvent(this, this.handleModBanSubmit)}
574 aria-label={I18NextService.i18n.t("unban")}
576 {capitalizeFirstLetter(I18NextService.i18n.t("unban"))}
581 <div className="d-flex align-items-center mb-2">
584 dangerouslySetInnerHTML={mdToHtml(pv.person.bio)}
589 <ul className="list-inline mb-2">
590 <li className="list-inline-item badge text-bg-light">
591 {I18NextService.i18n.t("number_of_posts", {
592 count: Number(pv.counts.post_count),
593 formattedCount: numToSI(pv.counts.post_count),
596 <li className="list-inline-item badge text-bg-light">
597 {I18NextService.i18n.t("number_of_comments", {
598 count: Number(pv.counts.comment_count),
599 formattedCount: numToSI(pv.counts.comment_count),
604 <div className="text-muted">
605 {I18NextService.i18n.t("joined")}{" "}
607 published={pv.person.published}
612 <div className="d-flex align-items-center text-muted mb-2">
614 <span className="ms-2">
615 {I18NextService.i18n.t("cake_day_title")}{" "}
617 .utc(pv.person.published)
619 .format("MMM DD, YYYY")}
622 {!UserService.Instance.myUserInfo && (
623 <div className="alert alert-info" role="alert">
624 {I18NextService.i18n.t("profile_not_logged_in_alert")}
634 banDialog(pv: PersonView) {
635 const { showBanDialog } = this.state;
639 <form onSubmit={linkEvent(this, this.handleModBanSubmit)}>
640 <div className="mb-3 row col-12">
641 <label className="col-form-label" htmlFor="profile-ban-reason">
642 {I18NextService.i18n.t("reason")}
646 id="profile-ban-reason"
647 className="form-control me-2"
648 placeholder={I18NextService.i18n.t("reason")}
649 value={this.state.banReason}
650 onInput={linkEvent(this, this.handleModBanReasonChange)}
652 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
653 {I18NextService.i18n.t("expires")}
657 id={`mod-ban-expires`}
658 className="form-control me-2"
659 placeholder={I18NextService.i18n.t("number_of_days")}
660 value={this.state.banExpireDays}
661 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
663 <div className="input-group mb-3">
664 <div className="form-check">
666 className="form-check-input"
667 id="mod-ban-remove-data"
669 checked={this.state.removeData}
670 onChange={linkEvent(this, this.handleModRemoveDataChange)}
673 className="form-check-label"
674 htmlFor="mod-ban-remove-data"
675 title={I18NextService.i18n.t("remove_content_more")}
677 {I18NextService.i18n.t("remove_content")}
682 {/* TODO hold off on expires until later */}
683 {/* <div class="mb-3 row"> */}
684 {/* <label class="col-form-label">Expires</label> */}
685 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
687 <div className="mb-3 row">
690 className="btn btn-secondary me-2"
691 aria-label={I18NextService.i18n.t("cancel")}
692 onClick={linkEvent(this, this.handleModBanSubmitCancel)}
694 {I18NextService.i18n.t("cancel")}
697 <div className="mb-3 row">
700 className="btn btn-secondary"
701 aria-label={I18NextService.i18n.t("ban")}
703 {I18NextService.i18n.t("ban")} {pv.person.name}
711 async updateUrl({ page, sort, view }: Partial<ProfileProps>) {
716 } = getProfileQueryParams();
718 const queryParams: QueryParams<ProfileProps> = {
719 page: (page ?? urlPage).toString(),
720 sort: sort ?? urlSort,
721 view: view ?? urlView,
724 const { username } = this.props.match.params;
726 this.props.history.push(`/u/${username}${getQueryString(queryParams)}`);
727 await this.fetchUserData();
730 handlePageChange(page: number) {
731 this.updateUrl({ page });
734 handleSortChange(sort: SortType) {
735 this.updateUrl({ sort, page: 1 });
738 handleViewChange(i: Profile, event: any) {
740 view: PersonDetailsView[event.target.value],
745 handleModBanShow(i: Profile) {
746 i.setState({ showBanDialog: true });
749 handleModBanReasonChange(i: Profile, event: any) {
750 i.setState({ banReason: event.target.value });
753 handleModBanExpireDaysChange(i: Profile, event: any) {
754 i.setState({ banExpireDays: event.target.value });
757 handleModRemoveDataChange(i: Profile, event: any) {
758 i.setState({ removeData: event.target.checked });
761 handleModBanSubmitCancel(i: Profile) {
762 i.setState({ showBanDialog: false });
765 async handleModBanSubmit(i: Profile, event: any) {
766 event.preventDefault();
767 const { removeData, banReason, banExpireDays } = i.state;
769 const personRes = i.state.personRes;
771 if (personRes.state == "success") {
772 const person = personRes.data.person_view.person;
773 const ban = !person.banned;
775 // If its an unban, restore all their data
777 i.setState({ removeData: false });
780 const res = await HttpService.client.banPerson({
781 person_id: person.id,
783 remove_data: removeData,
785 expires: futureDaysToUnixTime(banExpireDays),
786 auth: myAuthRequired(),
790 i.setState({ showBanDialog: false });
794 async toggleBlockPerson(recipientId: number, block: boolean) {
795 const res = await HttpService.client.blockPerson({
796 person_id: recipientId,
798 auth: myAuthRequired(),
800 if (res.state == "success") {
801 updatePersonBlock(res.data);
805 handleUnblockPerson(personId: number) {
806 this.toggleBlockPerson(personId, false);
809 handleBlockPerson(personId: number) {
810 this.toggleBlockPerson(personId, true);
813 async handleAddModToCommunity(form: AddModToCommunity) {
814 // TODO not sure what to do here
815 await HttpService.client.addModToCommunity(form);
818 async handlePurgePerson(form: PurgePerson) {
819 const purgePersonRes = await HttpService.client.purgePerson(form);
820 this.purgeItem(purgePersonRes);
823 async handlePurgeComment(form: PurgeComment) {
824 const purgeCommentRes = await HttpService.client.purgeComment(form);
825 this.purgeItem(purgeCommentRes);
828 async handlePurgePost(form: PurgePost) {
829 const purgeRes = await HttpService.client.purgePost(form);
830 this.purgeItem(purgeRes);
833 async handleBlockPersonAlt(form: BlockPerson) {
834 const blockPersonRes = await HttpService.client.blockPerson(form);
835 if (blockPersonRes.state === "success") {
836 updatePersonBlock(blockPersonRes.data);
840 async handleCreateComment(form: CreateComment) {
841 const createCommentRes = await HttpService.client.createComment(form);
842 this.createAndUpdateComments(createCommentRes);
844 return createCommentRes;
847 async handleEditComment(form: EditComment) {
848 const editCommentRes = await HttpService.client.editComment(form);
849 this.findAndUpdateComment(editCommentRes);
851 return editCommentRes;
854 async handleDeleteComment(form: DeleteComment) {
855 const deleteCommentRes = await HttpService.client.deleteComment(form);
856 this.findAndUpdateComment(deleteCommentRes);
859 async handleDeletePost(form: DeletePost) {
860 const deleteRes = await HttpService.client.deletePost(form);
861 this.findAndUpdatePost(deleteRes);
864 async handleRemovePost(form: RemovePost) {
865 const removeRes = await HttpService.client.removePost(form);
866 this.findAndUpdatePost(removeRes);
869 async handleRemoveComment(form: RemoveComment) {
870 const removeCommentRes = await HttpService.client.removeComment(form);
871 this.findAndUpdateComment(removeCommentRes);
874 async handleSaveComment(form: SaveComment) {
875 const saveCommentRes = await HttpService.client.saveComment(form);
876 this.findAndUpdateComment(saveCommentRes);
879 async handleSavePost(form: SavePost) {
880 const saveRes = await HttpService.client.savePost(form);
881 this.findAndUpdatePost(saveRes);
884 async handleFeaturePost(form: FeaturePost) {
885 const featureRes = await HttpService.client.featurePost(form);
886 this.findAndUpdatePost(featureRes);
889 async handleCommentVote(form: CreateCommentLike) {
890 const voteRes = await HttpService.client.likeComment(form);
891 this.findAndUpdateComment(voteRes);
894 async handlePostVote(form: CreatePostLike) {
895 const voteRes = await HttpService.client.likePost(form);
896 this.findAndUpdatePost(voteRes);
899 async handlePostEdit(form: EditPost) {
900 const res = await HttpService.client.editPost(form);
901 this.findAndUpdatePost(res);
904 async handleCommentReport(form: CreateCommentReport) {
905 const reportRes = await HttpService.client.createCommentReport(form);
906 if (reportRes.state === "success") {
907 toast(I18NextService.i18n.t("report_created"));
911 async handlePostReport(form: CreatePostReport) {
912 const reportRes = await HttpService.client.createPostReport(form);
913 if (reportRes.state === "success") {
914 toast(I18NextService.i18n.t("report_created"));
918 async handleLockPost(form: LockPost) {
919 const lockRes = await HttpService.client.lockPost(form);
920 this.findAndUpdatePost(lockRes);
923 async handleDistinguishComment(form: DistinguishComment) {
924 const distinguishRes = await HttpService.client.distinguishComment(form);
925 this.findAndUpdateComment(distinguishRes);
928 async handleAddAdmin(form: AddAdmin) {
929 const addAdminRes = await HttpService.client.addAdmin(form);
931 if (addAdminRes.state == "success") {
932 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
936 async handleTransferCommunity(form: TransferCommunity) {
937 await HttpService.client.transferCommunity(form);
938 toast(I18NextService.i18n.t("transfer_community"));
941 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
942 const readRes = await HttpService.client.markCommentReplyAsRead(form);
943 this.findAndUpdateCommentReply(readRes);
946 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
947 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
948 await HttpService.client.markPersonMentionAsRead(form);
951 async handleBanFromCommunity(form: BanFromCommunity) {
952 const banRes = await HttpService.client.banFromCommunity(form);
953 this.updateBanFromCommunity(banRes);
956 async handleBanPerson(form: BanPerson) {
957 const banRes = await HttpService.client.banPerson(form);
958 this.updateBan(banRes);
961 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
962 // Maybe not necessary
963 if (banRes.state === "success") {
965 if (s.personRes.state == "success") {
966 s.personRes.data.posts
967 .filter(c => c.creator.id === banRes.data.person_view.person.id)
969 c => (c.creator_banned_from_community = banRes.data.banned)
972 s.personRes.data.comments
973 .filter(c => c.creator.id === banRes.data.person_view.person.id)
975 c => (c.creator_banned_from_community = banRes.data.banned)
983 updateBan(banRes: RequestState<BanPersonResponse>) {
984 // Maybe not necessary
985 if (banRes.state == "success") {
987 if (s.personRes.state == "success") {
988 s.personRes.data.posts
989 .filter(c => c.creator.id == banRes.data.person_view.person.id)
990 .forEach(c => (c.creator.banned = banRes.data.banned));
991 s.personRes.data.comments
992 .filter(c => c.creator.id == banRes.data.person_view.person.id)
993 .forEach(c => (c.creator.banned = banRes.data.banned));
1000 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1001 if (purgeRes.state == "success") {
1002 toast(I18NextService.i18n.t("purge_success"));
1003 this.context.router.history.push(`/`);
1007 findAndUpdateComment(res: RequestState<CommentResponse>) {
1008 this.setState(s => {
1009 if (s.personRes.state == "success" && res.state == "success") {
1010 s.personRes.data.comments = editComment(
1011 res.data.comment_view,
1012 s.personRes.data.comments
1014 s.finished.set(res.data.comment_view.comment.id, true);
1020 createAndUpdateComments(res: RequestState<CommentResponse>) {
1021 this.setState(s => {
1022 if (s.personRes.state == "success" && res.state == "success") {
1023 s.personRes.data.comments.unshift(res.data.comment_view);
1024 // Set finished for the parent
1026 getCommentParentId(res.data.comment_view.comment) ?? 0,
1034 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1035 this.setState(s => {
1036 if (s.personRes.state == "success" && res.state == "success") {
1037 s.personRes.data.comments = editWith(
1038 res.data.comment_reply_view,
1039 s.personRes.data.comments
1046 findAndUpdatePost(res: RequestState<PostResponse>) {
1047 this.setState(s => {
1048 if (s.personRes.state == "success" && res.state == "success") {
1049 s.personRes.data.posts = editPost(
1051 s.personRes.data.posts