2020-09-06 16:15:25 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { Link } from 'inferno-router';
|
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import {
|
|
|
|
UserOperation,
|
|
|
|
SortType,
|
|
|
|
ListingType,
|
2020-12-24 01:58:27 +00:00
|
|
|
SaveUserSettings,
|
2020-09-06 16:15:25 +00:00
|
|
|
LoginResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
DeleteAccount,
|
2020-09-06 16:15:25 +00:00
|
|
|
GetSiteResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
GetUserDetailsResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
AddAdminResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
GetUserDetails,
|
2020-09-09 00:48:17 +00:00
|
|
|
CommentResponse,
|
|
|
|
PostResponse,
|
|
|
|
BanUserResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
} from 'lemmy-js-client';
|
2020-11-12 21:56:46 +00:00
|
|
|
import { InitialFetchRequest, UserDetailsView } from '../interfaces';
|
2020-09-06 16:15:25 +00:00
|
|
|
import { WebSocketService, UserService } from '../services';
|
|
|
|
import {
|
|
|
|
wsJsonToRes,
|
|
|
|
fetchLimit,
|
|
|
|
routeSortTypeToEnum,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
themes,
|
|
|
|
setTheme,
|
|
|
|
languages,
|
|
|
|
toast,
|
|
|
|
setupTippy,
|
|
|
|
getLanguage,
|
|
|
|
mdToHtml,
|
|
|
|
elementUrl,
|
2020-09-09 00:48:17 +00:00
|
|
|
setIsoData,
|
|
|
|
getIdFromProps,
|
|
|
|
getUsernameFromProps,
|
|
|
|
wsSubscribe,
|
|
|
|
createCommentLikeRes,
|
|
|
|
editCommentRes,
|
|
|
|
saveCommentRes,
|
|
|
|
createPostLikeFindRes,
|
2020-09-11 18:09:21 +00:00
|
|
|
previewLines,
|
2020-09-26 16:18:49 +00:00
|
|
|
editPostFindRes,
|
2020-12-24 01:58:27 +00:00
|
|
|
wsUserOp,
|
2020-12-24 22:05:57 +00:00
|
|
|
wsClient,
|
|
|
|
authField,
|
|
|
|
setOptionalAuth,
|
2020-09-06 16:15:25 +00:00
|
|
|
} from '../utils';
|
|
|
|
import { UserListing } from './user-listing';
|
2020-09-11 18:09:21 +00:00
|
|
|
import { HtmlTags } from './html-tags';
|
2020-09-06 16:15:25 +00:00
|
|
|
import { SortSelect } from './sort-select';
|
|
|
|
import { ListingTypeSelect } from './listing-type-select';
|
|
|
|
import { MomentTime } from './moment-time';
|
|
|
|
import { i18n } from '../i18next';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { UserDetails } from './user-details';
|
|
|
|
import { MarkdownTextArea } from './markdown-textarea';
|
|
|
|
import { ImageUploadForm } from './image-upload-form';
|
|
|
|
import { BannerIconHeader } from './banner-icon-header';
|
2020-11-16 22:19:10 +00:00
|
|
|
import { CommunityLink } from './community-link';
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface UserState {
|
2020-12-24 01:58:27 +00:00
|
|
|
userRes: GetUserDetailsResponse;
|
2020-09-09 00:48:17 +00:00
|
|
|
userId: number;
|
|
|
|
userName: string;
|
2020-09-06 16:15:25 +00:00
|
|
|
view: UserDetailsView;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
|
|
|
loading: boolean;
|
2020-12-24 01:58:27 +00:00
|
|
|
userSettingsForm: SaveUserSettings;
|
2020-09-06 16:15:25 +00:00
|
|
|
userSettingsLoading: boolean;
|
|
|
|
deleteAccountLoading: boolean;
|
|
|
|
deleteAccountShowConfirm: boolean;
|
2020-12-24 01:58:27 +00:00
|
|
|
deleteAccountForm: DeleteAccount;
|
2020-09-06 16:15:25 +00:00
|
|
|
siteRes: GetSiteResponse;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface UserProps {
|
|
|
|
view: UserDetailsView;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
|
|
|
user_id: number | null;
|
|
|
|
username: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface UrlParams {
|
|
|
|
view?: string;
|
|
|
|
sort?: SortType;
|
|
|
|
page?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class User extends Component<any, UserState> {
|
2020-09-09 00:48:17 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
private subscription: Subscription;
|
|
|
|
private emptyState: UserState = {
|
2020-09-09 00:48:17 +00:00
|
|
|
userRes: undefined,
|
|
|
|
userId: getIdFromProps(this.props),
|
|
|
|
userName: getUsernameFromProps(this.props),
|
2020-09-06 16:15:25 +00:00
|
|
|
loading: true,
|
|
|
|
view: User.getViewFromProps(this.props.match.view),
|
|
|
|
sort: User.getSortTypeFromProps(this.props.match.sort),
|
|
|
|
page: User.getPageFromProps(this.props.match.page),
|
|
|
|
userSettingsForm: {
|
|
|
|
show_nsfw: null,
|
|
|
|
theme: null,
|
|
|
|
default_sort_type: null,
|
|
|
|
default_listing_type: null,
|
|
|
|
lang: null,
|
|
|
|
show_avatars: null,
|
|
|
|
send_notifications_to_email: null,
|
|
|
|
bio: null,
|
|
|
|
preferred_username: null,
|
2020-12-26 03:28:05 +00:00
|
|
|
auth: authField(false),
|
2020-09-06 16:15:25 +00:00
|
|
|
},
|
|
|
|
userSettingsLoading: null,
|
|
|
|
deleteAccountLoading: null,
|
|
|
|
deleteAccountShowConfirm: false,
|
|
|
|
deleteAccountForm: {
|
|
|
|
password: null,
|
2020-12-26 03:28:05 +00:00
|
|
|
auth: authField(false),
|
2020-09-06 16:15:25 +00:00
|
|
|
},
|
2020-12-24 01:58:27 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
|
|
|
this.handleUserSettingsSortTypeChange = this.handleUserSettingsSortTypeChange.bind(
|
|
|
|
this
|
|
|
|
);
|
|
|
|
this.handleUserSettingsListingTypeChange = this.handleUserSettingsListingTypeChange.bind(
|
|
|
|
this
|
|
|
|
);
|
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
|
|
|
this.handleUserSettingsBioChange = this.handleUserSettingsBioChange.bind(
|
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
this.handleAvatarUpload = this.handleAvatarUpload.bind(this);
|
|
|
|
this.handleAvatarRemove = this.handleAvatarRemove.bind(this);
|
|
|
|
|
|
|
|
this.handleBannerUpload = this.handleBannerUpload.bind(this);
|
|
|
|
this.handleBannerRemove = this.handleBannerRemove.bind(this);
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
// Only fetch the data if coming from another route
|
|
|
|
if (this.isoData.path == this.context.router.route.match.url) {
|
|
|
|
this.state.userRes = this.isoData.routeData[0];
|
|
|
|
this.setUserInfo();
|
|
|
|
this.state.loading = false;
|
|
|
|
} else {
|
|
|
|
this.fetchUserData();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
fetchUserData() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: GetUserDetails = {
|
2020-09-09 00:48:17 +00:00
|
|
|
user_id: this.state.userId,
|
|
|
|
username: this.state.userName,
|
|
|
|
sort: this.state.sort,
|
|
|
|
saved_only: this.state.view === UserDetailsView.Saved,
|
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(false),
|
2020-09-09 00:48:17 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getUserDetails(form));
|
2020-09-09 00:48:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
get isCurrentUser() {
|
|
|
|
return (
|
|
|
|
UserService.Instance.user &&
|
2020-12-24 01:58:27 +00:00
|
|
|
UserService.Instance.user.id == this.state.userRes.user_view.user.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getViewFromProps(view: string): UserDetailsView {
|
|
|
|
return view ? UserDetailsView[view] : UserDetailsView.Overview;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSortTypeFromProps(sort: string): SortType {
|
|
|
|
return sort ? routeSortTypeToEnum(sort) : SortType.New;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getPageFromProps(page: number): number {
|
|
|
|
return page ? Number(page) : 1;
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
|
|
|
let pathSplit = req.path.split('/');
|
2020-09-09 00:48:17 +00:00
|
|
|
let promises: Promise<any>[] = [];
|
|
|
|
|
|
|
|
// It can be /u/me, or /username/1
|
|
|
|
let idOrName = pathSplit[2];
|
|
|
|
let user_id: number;
|
|
|
|
let username: string;
|
|
|
|
if (isNaN(Number(idOrName))) {
|
|
|
|
username = idOrName;
|
|
|
|
} else {
|
|
|
|
user_id = Number(idOrName);
|
|
|
|
}
|
|
|
|
|
|
|
|
let view = this.getViewFromProps(pathSplit[4]);
|
|
|
|
let sort = this.getSortTypeFromProps(pathSplit[6]);
|
|
|
|
let page = this.getPageFromProps(Number(pathSplit[8]));
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: GetUserDetails = {
|
2020-09-09 00:48:17 +00:00
|
|
|
sort,
|
|
|
|
saved_only: view === UserDetailsView.Saved,
|
|
|
|
page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
setOptionalAuth(form, req.auth);
|
2020-09-09 00:48:17 +00:00
|
|
|
this.setIdOrName(form, user_id, username);
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getUserDetails(form));
|
2020-09-09 00:48:17 +00:00
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
|
|
|
static setIdOrName(obj: any, id: number, name_: string) {
|
|
|
|
if (id) {
|
|
|
|
obj.user_id = id;
|
|
|
|
} else {
|
|
|
|
obj.username = name_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
static getDerivedStateFromProps(props: any): UserProps {
|
|
|
|
return {
|
|
|
|
view: this.getViewFromProps(props.match.params.view),
|
|
|
|
sort: this.getSortTypeFromProps(props.match.params.sort),
|
|
|
|
page: this.getPageFromProps(props.match.params.page),
|
|
|
|
user_id: Number(props.match.params.id) || null,
|
|
|
|
username: props.match.params.username,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(lastProps: any, _lastState: UserState, _snapshot: any) {
|
|
|
|
// Necessary if you are on a post and you click another post (same route)
|
|
|
|
if (
|
|
|
|
lastProps.location.pathname.split('/')[2] !==
|
|
|
|
lastProps.history.location.pathname.split('/')[2]
|
|
|
|
) {
|
|
|
|
// Couldnt get a refresh working. This does for now.
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2020-12-24 01:58:27 +00:00
|
|
|
return `@${this.state.userRes.user_view.user.name} - ${this.state.siteRes.site_view.site.name}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 18:09:21 +00:00
|
|
|
get bioTag(): string {
|
2020-12-24 01:58:27 +00:00
|
|
|
return this.state.userRes.user_view.user.bio
|
|
|
|
? previewLines(this.state.userRes.user_view.user.bio)
|
2020-09-11 18:09:21 +00:00
|
|
|
: undefined;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2020-09-09 00:48:17 +00:00
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
|
|
|
</h5>
|
|
|
|
) : (
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-12 col-md-8">
|
2020-09-06 16:15:25 +00:00
|
|
|
<>
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
description={this.bioTag}
|
2020-12-24 01:58:27 +00:00
|
|
|
image={this.state.userRes.user_view.user.avatar}
|
2020-09-11 18:09:21 +00:00
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.userInfo()}
|
|
|
|
<hr />
|
|
|
|
</>
|
2020-09-09 00:48:17 +00:00
|
|
|
{!this.state.loading && this.selects()}
|
|
|
|
<UserDetails
|
|
|
|
userRes={this.state.userRes}
|
2020-12-24 01:58:27 +00:00
|
|
|
admins={this.state.siteRes.admins}
|
2020-09-09 00:48:17 +00:00
|
|
|
sort={this.state.sort}
|
|
|
|
page={this.state.page}
|
|
|
|
limit={fetchLimit}
|
2020-12-24 01:58:27 +00:00
|
|
|
enableDownvotes={
|
|
|
|
this.state.siteRes.site_view.site.enable_downvotes
|
|
|
|
}
|
|
|
|
enableNsfw={this.state.siteRes.site_view.site.enable_nsfw}
|
2020-09-09 00:48:17 +00:00
|
|
|
view={this.state.view}
|
|
|
|
onPageChange={this.handlePageChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{!this.state.loading && (
|
|
|
|
<div class="col-12 col-md-4">
|
|
|
|
{this.isCurrentUser && this.userSettings()}
|
|
|
|
{this.moderates()}
|
|
|
|
{this.follows()}
|
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2020-09-09 00:48:17 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
viewRadios() {
|
|
|
|
return (
|
|
|
|
<div class="btn-group btn-group-toggle flex-wrap mb-2">
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.view == UserDetailsView.Overview && 'active'}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UserDetailsView.Overview}
|
|
|
|
checked={this.state.view === UserDetailsView.Overview}
|
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t('overview')}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.view == UserDetailsView.Comments && 'active'}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UserDetailsView.Comments}
|
|
|
|
checked={this.state.view == UserDetailsView.Comments}
|
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t('comments')}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.view == UserDetailsView.Posts && 'active'}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UserDetailsView.Posts}
|
|
|
|
checked={this.state.view == UserDetailsView.Posts}
|
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t('posts')}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.view == UserDetailsView.Saved && 'active'}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UserDetailsView.Saved}
|
|
|
|
checked={this.state.view == UserDetailsView.Saved}
|
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t('saved')}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
|
|
|
<span class="mr-3">{this.viewRadios()}</span>
|
|
|
|
<SortSelect
|
|
|
|
sort={this.state.sort}
|
|
|
|
onChange={this.handleSortChange}
|
|
|
|
hideHot
|
2021-02-01 18:48:42 +00:00
|
|
|
hideMostComments
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
<a
|
2020-09-09 00:48:17 +00:00
|
|
|
href={`/feeds/u/${this.state.userName}.xml?sort=${this.state.sort}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener"
|
|
|
|
title="RSS"
|
|
|
|
>
|
|
|
|
<svg class="icon mx-2 text-muted small">
|
|
|
|
<use xlinkHref="#icon-rss">#</use>
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
userInfo() {
|
2020-12-26 03:28:05 +00:00
|
|
|
let uv = this.state.userRes?.user_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2020-12-24 01:58:27 +00:00
|
|
|
<BannerIconHeader banner={uv.user.banner} icon={uv.user.avatar} />
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="mb-3">
|
|
|
|
<div class="">
|
|
|
|
<div class="mb-0 d-flex flex-wrap">
|
|
|
|
<div>
|
2020-12-24 01:58:27 +00:00
|
|
|
{uv.user.preferred_username && (
|
|
|
|
<h5 class="mb-0">{uv.user.preferred_username}</h5>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
<ul class="list-inline mb-2">
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<UserListing
|
2020-12-24 01:58:27 +00:00
|
|
|
user={uv.user}
|
2020-09-06 16:15:25 +00:00
|
|
|
realLink
|
|
|
|
useApubName
|
|
|
|
muted
|
|
|
|
hideAvatar
|
|
|
|
/>
|
|
|
|
</li>
|
2020-12-24 01:58:27 +00:00
|
|
|
{uv.user.banned && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<li className="list-inline-item badge badge-danger">
|
|
|
|
{i18n.t('banned')}
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div className="flex-grow-1 unselectable pointer mx-2"></div>
|
|
|
|
{this.isCurrentUser ? (
|
|
|
|
<button
|
2020-09-23 23:01:45 +00:00
|
|
|
class="d-flex align-self-start btn btn-secondary mr-2"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleLogoutClick)}
|
|
|
|
>
|
|
|
|
{i18n.t('logout')}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<a
|
2020-09-23 23:01:45 +00:00
|
|
|
className={`d-flex align-self-start btn btn-secondary mr-2 ${
|
2020-12-24 01:58:27 +00:00
|
|
|
!uv.user.matrix_user_id && 'invisible'
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener"
|
2020-12-24 01:58:27 +00:00
|
|
|
href={`https://matrix.to/#/${uv.user.matrix_user_id}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
{i18n.t('send_secure_message')}
|
|
|
|
</a>
|
|
|
|
<Link
|
2020-09-23 23:01:45 +00:00
|
|
|
className={'d-flex align-self-start btn btn-secondary'}
|
2020-12-24 01:58:27 +00:00
|
|
|
to={`/create_private_message/recipient/${uv.user.id}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
{i18n.t('send_message')}
|
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2020-12-24 01:58:27 +00:00
|
|
|
{uv.user.bio && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<div className="d-flex align-items-center mb-2">
|
|
|
|
<div
|
|
|
|
className="md-div"
|
2020-12-24 01:58:27 +00:00
|
|
|
dangerouslySetInnerHTML={mdToHtml(uv.user.bio)}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div>
|
|
|
|
<ul class="list-inline mb-2">
|
|
|
|
<li className="list-inline-item badge badge-light">
|
2020-12-24 01:58:27 +00:00
|
|
|
{i18n.t('number_of_posts', { count: uv.counts.post_count })}
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
<li className="list-inline-item badge badge-light">
|
|
|
|
{i18n.t('number_of_comments', {
|
2020-12-24 01:58:27 +00:00
|
|
|
count: uv.counts.comment_count,
|
2020-09-06 16:15:25 +00:00
|
|
|
})}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="text-muted">
|
2020-12-24 01:58:27 +00:00
|
|
|
{i18n.t('joined')} <MomentTime data={uv.user} showAgo />
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
<div className="d-flex align-items-center text-muted mb-2">
|
|
|
|
<svg class="icon">
|
|
|
|
<use xlinkHref="#icon-cake"></use>
|
|
|
|
</svg>
|
|
|
|
<span className="ml-2">
|
|
|
|
{i18n.t('cake_day_title')}{' '}
|
2020-12-24 01:58:27 +00:00
|
|
|
{moment.utc(uv.user.published).local().format('MMM DD, YYYY')}
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
userSettings() {
|
|
|
|
return (
|
|
|
|
<div>
|
2020-09-23 23:01:45 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="card-body">
|
|
|
|
<h5>{i18n.t('settings')}</h5>
|
|
|
|
<form onSubmit={linkEvent(this, this.handleUserSettingsSubmit)}>
|
|
|
|
<div class="form-group">
|
|
|
|
<label>{i18n.t('avatar')}</label>
|
|
|
|
<ImageUploadForm
|
|
|
|
uploadTitle={i18n.t('upload_avatar')}
|
|
|
|
imageSrc={this.state.userSettingsForm.avatar}
|
|
|
|
onUpload={this.handleAvatarUpload}
|
|
|
|
onRemove={this.handleAvatarRemove}
|
|
|
|
rounded
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<label>{i18n.t('banner')}</label>
|
|
|
|
<ImageUploadForm
|
|
|
|
uploadTitle={i18n.t('upload_banner')}
|
|
|
|
imageSrc={this.state.userSettingsForm.banner}
|
|
|
|
onUpload={this.handleBannerUpload}
|
|
|
|
onRemove={this.handleBannerRemove}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<label>{i18n.t('language')}</label>
|
|
|
|
<select
|
|
|
|
value={this.state.userSettingsForm.lang}
|
|
|
|
onChange={linkEvent(this, this.handleUserSettingsLangChange)}
|
|
|
|
class="ml-2 custom-select w-auto"
|
|
|
|
>
|
|
|
|
<option disabled>{i18n.t('language')}</option>
|
|
|
|
<option value="browser">{i18n.t('browser_default')}</option>
|
|
|
|
<option disabled>──</option>
|
|
|
|
{languages.map(lang => (
|
|
|
|
<option value={lang.code}>{lang.name}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<label>{i18n.t('theme')}</label>
|
|
|
|
<select
|
|
|
|
value={this.state.userSettingsForm.theme}
|
|
|
|
onChange={linkEvent(this, this.handleUserSettingsThemeChange)}
|
|
|
|
class="ml-2 custom-select w-auto"
|
|
|
|
>
|
|
|
|
<option disabled>{i18n.t('theme')}</option>
|
2020-09-24 22:03:03 +00:00
|
|
|
<option value="browser">{i18n.t('browser_default')}</option>
|
2020-09-06 16:15:25 +00:00
|
|
|
{themes.map(theme => (
|
|
|
|
<option value={theme}>{theme}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<form className="form-group">
|
|
|
|
<label>
|
|
|
|
<div class="mr-2">{i18n.t('sort_type')}</div>
|
|
|
|
</label>
|
|
|
|
<ListingTypeSelect
|
|
|
|
type_={
|
|
|
|
Object.values(ListingType)[
|
|
|
|
this.state.userSettingsForm.default_listing_type
|
|
|
|
]
|
|
|
|
}
|
2020-09-10 02:38:57 +00:00
|
|
|
showLocal={
|
2021-02-01 18:26:24 +00:00
|
|
|
this.state.siteRes.federated_instances?.linked.length > 0
|
2020-09-10 02:38:57 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={this.handleUserSettingsListingTypeChange}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<form className="form-group">
|
|
|
|
<label>
|
|
|
|
<div class="mr-2">{i18n.t('type')}</div>
|
|
|
|
</label>
|
|
|
|
<SortSelect
|
|
|
|
sort={
|
|
|
|
Object.values(SortType)[
|
|
|
|
this.state.userSettingsForm.default_sort_type
|
|
|
|
]
|
|
|
|
}
|
|
|
|
onChange={this.handleUserSettingsSortTypeChange}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-5 col-form-label">
|
|
|
|
{i18n.t('display_name')}
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
placeholder={i18n.t('optional')}
|
|
|
|
value={this.state.userSettingsForm.preferred_username}
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsPreferredUsernameChange
|
|
|
|
)}
|
|
|
|
pattern="^(?!@)(.+)$"
|
|
|
|
minLength={3}
|
|
|
|
maxLength={20}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-3 col-form-label" htmlFor="user-bio">
|
|
|
|
{i18n.t('bio')}
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-9">
|
|
|
|
<MarkdownTextArea
|
|
|
|
initialContent={this.state.userSettingsForm.bio}
|
|
|
|
onContentChange={this.handleUserSettingsBioChange}
|
|
|
|
maxLength={300}
|
|
|
|
hideNavigationWarnings
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-3 col-form-label" htmlFor="user-email">
|
|
|
|
{i18n.t('email')}
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-9">
|
|
|
|
<input
|
|
|
|
type="email"
|
|
|
|
id="user-email"
|
|
|
|
class="form-control"
|
|
|
|
placeholder={i18n.t('optional')}
|
|
|
|
value={this.state.userSettingsForm.email}
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsEmailChange
|
|
|
|
)}
|
|
|
|
minLength={3}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-5 col-form-label">
|
|
|
|
<a href={elementUrl} target="_blank" rel="noopener">
|
|
|
|
{i18n.t('matrix_user_id')}
|
|
|
|
</a>
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
placeholder="@user:example.com"
|
|
|
|
value={this.state.userSettingsForm.matrix_user_id}
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsMatrixUserIdChange
|
|
|
|
)}
|
|
|
|
minLength={3}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-5 col-form-label" htmlFor="user-password">
|
|
|
|
{i18n.t('new_password')}
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
id="user-password"
|
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.new_password}
|
|
|
|
autoComplete="new-password"
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsNewPasswordChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label
|
|
|
|
class="col-lg-5 col-form-label"
|
|
|
|
htmlFor="user-verify-password"
|
|
|
|
>
|
|
|
|
{i18n.t('verify_password')}
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
id="user-verify-password"
|
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.new_password_verify}
|
|
|
|
autoComplete="new-password"
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsNewPasswordVerifyChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label
|
|
|
|
class="col-lg-5 col-form-label"
|
|
|
|
htmlFor="user-old-password"
|
|
|
|
>
|
|
|
|
{i18n.t('old_password')}
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
id="user-old-password"
|
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.old_password}
|
|
|
|
autoComplete="new-password"
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsOldPasswordChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.siteRes.site_view.site.enable_nsfw && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
id="user-show-nsfw"
|
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.userSettingsForm.show_nsfw}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsShowNsfwChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label class="form-check-label" htmlFor="user-show-nsfw">
|
|
|
|
{i18n.t('show_nsfw')}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
id="user-show-avatars"
|
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.userSettingsForm.show_avatars}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsShowAvatarsChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label class="form-check-label" htmlFor="user-show-avatars">
|
|
|
|
{i18n.t('show_avatars')}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
id="user-send-notifications-to-email"
|
|
|
|
type="checkbox"
|
|
|
|
disabled={!this.state.userSettingsForm.email}
|
|
|
|
checked={
|
|
|
|
this.state.userSettingsForm.send_notifications_to_email
|
|
|
|
}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsSendNotificationsToEmailChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label
|
|
|
|
class="form-check-label"
|
|
|
|
htmlFor="user-send-notifications-to-email"
|
|
|
|
>
|
|
|
|
{i18n.t('send_notifications_to_email')}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<button type="submit" class="btn btn-block btn-secondary mr-4">
|
|
|
|
{this.state.userSettingsLoading ? (
|
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
|
|
|
) : (
|
|
|
|
capitalizeFirstLetter(i18n.t('save'))
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
<div class="form-group mb-0">
|
|
|
|
<button
|
|
|
|
class="btn btn-block btn-danger"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteAccountShowConfirmToggle
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('delete_account')}
|
|
|
|
</button>
|
|
|
|
{this.state.deleteAccountShowConfirm && (
|
|
|
|
<>
|
|
|
|
<div class="my-2 alert alert-danger" role="alert">
|
|
|
|
{i18n.t('delete_account_confirm')}
|
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
value={this.state.deleteAccountForm.password}
|
|
|
|
autoComplete="new-password"
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteAccountPasswordChange
|
|
|
|
)}
|
|
|
|
class="form-control my-2"
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
class="btn btn-danger mr-4"
|
|
|
|
disabled={!this.state.deleteAccountForm.password}
|
|
|
|
onClick={linkEvent(this, this.handleDeleteAccount)}
|
|
|
|
>
|
|
|
|
{this.state.deleteAccountLoading ? (
|
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
|
|
|
) : (
|
|
|
|
capitalizeFirstLetter(i18n.t('delete'))
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-secondary"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteAccountShowConfirmToggle
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('cancel')}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
moderates() {
|
|
|
|
return (
|
|
|
|
<div>
|
2020-09-09 00:48:17 +00:00
|
|
|
{this.state.userRes.moderates.length > 0 && (
|
2020-09-23 23:01:45 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="card-body">
|
|
|
|
<h5>{i18n.t('moderates')}</h5>
|
|
|
|
<ul class="list-unstyled mb-0">
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.userRes.moderates.map(cmv => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<li>
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={cmv.community} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
follows() {
|
|
|
|
return (
|
|
|
|
<div>
|
2020-09-09 00:48:17 +00:00
|
|
|
{this.state.userRes.follows.length > 0 && (
|
2020-09-23 23:01:45 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="card-body">
|
|
|
|
<h5>{i18n.t('subscribed')}</h5>
|
|
|
|
<ul class="list-unstyled mb-0">
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.userRes.follows.map(cfv => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<li>
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={cfv.community} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateUrl(paramUpdates: UrlParams) {
|
|
|
|
const page = paramUpdates.page || this.state.page;
|
|
|
|
const viewStr = paramUpdates.view || UserDetailsView[this.state.view];
|
|
|
|
const sortStr = paramUpdates.sort || this.state.sort;
|
2021-01-23 23:23:09 +00:00
|
|
|
|
|
|
|
let typeView = this.state.userName
|
|
|
|
? `/u/${this.state.userName}`
|
|
|
|
: `/user/${this.state.userId}`;
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
this.props.history.push(
|
2021-01-23 23:23:09 +00:00
|
|
|
`${typeView}/view/${viewStr}/sort/${sortStr}/page/${page}`
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
2020-09-26 16:18:49 +00:00
|
|
|
this.state.loading = true;
|
|
|
|
this.setState(this.state);
|
|
|
|
this.fetchUserData();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePageChange(page: number) {
|
|
|
|
this.updateUrl({ page });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSortChange(val: SortType) {
|
|
|
|
this.updateUrl({ sort: val, page: 1 });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleViewChange(i: User, event: any) {
|
|
|
|
i.updateUrl({
|
|
|
|
view: UserDetailsView[Number(event.target.value)],
|
|
|
|
page: 1,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsShowNsfwChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.show_nsfw = event.target.checked;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsShowAvatarsChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.show_avatars = event.target.checked;
|
|
|
|
UserService.Instance.user.show_avatars = event.target.checked; // Just for instant updates
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsSendNotificationsToEmailChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.send_notifications_to_email = event.target.checked;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsThemeChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.theme = event.target.value;
|
|
|
|
setTheme(event.target.value, true);
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsLangChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.lang = event.target.value;
|
|
|
|
i18n.changeLanguage(getLanguage(i.state.userSettingsForm.lang));
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsSortTypeChange(val: SortType) {
|
2020-12-26 03:28:05 +00:00
|
|
|
this.state.userSettingsForm.default_sort_type = Object.keys(
|
|
|
|
SortType
|
|
|
|
).indexOf(val);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsListingTypeChange(val: ListingType) {
|
2020-12-26 03:28:05 +00:00
|
|
|
this.state.userSettingsForm.default_listing_type = Object.keys(
|
|
|
|
ListingType
|
|
|
|
).indexOf(val);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsEmailChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.email = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsBioChange(val: string) {
|
|
|
|
this.state.userSettingsForm.bio = val;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAvatarUpload(url: string) {
|
|
|
|
this.state.userSettingsForm.avatar = url;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAvatarRemove() {
|
|
|
|
this.state.userSettingsForm.avatar = '';
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBannerUpload(url: string) {
|
|
|
|
this.state.userSettingsForm.banner = url;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBannerRemove() {
|
|
|
|
this.state.userSettingsForm.banner = '';
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsPreferredUsernameChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.preferred_username = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsMatrixUserIdChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.matrix_user_id = event.target.value;
|
|
|
|
if (
|
|
|
|
i.state.userSettingsForm.matrix_user_id == '' &&
|
2020-12-24 01:58:27 +00:00
|
|
|
!i.state.userRes.user_view.user.matrix_user_id
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
|
|
|
i.state.userSettingsForm.matrix_user_id = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsNewPasswordChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.new_password = event.target.value;
|
|
|
|
if (i.state.userSettingsForm.new_password == '') {
|
|
|
|
i.state.userSettingsForm.new_password = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsNewPasswordVerifyChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.new_password_verify = event.target.value;
|
|
|
|
if (i.state.userSettingsForm.new_password_verify == '') {
|
|
|
|
i.state.userSettingsForm.new_password_verify = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsOldPasswordChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.old_password = event.target.value;
|
|
|
|
if (i.state.userSettingsForm.old_password == '') {
|
|
|
|
i.state.userSettingsForm.old_password = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsSubmit(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.state.userSettingsLoading = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.saveUserSettings(i.state.userSettingsForm)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleDeleteAccountShowConfirmToggle(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.state.deleteAccountShowConfirm = !i.state.deleteAccountShowConfirm;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDeleteAccountPasswordChange(i: User, event: any) {
|
|
|
|
i.state.deleteAccountForm.password = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLogoutClick(i: User) {
|
|
|
|
UserService.Instance.logout();
|
|
|
|
i.context.router.history.push('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDeleteAccount(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.state.deleteAccountLoading = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.deleteAccount(i.state.deleteAccountForm)
|
|
|
|
);
|
2020-11-30 20:28:00 +00:00
|
|
|
i.handleLogoutClick(i);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
setUserInfo() {
|
|
|
|
if (this.isCurrentUser) {
|
|
|
|
this.state.userSettingsForm.show_nsfw =
|
|
|
|
UserService.Instance.user.show_nsfw;
|
|
|
|
this.state.userSettingsForm.theme = UserService.Instance.user.theme
|
|
|
|
? UserService.Instance.user.theme
|
2020-09-24 22:03:03 +00:00
|
|
|
: 'browser';
|
2020-09-09 00:48:17 +00:00
|
|
|
this.state.userSettingsForm.default_sort_type =
|
|
|
|
UserService.Instance.user.default_sort_type;
|
|
|
|
this.state.userSettingsForm.default_listing_type =
|
|
|
|
UserService.Instance.user.default_listing_type;
|
|
|
|
this.state.userSettingsForm.lang = UserService.Instance.user.lang;
|
|
|
|
this.state.userSettingsForm.avatar = UserService.Instance.user.avatar;
|
|
|
|
this.state.userSettingsForm.banner = UserService.Instance.user.banner;
|
|
|
|
this.state.userSettingsForm.preferred_username =
|
|
|
|
UserService.Instance.user.preferred_username;
|
|
|
|
this.state.userSettingsForm.show_avatars =
|
|
|
|
UserService.Instance.user.show_avatars;
|
|
|
|
this.state.userSettingsForm.email = UserService.Instance.user.email;
|
|
|
|
this.state.userSettingsForm.bio = UserService.Instance.user.bio;
|
|
|
|
this.state.userSettingsForm.send_notifications_to_email =
|
|
|
|
UserService.Instance.user.send_notifications_to_email;
|
|
|
|
this.state.userSettingsForm.matrix_user_id =
|
|
|
|
UserService.Instance.user.matrix_user_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
2020-09-06 16:15:25 +00:00
|
|
|
if (msg.error) {
|
|
|
|
toast(i18n.t(msg.error), 'danger');
|
|
|
|
if (msg.error == 'couldnt_find_that_username_or_email') {
|
|
|
|
this.context.router.history.push('/');
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
deleteAccountLoading: false,
|
|
|
|
userSettingsLoading: false,
|
|
|
|
});
|
|
|
|
return;
|
2020-09-09 00:48:17 +00:00
|
|
|
} else if (msg.reconnect) {
|
|
|
|
this.fetchUserData();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetUserDetails) {
|
2020-09-06 16:15:25 +00:00
|
|
|
// Since the UserDetails contains posts/comments as well as some general user info we listen here as well
|
|
|
|
// and set the parent state if it is not set or differs
|
2020-09-09 00:48:17 +00:00
|
|
|
// TODO this might need to get abstracted
|
2020-12-24 01:58:27 +00:00
|
|
|
let data = wsJsonToRes<GetUserDetailsResponse>(msg).data;
|
2020-09-09 00:48:17 +00:00
|
|
|
this.state.userRes = data;
|
|
|
|
this.setUserInfo();
|
|
|
|
this.state.loading = false;
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.SaveUserSettings) {
|
|
|
|
let data = wsJsonToRes<LoginResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
UserService.Instance.login(data);
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.userRes.user_view.user.bio = this.state.userSettingsForm.bio;
|
|
|
|
this.state.userRes.user_view.user.preferred_username = this.state.userSettingsForm.preferred_username;
|
|
|
|
this.state.userRes.user_view.user.banner = this.state.userSettingsForm.banner;
|
|
|
|
this.state.userRes.user_view.user.avatar = this.state.userSettingsForm.avatar;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.userSettingsLoading = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
|
|
|
|
window.scrollTo(0, 0);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.DeleteAccount) {
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState({
|
|
|
|
deleteAccountLoading: false,
|
|
|
|
deleteAccountShowConfirm: false,
|
|
|
|
});
|
|
|
|
this.context.router.history.push('/');
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.AddAdmin) {
|
|
|
|
let data = wsJsonToRes<AddAdminResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.siteRes.admins = data.admins;
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateCommentLike) {
|
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
|
|
|
createCommentLikeRes(data.comment_view, this.state.userRes.comments);
|
2020-09-09 00:48:17 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditComment ||
|
|
|
|
op == UserOperation.DeleteComment ||
|
|
|
|
op == UserOperation.RemoveComment
|
2020-09-09 00:48:17 +00:00
|
|
|
) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
|
|
|
editCommentRes(data.comment_view, this.state.userRes.comments);
|
2020-09-09 00:48:17 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateComment) {
|
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
2020-09-09 00:48:17 +00:00
|
|
|
if (
|
|
|
|
UserService.Instance.user &&
|
2020-12-24 01:58:27 +00:00
|
|
|
data.comment_view.creator.id == UserService.Instance.user.id
|
2020-09-09 00:48:17 +00:00
|
|
|
) {
|
|
|
|
toast(i18n.t('reply_sent'));
|
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.SaveComment) {
|
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
|
|
|
saveCommentRes(data.comment_view, this.state.userRes.comments);
|
2020-09-09 00:48:17 +00:00
|
|
|
this.setState(this.state);
|
2020-09-26 16:18:49 +00:00
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditPost ||
|
|
|
|
op == UserOperation.DeletePost ||
|
|
|
|
op == UserOperation.RemovePost ||
|
|
|
|
op == UserOperation.LockPost ||
|
|
|
|
op == UserOperation.StickyPost ||
|
|
|
|
op == UserOperation.SavePost
|
2020-09-26 16:18:49 +00:00
|
|
|
) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg).data;
|
|
|
|
editPostFindRes(data.post_view, this.state.userRes.posts);
|
2020-09-26 16:18:49 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePostLike) {
|
|
|
|
let data = wsJsonToRes<PostResponse>(msg).data;
|
|
|
|
createPostLikeFindRes(data.post_view, this.state.userRes.posts);
|
2020-09-09 00:48:17 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.BanUser) {
|
|
|
|
let data = wsJsonToRes<BanUserResponse>(msg).data;
|
2020-09-09 00:48:17 +00:00
|
|
|
this.state.userRes.comments
|
2020-12-24 01:58:27 +00:00
|
|
|
.filter(c => c.creator.id == data.user_view.user.id)
|
|
|
|
.forEach(c => (c.creator.banned = data.banned));
|
2020-09-09 00:48:17 +00:00
|
|
|
this.state.userRes.posts
|
2020-12-24 01:58:27 +00:00
|
|
|
.filter(c => c.creator.id == data.user_view.user.id)
|
|
|
|
.forEach(c => (c.creator.banned = data.banned));
|
2020-09-09 00:48:17 +00:00
|
|
|
this.setState(this.state);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|