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);
207 this.handleModBanSubmit = this.handleModBanSubmit.bind(this);
209 // Only fetch the data if coming from another route
210 if (FirstLoadService.isFirstLoad) {
213 personRes: this.isoData.routeData.personResponse,
219 async componentDidMount() {
220 if (!this.state.isIsomorphic) {
221 await this.fetchUserData();
226 componentWillUnmount() {
227 saveScrollPosition(this.context);
230 async fetchUserData() {
231 const { page, sort, view } = getProfileQueryParams();
233 this.setState({ personRes: { state: "empty" } });
235 personRes: await HttpService.client.getPersonDetails({
236 username: this.props.match.params.username,
238 saved_only: view === PersonDetailsView.Saved,
244 restoreScrollPosition(this.context);
245 this.setPersonBlock();
248 get amCurrentUser() {
249 if (this.state.personRes.state === "success") {
251 UserService.Instance.myUserInfo?.local_user_view.person.id ===
252 this.state.personRes.data.person_view.person.id
260 const mui = UserService.Instance.myUserInfo;
261 const res = this.state.personRes;
263 if (mui && res.state === "success") {
265 personBlocked: mui.person_blocks.some(
266 ({ target: { id } }) => id === res.data.person_view.person.id
272 static async fetchInitialData({
275 query: { page, sort, view: urlView },
277 }: InitialFetchRequest<QueryParams<ProfileProps>>): Promise<ProfileData> {
278 const pathSplit = path.split("/");
280 const username = pathSplit[2];
281 const view = getViewFromProps(urlView);
283 const form: GetPersonDetails = {
285 sort: getSortTypeFromQuery(sort),
286 saved_only: view === PersonDetailsView.Saved,
287 page: getPageFromString(page),
293 personResponse: await client.getPersonDetails(form),
297 get documentTitle(): string {
298 const siteName = this.state.siteRes.site_view.site.name;
299 const res = this.state.personRes;
300 return res.state == "success"
301 ? `@${res.data.person_view.person.name} - ${siteName}`
306 switch (this.state.personRes.state) {
314 const siteRes = this.state.siteRes;
315 const personRes = this.state.personRes.data;
316 const { page, sort, view } = getProfileQueryParams();
319 <div className="row">
320 <div className="col-12 col-md-8">
322 title={this.documentTitle}
323 path={this.context.router.route.match.url}
324 description={personRes.person_view.person.bio}
325 image={personRes.person_view.person.avatar}
328 {this.userInfo(personRes.person_view)}
335 personRes={personRes}
336 admins={siteRes.admins}
340 finished={this.state.finished}
341 enableDownvotes={enableDownvotes(siteRes)}
342 enableNsfw={enableNsfw(siteRes)}
344 onPageChange={this.handlePageChange}
345 allLanguages={siteRes.all_languages}
346 siteLanguages={siteRes.discussion_languages}
347 // TODO all the forms here
348 onSaveComment={this.handleSaveComment}
349 onBlockPerson={this.handleBlockPersonAlt}
350 onDeleteComment={this.handleDeleteComment}
351 onRemoveComment={this.handleRemoveComment}
352 onCommentVote={this.handleCommentVote}
353 onCommentReport={this.handleCommentReport}
354 onDistinguishComment={this.handleDistinguishComment}
355 onAddModToCommunity={this.handleAddModToCommunity}
356 onAddAdmin={this.handleAddAdmin}
357 onTransferCommunity={this.handleTransferCommunity}
358 onPurgeComment={this.handlePurgeComment}
359 onPurgePerson={this.handlePurgePerson}
360 onCommentReplyRead={this.handleCommentReplyRead}
361 onPersonMentionRead={this.handlePersonMentionRead}
362 onBanPersonFromCommunity={this.handleBanFromCommunity}
363 onBanPerson={this.handleBanPerson}
364 onCreateComment={this.handleCreateComment}
365 onEditComment={this.handleEditComment}
366 onPostEdit={this.handlePostEdit}
367 onPostVote={this.handlePostVote}
368 onPostReport={this.handlePostReport}
369 onLockPost={this.handleLockPost}
370 onDeletePost={this.handleDeletePost}
371 onRemovePost={this.handleRemovePost}
372 onSavePost={this.handleSavePost}
373 onPurgePost={this.handlePurgePost}
374 onFeaturePost={this.handleFeaturePost}
378 <div className="col-12 col-md-4">
379 <Moderates moderates={personRes.moderates} />
380 {this.amCurrentUser && <Follows />}
390 <div className="person-profile container-lg">
391 {this.renderPersonRes()}
398 <div className="btn-group btn-group-toggle flex-wrap mb-2">
399 {this.getRadio(PersonDetailsView.Overview)}
400 {this.getRadio(PersonDetailsView.Comments)}
401 {this.getRadio(PersonDetailsView.Posts)}
402 {this.amCurrentUser && this.getRadio(PersonDetailsView.Saved)}
407 getRadio(view: PersonDetailsView) {
408 const { view: urlView } = getProfileQueryParams();
409 const active = view === urlView;
413 className={classNames("btn btn-outline-secondary pointer", {
419 className="btn-check"
422 onChange={linkEvent(this, this.handleViewChange)}
424 {I18NextService.i18n.t(view.toLowerCase() as NoOptionI18nKeys)}
430 const { sort } = getProfileQueryParams();
431 const { username } = this.props.match.params;
433 const profileRss = `/feeds/u/${username}.xml?sort=${sort}`;
436 <div className="mb-2">
437 <span className="me-3">{this.viewRadios}</span>
440 onChange={this.handleSortChange}
444 <a href={profileRss} rel={relTags} title="RSS">
445 <Icon icon="rss" classes="text-muted small mx-2" />
447 <link rel="alternate" type="application/atom+xml" href={profileRss} />
452 userInfo(pv: PersonView) {
462 {!isBanned(pv.person) && (
464 banner={pv.person.banner}
465 icon={pv.person.avatar}
468 <div className="mb-3">
470 <div className="mb-0 d-flex flex-wrap">
472 {pv.person.display_name && (
473 <h5 className="mb-0">{pv.person.display_name}</h5>
475 <ul className="list-inline mb-2">
476 <li className="list-inline-item">
485 {isBanned(pv.person) && (
486 <li className="list-inline-item badge text-bg-danger">
487 {I18NextService.i18n.t("banned")}
490 {pv.person.deleted && (
491 <li className="list-inline-item badge text-bg-danger">
492 {I18NextService.i18n.t("deleted")}
495 {pv.person.admin && (
496 <li className="list-inline-item badge text-bg-light">
497 {I18NextService.i18n.t("admin")}
500 {pv.person.bot_account && (
501 <li className="list-inline-item badge text-bg-light">
502 {I18NextService.i18n.t("bot_account").toLowerCase()}
508 <div className="flex-grow-1 unselectable pointer mx-2"></div>
509 {!this.amCurrentUser && UserService.Instance.myUserInfo && (
512 className={`d-flex align-self-start btn btn-secondary me-2 ${
513 !pv.person.matrix_user_id && "invisible"
516 href={`https://matrix.to/#/${pv.person.matrix_user_id}`}
518 {I18NextService.i18n.t("send_secure_message")}
522 "d-flex align-self-start btn btn-secondary me-2"
524 to={`/create_private_message/${pv.person.id}`}
526 {I18NextService.i18n.t("send_message")}
531 "d-flex align-self-start btn btn-secondary me-2"
535 this.handleUnblockPerson
538 {I18NextService.i18n.t("unblock_user")}
543 "d-flex align-self-start btn btn-secondary me-2"
547 this.handleBlockPerson
550 {I18NextService.i18n.t("block_user")}
556 {canMod(pv.person.id, undefined, admins) &&
557 !isAdmin(pv.person.id, admins) &&
559 (!isBanned(pv.person) ? (
562 "d-flex align-self-start btn btn-secondary me-2"
564 onClick={linkEvent(this, this.handleModBanShow)}
565 aria-label={I18NextService.i18n.t("ban")}
567 {capitalizeFirstLetter(I18NextService.i18n.t("ban"))}
572 "d-flex align-self-start btn btn-secondary me-2"
574 onClick={linkEvent(this, this.handleModBanSubmit)}
575 aria-label={I18NextService.i18n.t("unban")}
577 {capitalizeFirstLetter(I18NextService.i18n.t("unban"))}
582 <div className="d-flex align-items-center mb-2">
585 dangerouslySetInnerHTML={mdToHtml(pv.person.bio)}
590 <ul className="list-inline mb-2">
591 <li className="list-inline-item badge text-bg-light">
592 {I18NextService.i18n.t("number_of_posts", {
593 count: Number(pv.counts.post_count),
594 formattedCount: numToSI(pv.counts.post_count),
597 <li className="list-inline-item badge text-bg-light">
598 {I18NextService.i18n.t("number_of_comments", {
599 count: Number(pv.counts.comment_count),
600 formattedCount: numToSI(pv.counts.comment_count),
605 <div className="text-muted">
606 {I18NextService.i18n.t("joined")}{" "}
608 published={pv.person.published}
613 <div className="d-flex align-items-center text-muted mb-2">
615 <span className="ms-2">
616 {I18NextService.i18n.t("cake_day_title")}{" "}
618 .utc(pv.person.published)
620 .format("MMM DD, YYYY")}
623 {!UserService.Instance.myUserInfo && (
624 <div className="alert alert-info" role="alert">
625 {I18NextService.i18n.t("profile_not_logged_in_alert")}
635 banDialog(pv: PersonView) {
636 const { showBanDialog } = this.state;
640 <form onSubmit={linkEvent(this, this.handleModBanSubmit)}>
641 <div className="mb-3 row col-12">
642 <label className="col-form-label" htmlFor="profile-ban-reason">
643 {I18NextService.i18n.t("reason")}
647 id="profile-ban-reason"
648 className="form-control me-2"
649 placeholder={I18NextService.i18n.t("reason")}
650 value={this.state.banReason}
651 onInput={linkEvent(this, this.handleModBanReasonChange)}
653 <label className="col-form-label" htmlFor={`mod-ban-expires`}>
654 {I18NextService.i18n.t("expires")}
658 id={`mod-ban-expires`}
659 className="form-control me-2"
660 placeholder={I18NextService.i18n.t("number_of_days")}
661 value={this.state.banExpireDays}
662 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
664 <div className="input-group mb-3">
665 <div className="form-check">
667 className="form-check-input"
668 id="mod-ban-remove-data"
670 checked={this.state.removeData}
671 onChange={linkEvent(this, this.handleModRemoveDataChange)}
674 className="form-check-label"
675 htmlFor="mod-ban-remove-data"
676 title={I18NextService.i18n.t("remove_content_more")}
678 {I18NextService.i18n.t("remove_content")}
683 {/* TODO hold off on expires until later */}
684 {/* <div class="mb-3 row"> */}
685 {/* <label class="col-form-label">Expires</label> */}
686 {/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
688 <div className="mb-3 row">
691 className="btn btn-secondary me-2"
692 aria-label={I18NextService.i18n.t("cancel")}
693 onClick={linkEvent(this, this.handleModBanSubmitCancel)}
695 {I18NextService.i18n.t("cancel")}
699 className="btn btn-secondary"
700 aria-label={I18NextService.i18n.t("ban")}
702 {I18NextService.i18n.t("ban")} {pv.person.name}
710 async updateUrl({ page, sort, view }: Partial<ProfileProps>) {
715 } = getProfileQueryParams();
717 const queryParams: QueryParams<ProfileProps> = {
718 page: (page ?? urlPage).toString(),
719 sort: sort ?? urlSort,
720 view: view ?? urlView,
723 const { username } = this.props.match.params;
725 this.props.history.push(`/u/${username}${getQueryString(queryParams)}`);
726 await this.fetchUserData();
729 handlePageChange(page: number) {
730 this.updateUrl({ page });
733 handleSortChange(sort: SortType) {
734 this.updateUrl({ sort, page: 1 });
737 handleViewChange(i: Profile, event: any) {
739 view: PersonDetailsView[event.target.value],
744 handleModBanShow(i: Profile) {
745 i.setState({ showBanDialog: true });
748 handleModBanReasonChange(i: Profile, event: any) {
749 i.setState({ banReason: event.target.value });
752 handleModBanExpireDaysChange(i: Profile, event: any) {
753 i.setState({ banExpireDays: event.target.value });
756 handleModRemoveDataChange(i: Profile, event: any) {
757 i.setState({ removeData: event.target.checked });
760 handleModBanSubmitCancel(i: Profile) {
761 i.setState({ showBanDialog: false });
764 async handleModBanSubmit(i: Profile, event: any) {
765 event.preventDefault();
766 const { removeData, banReason, banExpireDays } = i.state;
768 const personRes = i.state.personRes;
770 if (personRes.state == "success") {
771 const person = personRes.data.person_view.person;
772 const ban = !person.banned;
774 // If its an unban, restore all their data
776 i.setState({ removeData: false });
779 const res = await HttpService.client.banPerson({
780 person_id: person.id,
782 remove_data: removeData,
784 expires: futureDaysToUnixTime(banExpireDays),
785 auth: myAuthRequired(),
789 i.setState({ showBanDialog: false });
793 async toggleBlockPerson(recipientId: number, block: boolean) {
794 const res = await HttpService.client.blockPerson({
795 person_id: recipientId,
797 auth: myAuthRequired(),
799 if (res.state == "success") {
800 updatePersonBlock(res.data);
804 handleUnblockPerson(personId: number) {
805 this.toggleBlockPerson(personId, false);
808 handleBlockPerson(personId: number) {
809 this.toggleBlockPerson(personId, true);
812 async handleAddModToCommunity(form: AddModToCommunity) {
813 // TODO not sure what to do here
814 await HttpService.client.addModToCommunity(form);
817 async handlePurgePerson(form: PurgePerson) {
818 const purgePersonRes = await HttpService.client.purgePerson(form);
819 this.purgeItem(purgePersonRes);
822 async handlePurgeComment(form: PurgeComment) {
823 const purgeCommentRes = await HttpService.client.purgeComment(form);
824 this.purgeItem(purgeCommentRes);
827 async handlePurgePost(form: PurgePost) {
828 const purgeRes = await HttpService.client.purgePost(form);
829 this.purgeItem(purgeRes);
832 async handleBlockPersonAlt(form: BlockPerson) {
833 const blockPersonRes = await HttpService.client.blockPerson(form);
834 if (blockPersonRes.state === "success") {
835 updatePersonBlock(blockPersonRes.data);
839 async handleCreateComment(form: CreateComment) {
840 const createCommentRes = await HttpService.client.createComment(form);
841 this.createAndUpdateComments(createCommentRes);
843 return createCommentRes;
846 async handleEditComment(form: EditComment) {
847 const editCommentRes = await HttpService.client.editComment(form);
848 this.findAndUpdateComment(editCommentRes);
850 return editCommentRes;
853 async handleDeleteComment(form: DeleteComment) {
854 const deleteCommentRes = await HttpService.client.deleteComment(form);
855 this.findAndUpdateComment(deleteCommentRes);
858 async handleDeletePost(form: DeletePost) {
859 const deleteRes = await HttpService.client.deletePost(form);
860 this.findAndUpdatePost(deleteRes);
863 async handleRemovePost(form: RemovePost) {
864 const removeRes = await HttpService.client.removePost(form);
865 this.findAndUpdatePost(removeRes);
868 async handleRemoveComment(form: RemoveComment) {
869 const removeCommentRes = await HttpService.client.removeComment(form);
870 this.findAndUpdateComment(removeCommentRes);
873 async handleSaveComment(form: SaveComment) {
874 const saveCommentRes = await HttpService.client.saveComment(form);
875 this.findAndUpdateComment(saveCommentRes);
878 async handleSavePost(form: SavePost) {
879 const saveRes = await HttpService.client.savePost(form);
880 this.findAndUpdatePost(saveRes);
883 async handleFeaturePost(form: FeaturePost) {
884 const featureRes = await HttpService.client.featurePost(form);
885 this.findAndUpdatePost(featureRes);
888 async handleCommentVote(form: CreateCommentLike) {
889 const voteRes = await HttpService.client.likeComment(form);
890 this.findAndUpdateComment(voteRes);
893 async handlePostVote(form: CreatePostLike) {
894 const voteRes = await HttpService.client.likePost(form);
895 this.findAndUpdatePost(voteRes);
898 async handlePostEdit(form: EditPost) {
899 const res = await HttpService.client.editPost(form);
900 this.findAndUpdatePost(res);
903 async handleCommentReport(form: CreateCommentReport) {
904 const reportRes = await HttpService.client.createCommentReport(form);
905 if (reportRes.state === "success") {
906 toast(I18NextService.i18n.t("report_created"));
910 async handlePostReport(form: CreatePostReport) {
911 const reportRes = await HttpService.client.createPostReport(form);
912 if (reportRes.state === "success") {
913 toast(I18NextService.i18n.t("report_created"));
917 async handleLockPost(form: LockPost) {
918 const lockRes = await HttpService.client.lockPost(form);
919 this.findAndUpdatePost(lockRes);
922 async handleDistinguishComment(form: DistinguishComment) {
923 const distinguishRes = await HttpService.client.distinguishComment(form);
924 this.findAndUpdateComment(distinguishRes);
927 async handleAddAdmin(form: AddAdmin) {
928 const addAdminRes = await HttpService.client.addAdmin(form);
930 if (addAdminRes.state == "success") {
931 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
935 async handleTransferCommunity(form: TransferCommunity) {
936 await HttpService.client.transferCommunity(form);
937 toast(I18NextService.i18n.t("transfer_community"));
940 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
941 const readRes = await HttpService.client.markCommentReplyAsRead(form);
942 this.findAndUpdateCommentReply(readRes);
945 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
946 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
947 await HttpService.client.markPersonMentionAsRead(form);
950 async handleBanFromCommunity(form: BanFromCommunity) {
951 const banRes = await HttpService.client.banFromCommunity(form);
952 this.updateBanFromCommunity(banRes);
955 async handleBanPerson(form: BanPerson) {
956 const banRes = await HttpService.client.banPerson(form);
957 this.updateBan(banRes);
960 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
961 // Maybe not necessary
962 if (banRes.state === "success") {
964 if (s.personRes.state == "success") {
965 s.personRes.data.posts
966 .filter(c => c.creator.id === banRes.data.person_view.person.id)
968 c => (c.creator_banned_from_community = banRes.data.banned)
971 s.personRes.data.comments
972 .filter(c => c.creator.id === banRes.data.person_view.person.id)
974 c => (c.creator_banned_from_community = banRes.data.banned)
982 updateBan(banRes: RequestState<BanPersonResponse>) {
983 // Maybe not necessary
984 if (banRes.state == "success") {
986 if (s.personRes.state == "success") {
987 s.personRes.data.posts
988 .filter(c => c.creator.id == banRes.data.person_view.person.id)
989 .forEach(c => (c.creator.banned = banRes.data.banned));
990 s.personRes.data.comments
991 .filter(c => c.creator.id == banRes.data.person_view.person.id)
992 .forEach(c => (c.creator.banned = banRes.data.banned));
993 s.personRes.data.person_view.person.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