"no-useless-constructor": 0,
"no-useless-escape": 0,
"no-var": 0,
- "prefer-const": 0,
+ "prefer-const": 1,
"prefer-rest-params": 0,
"quote-props": 0,
"unicorn/filename-case": 0
function setForwardedHeaders(headers: IncomingHttpHeaders): {
[key: string]: string;
} {
- let out: { [key: string]: string } = {};
+ const out: { [key: string]: string } = {};
if (headers.host) {
out.host = headers.host;
}
- let realIp = headers["x-real-ip"];
+ const realIp = headers["x-real-ip"];
if (realIp) {
out["x-real-ip"] = realIp as string;
}
- let forwardedFor = headers["x-forwarded-for"];
+ const forwardedFor = headers["x-forwarded-for"];
if (forwardedFor) {
out["x-forwarded-for"] = forwardedFor as string;
}
// Subscribe to jwt changes
if (isBrowser()) {
// On the first load, check the unreads
- let auth = myAuth(false);
+ const auth = myAuth(false);
if (auth && UserService.Instance.myUserInfo) {
this.requestNotificationPermission();
WebSocketService.Instance.send(
}
get moderatesSomething(): boolean {
- let mods = UserService.Instance.myUserInfo?.moderates;
- let moderatesS = (mods && mods.length > 0) || false;
+ const mods = UserService.Instance.myUserInfo?.moderates;
+ const moderatesS = (mods && mods.length > 0) || false;
return amAdmin() || moderatesS;
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
if (msg.error == "not_logged_in") {
return;
} else if (msg.reconnect) {
console.log(i18n.t("websocket_reconnected"));
- let auth = myAuth(false);
+ const auth = myAuth(false);
if (UserService.Instance.myUserInfo && auth) {
WebSocketService.Instance.send(
wsClient.userJoin({
this.fetchUnreads();
}
} else if (op == UserOperation.GetUnreadCount) {
- let data = wsJsonToRes<GetUnreadCountResponse>(msg);
+ const data = wsJsonToRes<GetUnreadCountResponse>(msg);
this.setState({
unreadInboxCount: data.replies + data.mentions + data.private_messages,
});
this.sendUnreadCount();
} else if (op == UserOperation.GetReportCount) {
- let data = wsJsonToRes<GetReportCountResponse>(msg);
+ const data = wsJsonToRes<GetReportCountResponse>(msg);
this.setState({
unreadReportCount:
data.post_reports +
});
this.sendReportUnread();
} else if (op == UserOperation.GetUnreadRegistrationApplicationCount) {
- let data =
+ const data =
wsJsonToRes<GetUnreadRegistrationApplicationCountResponse>(msg);
this.setState({ unreadApplicationCount: data.registration_applications });
this.sendApplicationUnread();
} else if (op == UserOperation.CreateComment) {
- let data = wsJsonToRes<CommentResponse>(msg);
- let mui = UserService.Instance.myUserInfo;
+ const data = wsJsonToRes<CommentResponse>(msg);
+ const mui = UserService.Instance.myUserInfo;
if (
mui &&
data.recipient_ids.includes(mui.local_user_view.local_user.id)
notifyComment(data.comment_view, this.context.router);
}
} else if (op == UserOperation.CreatePrivateMessage) {
- let data = wsJsonToRes<PrivateMessageResponse>(msg);
+ const data = wsJsonToRes<PrivateMessageResponse>(msg);
if (
data.private_message_view.recipient.id ==
fetchUnreads() {
console.log("Fetching inbox unreads...");
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let unreadForm: GetUnreadCount = {
+ const unreadForm: GetUnreadCount = {
auth,
};
WebSocketService.Instance.send(wsClient.getUnreadCount(unreadForm));
console.log("Fetching reports...");
- let reportCountForm: GetReportCount = {
+ const reportCountForm: GetReportCount = {
auth,
};
WebSocketService.Instance.send(wsClient.getReportCount(reportCountForm));
if (amAdmin()) {
console.log("Fetching applications...");
- let applicationCountForm: GetUnreadRegistrationApplicationCount = {
+ const applicationCountForm: GetUnreadRegistrationApplicationCount = {
auth,
};
WebSocketService.Instance.send(
export class Theme extends Component<Props> {
render() {
- let user = UserService.Instance.myUserInfo;
- let hasTheme = user?.local_user_view.local_user.theme !== "browser";
+ const user = UserService.Instance.myUserInfo;
+ const hasTheme = user?.local_user_view.local_user.theme !== "browser";
if (user && hasTheme) {
return (
}
render() {
- let initialContent =
+ const initialContent =
typeof this.props.node !== "number"
? this.props.edit
? this.props.node.comment_view.comment.content
formId: string;
languageId?: number;
}) {
- let content = msg.val;
- let language_id = msg.languageId;
- let node = this.props.node;
+ const content = msg.val;
+ const language_id = msg.languageId;
+ const node = this.props.node;
this.setState({ formId: msg.formId });
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
if (typeof node === "number") {
- let postId = node;
- let form: CreateComment = {
+ const postId = node;
+ const form: CreateComment = {
content,
form_id: this.state.formId,
post_id: postId,
WebSocketService.Instance.send(wsClient.createComment(form));
} else {
if (this.props.edit) {
- let form: EditComment = {
+ const form: EditComment = {
content,
form_id: this.state.formId,
comment_id: node.comment_view.comment.id,
};
WebSocketService.Instance.send(wsClient.editComment(form));
} else {
- let form: CreateComment = {
+ const form: CreateComment = {
content,
form_id: this.state.formId,
post_id: node.comment_view.post.id,
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
// Only do the showing and hiding if logged in
op == UserOperation.CreateComment ||
op == UserOperation.EditComment
) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
// This only finishes this form, if the randomly generated form_id matches the one received
if (this.state.formId && this.state.formId == data.form_id) {
// TODO see if there's a better way to do this, and all willReceiveProps
componentWillReceiveProps(nextProps: CommentNodeProps) {
- let cv = nextProps.node.comment_view;
+ const cv = nextProps.node.comment_view;
this.setState({
my_vote: cv.my_vote,
upvotes: cv.counts.upvotes,
}
render() {
- let node = this.props.node;
- let cv = this.props.node.comment_view;
+ const node = this.props.node;
+ const cv = this.props.node.comment_view;
- let purgeTypeText =
+ const purgeTypeText =
this.state.purgeType == PurgeType.Comment
? i18n.t("purge_comment")
: `${i18n.t("purge")} ${cv.creator.name}`;
- let canMod_ =
+ const canMod_ =
canMod(cv.creator.id, this.props.moderators, this.props.admins) &&
cv.community.local;
- let canModOnSelf =
+ const canModOnSelf =
canMod(
cv.creator.id,
this.props.moderators,
UserService.Instance.myUserInfo,
true
) && cv.community.local;
- let canAdmin_ =
+ const canAdmin_ =
canAdmin(cv.creator.id, this.props.admins) && cv.community.local;
- let canAdminOnSelf =
+ const canAdminOnSelf =
canAdmin(
cv.creator.id,
this.props.admins,
UserService.Instance.myUserInfo,
true
) && cv.community.local;
- let isMod_ = isMod(cv.creator.id, this.props.moderators);
- let isAdmin_ =
+ const isMod_ = isMod(cv.creator.id, this.props.moderators);
+ const isAdmin_ =
isAdmin(cv.creator.id, this.props.admins) && cv.community.local;
- let amCommunityCreator_ = amCommunityCreator(
+ const amCommunityCreator_ = amCommunityCreator(
cv.creator.id,
this.props.moderators
);
- let borderColor = this.props.node.depth
+ const borderColor = this.props.node.depth
? colorList[(this.props.node.depth - 1) % colorList.length]
: colorList[0];
- let moreRepliesBorderColor = this.props.node.depth
+ const moreRepliesBorderColor = this.props.node.depth
? colorList[this.props.node.depth % colorList.length]
: colorList[0];
- let showMoreChildren =
+ const showMoreChildren =
this.props.viewType == CommentViewType.Tree &&
!this.state.collapsed &&
node.children.length == 0 &&
}
get commentReplyOrMentionRead(): boolean {
- let cv = this.props.node.comment_view;
+ const cv = this.props.node.comment_view;
if (this.isPersonMentionType(cv)) {
return cv.person_mention.read;
}
linkBtn(small = false) {
- let cv = this.props.node.comment_view;
- let classnames = classNames("btn btn-link btn-animate text-muted", {
+ const cv = this.props.node.comment_view;
+ const classnames = classNames("btn btn-link btn-animate text-muted", {
"btn-sm": small,
});
- let title = this.props.showContext
+ const title = this.props.showContext
? i18n.t("show_context")
: i18n.t("link");
}
get commentUnlessRemoved(): string {
- let comment = this.props.node.comment_view.comment;
+ const comment = this.props.node.comment_view.comment;
return comment.removed
? `*${i18n.t("removed")}*`
: comment.deleted
}
handleBlockUserClick(i: CommentNode) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let blockUserForm: BlockPerson = {
+ const blockUserForm: BlockPerson = {
person_id: i.props.node.comment_view.creator.id,
block: true,
auth,
}
handleDeleteClick(i: CommentNode) {
- let comment = i.props.node.comment_view.comment;
- let auth = myAuth();
+ const comment = i.props.node.comment_view.comment;
+ const auth = myAuth();
if (auth) {
- let deleteForm: DeleteComment = {
+ const deleteForm: DeleteComment = {
comment_id: comment.id,
deleted: !comment.deleted,
auth,
}
handleSaveCommentClick(i: CommentNode) {
- let cv = i.props.node.comment_view;
- let save = cv.saved == undefined ? true : !cv.saved;
- let auth = myAuth();
+ const cv = i.props.node.comment_view;
+ const save = cv.saved == undefined ? true : !cv.saved;
+ const auth = myAuth();
if (auth) {
- let form: SaveComment = {
+ const form: SaveComment = {
comment_id: cv.comment.id,
save,
auth,
handleCommentUpvote(event: any) {
event.preventDefault();
- let myVote = this.state.my_vote;
- let newVote = myVote == 1 ? 0 : 1;
+ const myVote = this.state.my_vote;
+ const newVote = myVote == 1 ? 0 : 1;
if (myVote == 1) {
this.setState({
this.setState({ my_vote: newVote });
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: CreateCommentLike = {
+ const form: CreateCommentLike = {
comment_id: this.props.node.comment_view.comment.id,
score: newVote,
auth,
handleCommentDownvote(event: any) {
event.preventDefault();
- let myVote = this.state.my_vote;
- let newVote = myVote == -1 ? 0 : -1;
+ const myVote = this.state.my_vote;
+ const newVote = myVote == -1 ? 0 : -1;
if (myVote == 1) {
this.setState({
this.setState({ my_vote: newVote });
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: CreateCommentLike = {
+ const form: CreateCommentLike = {
comment_id: this.props.node.comment_view.comment.id,
score: newVote,
auth,
}
handleReportSubmit(i: CommentNode) {
- let comment = i.props.node.comment_view.comment;
- let reason = i.state.reportReason;
- let auth = myAuth();
+ const comment = i.props.node.comment_view.comment;
+ const reason = i.state.reportReason;
+ const auth = myAuth();
if (reason && auth) {
- let form: CreateCommentReport = {
+ const form: CreateCommentReport = {
comment_id: comment.id,
reason,
auth,
}
handleModRemoveSubmit(i: CommentNode) {
- let comment = i.props.node.comment_view.comment;
- let auth = myAuth();
+ const comment = i.props.node.comment_view.comment;
+ const auth = myAuth();
if (auth) {
- let form: RemoveComment = {
+ const form: RemoveComment = {
comment_id: comment.id,
removed: !comment.removed,
reason: i.state.removeReason,
}
handleDistinguishClick(i: CommentNode) {
- let comment = i.props.node.comment_view.comment;
- let auth = myAuth();
+ const comment = i.props.node.comment_view.comment;
+ const auth = myAuth();
if (auth) {
- let form: DistinguishComment = {
+ const form: DistinguishComment = {
comment_id: comment.id,
distinguished: !comment.distinguished,
auth,
}
handleMarkRead(i: CommentNode) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
if (i.isPersonMentionType(i.props.node.comment_view)) {
- let form: MarkPersonMentionAsRead = {
+ const form: MarkPersonMentionAsRead = {
person_mention_id: i.props.node.comment_view.person_mention.id,
read: !i.props.node.comment_view.person_mention.read,
auth,
};
WebSocketService.Instance.send(wsClient.markPersonMentionAsRead(form));
} else if (i.isCommentReplyType(i.props.node.comment_view)) {
- let form: MarkCommentReplyAsRead = {
+ const form: MarkCommentReplyAsRead = {
comment_reply_id: i.props.node.comment_view.comment_reply.id,
read: !i.props.node.comment_view.comment_reply.read,
auth,
}
handleModBanBothSubmit(i: CommentNode) {
- let cv = i.props.node.comment_view;
- let auth = myAuth();
+ const cv = i.props.node.comment_view;
+ const auth = myAuth();
if (auth) {
if (i.state.banType == BanType.Community) {
// If its an unban, restore all their data
- let ban = !cv.creator_banned_from_community;
+ const ban = !cv.creator_banned_from_community;
if (ban == false) {
i.setState({ removeData: false });
}
- let form: BanFromCommunity = {
+ const form: BanFromCommunity = {
person_id: cv.creator.id,
community_id: cv.community.id,
ban,
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
} else {
// If its an unban, restore all their data
- let ban = !cv.creator.banned;
+ const ban = !cv.creator.banned;
if (ban == false) {
i.setState({ removeData: false });
}
- let form: BanPerson = {
+ const form: BanPerson = {
person_id: cv.creator.id,
ban,
remove_data: i.state.removeData,
handlePurgeSubmit(i: CommentNode, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
if (i.state.purgeType == PurgeType.Person) {
- let form: PurgePerson = {
+ const form: PurgePerson = {
person_id: i.props.node.comment_view.creator.id,
reason: i.state.purgeReason,
auth,
};
WebSocketService.Instance.send(wsClient.purgePerson(form));
} else if (i.state.purgeType == PurgeType.Comment) {
- let form: PurgeComment = {
+ const form: PurgeComment = {
comment_id: i.props.node.comment_view.comment.id,
reason: i.state.purgeReason,
auth,
}
handleAddModToCommunity(i: CommentNode) {
- let cv = i.props.node.comment_view;
- let auth = myAuth();
+ const cv = i.props.node.comment_view;
+ const auth = myAuth();
if (auth) {
- let form: AddModToCommunity = {
+ const form: AddModToCommunity = {
person_id: cv.creator.id,
community_id: cv.community.id,
added: !isMod(cv.creator.id, i.props.moderators),
}
handleAddAdmin(i: CommentNode) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let creatorId = i.props.node.comment_view.creator.id;
- let form: AddAdmin = {
+ const creatorId = i.props.node.comment_view.creator.id;
+ const form: AddAdmin = {
person_id: creatorId,
added: !isAdmin(creatorId, i.props.admins),
auth,
}
handleTransferCommunity(i: CommentNode) {
- let cv = i.props.node.comment_view;
- let auth = myAuth();
+ const cv = i.props.node.comment_view;
+ const auth = myAuth();
if (auth) {
- let form: TransferCommunity = {
+ const form: TransferCommunity = {
community_id: cv.community.id,
person_id: cv.creator.id,
auth,
}
get isCommentNew(): boolean {
- let now = moment.utc().subtract(10, "minutes");
- let then = moment.utc(this.props.node.comment_view.comment.published);
+ const now = moment.utc().subtract(10, "minutes");
+ const then = moment.utc(this.props.node.comment_view.comment.published);
return now.isBefore(then);
}
}
handleFetchChildren(i: CommentNode) {
- let form: GetComments = {
+ const form: GetComments = {
post_id: i.props.node.comment_view.post.id,
parent_id: i.props.node.comment_view.comment.id,
max_depth: commentTreeMaxDepth,
}
get pointsTippy(): string {
- let points = i18n.t("number_of_points", {
+ const points = i18n.t("number_of_points", {
count: Number(this.state.score),
formattedCount: numToSI(this.state.score),
});
- let upvotes = i18n.t("number_of_upvotes", {
+ const upvotes = i18n.t("number_of_upvotes", {
count: Number(this.state.upvotes),
formattedCount: numToSI(this.state.upvotes),
});
- let downvotes = i18n.t("number_of_downvotes", {
+ const downvotes = i18n.t("number_of_downvotes", {
count: Number(this.state.downvotes),
formattedCount: numToSI(this.state.downvotes),
});
}
render() {
- let maxComments = this.props.maxCommentsShown ?? this.props.nodes.length;
+ const maxComments = this.props.maxCommentsShown ?? this.props.nodes.length;
return (
<div className="comments">
}
render() {
- let r = this.props.report;
- let comment = r.comment;
- let tippyContent = i18n.t(
+ const r = this.props.report;
+ const comment = r.comment;
+ const tippyContent = i18n.t(
r.comment_report.resolved ? "unresolve_report" : "resolve_report"
);
// Set the original post data ( a troll could change it )
comment.content = r.comment_report.original_comment_text;
- let comment_view: CommentView = {
+ const comment_view: CommentView = {
comment,
creator: r.comment_creator,
post: r.post,
my_vote: r.my_vote,
};
- let node: CommentNodeI = {
+ const node: CommentNodeI = {
comment_view,
children: [],
depth: 0,
}
handleResolveReport(i: CommentReport) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: ResolveCommentReport = {
+ const form: ResolveCommentReport = {
report_id: i.props.report.comment_report.id,
resolved: !i.props.report.comment_report.resolved,
auth,
}
render() {
- let banner = this.props.banner;
- let icon = this.props.icon;
+ const banner = this.props.banner;
+ const icon = this.props.icon;
return (
<div className="position-relative mb-2">
{banner && <PictrsImage src={banner} banner alt="" />}
this.handleEmojiClick = this.handleEmojiClick.bind(this);
}
componentDidMount() {
- let div: any = document.getElementById("emoji-picker");
+ const div: any = document.getElementById("emoji-picker");
if (div) {
div.appendChild(
getEmojiMart(this.handleEmojiClick, this.props.pickerOptions)
/// Taken from https://metatags.io/
export class HtmlTags extends Component<HtmlTagsProps, any> {
render() {
- let url = httpExternalPath(this.props.path);
- let desc = this.props.description;
- let image = this.props.image;
+ const url = httpExternalPath(this.props.path);
+ const desc = this.props.description;
+ const image = this.props.image;
return (
<Helmet title={this.props.title}>
// Necessary because there is no HTML way to set selected for multiple in value=
setSelectedValues() {
- let ids = this.props.selectedLanguageIds?.map(toString);
+ const ids = this.props.selectedLanguageIds?.map(toString);
if (ids) {
- let select = (document.getElementById(this.id) as HTMLSelectElement)
+ const select = (document.getElementById(this.id) as HTMLSelectElement)
.options;
for (let i = 0; i < select.length; i++) {
- let o = select[i];
+ const o = select[i];
if (ids.includes(o.value)) {
o.selected = true;
}
}
handleLanguageChange(i: LanguageSelect, event: any) {
- let options: HTMLOptionElement[] = Array.from(event.target.options);
- let selected: number[] = options
+ const options: HTMLOptionElement[] = Array.from(event.target.options);
+ const selected: number[] = options
.filter(o => o.selected)
.map(o => Number(o.value));
}
componentDidMount() {
- let textarea: any = document.getElementById(this.id);
+ const textarea: any = document.getElementById(this.id);
if (textarea) {
autosize(textarea);
this.tribute.attach(textarea);
}
render() {
- let languageId = this.state.languageId;
+ const languageId = this.state.languageId;
return (
<form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}>
handleEmoji(i: MarkdownTextArea, e: any) {
let value = e.native;
if (value == null) {
- let emoji = customEmojisLookup.get(e.id)?.custom_emoji;
+ const emoji = customEmojisLookup.get(e.id)?.custom_emoji;
if (emoji) {
value = `![${emoji.alt_text}](${emoji.image_url} "${emoji.shortcode}")`;
}
content: `${i.state.content ?? ""} ${value} `,
});
i.contentChange();
- let textarea: any = document.getElementById(i.id);
+ const textarea: any = document.getElementById(i.id);
autosize.update(textarea);
}
contentChange() {
// Coerces the undefineds to empty strings, for replacing in the DB
- let content = this.state.content ?? "";
+ const content = this.state.content ?? "";
this.props.onContentChange?.(content);
}
handleSubmit(i: MarkdownTextArea, event: any) {
event.preventDefault();
i.setState({ loading: true });
- let msg = {
+ const msg = {
val: i.state.content,
formId: i.formId,
languageId: i.state.languageId,
}
simpleInsert(chars: string) {
- let content = this.state.content;
+ const content = this.state.content;
if (!content) {
this.setState({ content: `${chars} ` });
} else {
});
}
- let textarea: any = document.getElementById(this.id);
+ const textarea: any = document.getElementById(this.id);
textarea.focus();
setTimeout(() => {
autosize.update(textarea);
handleInsertSpoiler(i: MarkdownTextArea, event: any) {
event.preventDefault();
- let beforeChars = `\n::: spoiler ${i18n.t("spoiler")}\n`;
- let afterChars = "\n:::\n";
+ const beforeChars = `\n::: spoiler ${i18n.t("spoiler")}\n`;
+ const afterChars = "\n:::\n";
i.simpleSurroundBeforeAfter(beforeChars, afterChars);
}
constructor(props: any, context: any) {
super(props, context);
- let lang = getLanguages();
+ const lang = getLanguages();
moment.locale(lang);
}
createdAndModifiedTimes() {
- let updated = this.props.updated;
+ const updated = this.props.updated;
let line = `${capitalizeFirstLetter(i18n.t("created"))}: ${this.format(
this.props.published
)}`;
</span>
);
} else {
- let published = this.props.published;
+ const published = this.props.published;
return (
<span
className="pointer unselectable"
// sample url:
// http://localhost:8535/pictrs/image/file.png?thumbnail=256&format=jpg
- let split = this.props.src.split("/pictrs/image/");
+ const split = this.props.src.split("/pictrs/image/");
// If theres not multiple, then its not a pictrs image
if (split.length == 1) {
return this.props.src;
}
- let host = split[0];
- let path = split[1];
+ const host = split[0];
+ const path = split[1];
- let params = { format };
+ const params = { format };
if (this.props.thumbnail) {
params["thumbnail"] = thumbnailSize;
params["thumbnail"] = iconThumbnailSize;
}
- let paramsStr = new URLSearchParams(params).toString();
- let out = `${host}/pictrs/image/${path}?${paramsStr}`;
+ const paramsStr = new URLSearchParams(params).toString();
+ const out = `${host}/pictrs/image/${path}?${paramsStr}`;
return out;
}
}
render() {
- let a = this.props.application;
- let ra = this.props.application.registration_application;
- let accepted = a.creator_local_user.accepted_application;
+ const a = this.props.application;
+ const ra = this.props.application.registration_application;
+ const accepted = a.creator_local_user.accepted_application;
return (
<div>
}
handleApprove(i: RegistrationApplication) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
i.setState({ denyExpanded: false });
- let form: ApproveRegistrationApplication = {
+ const form: ApproveRegistrationApplication = {
id: i.props.application.registration_application.id,
approve: true,
auth,
handleDeny(i: RegistrationApplication) {
if (i.state.denyExpanded) {
i.setState({ denyExpanded: false });
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: ApproveRegistrationApplication = {
+ const form: ApproveRegistrationApplication = {
id: i.props.application.registration_application.id,
approve: false,
deny_reason: i.state.denyReason,
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
- let cv = this.props.community_view;
+ const cv = this.props.community_view;
if (cv) {
this.state = {
handleCreateCommunitySubmit(i: CommunityForm, event: any) {
event.preventDefault();
i.setState({ loading: true });
- let cForm = i.state.form;
- let auth = myAuth();
+ const cForm = i.state.form;
+ const auth = myAuth();
- let cv = i.props.community_view;
+ const cv = i.props.community_view;
if (auth) {
if (cv) {
- let form: EditCommunity = {
+ const form: EditCommunity = {
community_id: cv.community.id,
title: cForm.title,
description: cForm.description,
WebSocketService.Instance.send(wsClient.editCommunity(form));
} else {
if (cForm.title && cForm.name) {
- let form: CreateCommunity = {
+ const form: CreateCommunity = {
name: cForm.name,
title: cForm.title,
description: cForm.description,
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
// Errors handled by top level pages
this.setState({ loading: false });
return;
} else if (op == UserOperation.CreateCommunity) {
- let data = wsJsonToRes<CommunityResponse>(msg);
+ const data = wsJsonToRes<CommunityResponse>(msg);
this.props.onCreate?.(data.community_view);
// Update myUserInfo
- let community = data.community_view.community;
+ const community = data.community_view.community;
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
- let person = mui.local_user_view.person;
+ const person = mui.local_user_view.person;
mui.follows.push({
community,
follower: person,
});
}
} else if (op == UserOperation.EditCommunity) {
- let data = wsJsonToRes<CommunityResponse>(msg);
+ const data = wsJsonToRes<CommunityResponse>(msg);
this.setState({ loading: false });
this.props.onEdit?.(data.community_view);
- let community = data.community_view.community;
+ const community = data.community_view.community;
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
- let followFound = mui.follows.findIndex(
+ const followFound = mui.follows.findIndex(
f => f.community.id == community.id
);
if (followFound) {
mui.follows[followFound].community = community;
}
- let moderatesFound = mui.moderates.findIndex(
+ const moderatesFound = mui.moderates.findIndex(
f => f.community.id == community.id
);
if (moderatesFound) {
}
render() {
- let community = this.props.community;
+ const community = this.props.community;
let name_: string, title: string, link: string;
- let local = community.local == null ? true : community.local;
+ const local = community.local == null ? true : community.local;
if (local) {
name_ = community.name;
title = community.title;
link = `/c/${community.name}`;
} else {
- let domain = hostname(community.actor_id);
+ const domain = hostname(community.actor_id);
name_ = `${community.name}@${domain}`;
title = `${community.title}@${domain}`;
link = !this.props.realLink ? `/c/${name_}` : community.actor_id;
}
- let apubName = `!${name_}`;
- let displayName = this.props.useApubName ? apubName : title;
+ const apubName = `!${name_}`;
+ const displayName = this.props.useApubName ? apubName : title;
return !this.props.realLink ? (
<Link
title={apubName}
}
avatarAndName(displayName: string) {
- let icon = this.props.community.icon;
+ const icon = this.props.community.icon;
return (
<>
{!this.props.hideAvatar &&
}
communityTitle() {
- let community = this.props.community_view.community;
- let subscribed = this.props.community_view.subscribed;
+ const community = this.props.community_view.community;
+ const subscribed = this.props.community_view.subscribed;
return (
<div>
<h5 className="mb-0">
}
badges() {
- let community_view = this.props.community_view;
- let counts = community_view.counts;
+ const community_view = this.props.community_view;
+ const counts = community_view.counts;
return (
<ul className="my-1 list-inline">
<li className="list-inline-item badge badge-secondary">
}
createPost() {
- let cv = this.props.community_view;
+ const cv = this.props.community_view;
return (
<Link
className={`btn btn-secondary btn-block mb-2 ${
}
subscribe() {
- let community_view = this.props.community_view;
+ const community_view = this.props.community_view;
return (
<div className="mb-2">
{community_view.subscribed == "NotSubscribed" && (
}
blockCommunity() {
- let community_view = this.props.community_view;
- let blocked = this.props.community_view.blocked;
+ const community_view = this.props.community_view;
+ const blocked = this.props.community_view.blocked;
return (
<div className="mb-2">
}
description() {
- let desc = this.props.community_view.community.description;
+ const desc = this.props.community_view.community.description;
return (
desc && (
<div className="md-div" dangerouslySetInnerHTML={mdToHtml(desc)} />
}
adminButtons() {
- let community_view = this.props.community_view;
+ const community_view = this.props.community_view;
return (
<>
<ul className="list-inline mb-1 text-muted font-weight-bold">
handleDeleteClick(i: Sidebar, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let deleteForm: DeleteCommunity = {
+ const deleteForm: DeleteCommunity = {
community_id: i.props.community_view.community.id,
deleted: !i.props.community_view.community.deleted,
auth,
}
handleLeaveModTeamClick(i: Sidebar) {
- let mui = UserService.Instance.myUserInfo;
- let auth = myAuth();
+ const mui = UserService.Instance.myUserInfo;
+ const auth = myAuth();
if (auth && mui) {
- let form: AddModToCommunity = {
+ const form: AddModToCommunity = {
person_id: mui.local_user_view.person.id,
community_id: i.props.community_view.community.id,
added: false,
handleUnsubscribe(i: Sidebar, event: any) {
event.preventDefault();
- let community_id = i.props.community_view.community.id;
- let auth = myAuth();
+ const community_id = i.props.community_view.community.id;
+ const auth = myAuth();
if (auth) {
- let form: FollowCommunity = {
+ const form: FollowCommunity = {
community_id,
follow: false,
auth,
}
// Update myUserInfo
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
mui.follows = mui.follows.filter(i => i.community.id != community_id);
}
handleSubscribe(i: Sidebar, event: any) {
event.preventDefault();
- let community_id = i.props.community_view.community.id;
- let auth = myAuth();
+ const community_id = i.props.community_view.community.id;
+ const auth = myAuth();
if (auth) {
- let form: FollowCommunity = {
+ const form: FollowCommunity = {
community_id,
follow: true,
auth,
}
// Update myUserInfo
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
mui.follows.push({
community: i.props.community_view.community,
handleModRemoveSubmit(i: Sidebar, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let removeForm: RemoveCommunity = {
+ const removeForm: RemoveCommunity = {
community_id: i.props.community_view.community.id,
removed: !i.props.community_view.community.removed,
reason: i.state.removeReason,
handlePurgeSubmit(i: Sidebar, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: PurgeCommunity = {
+ const form: PurgeCommunity = {
community_id: i.props.community_view.community.id,
reason: i.state.purgeReason,
auth,
handleBlock(i: Sidebar, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let blockCommunityForm: BlockCommunity = {
+ const blockCommunityForm: BlockCommunity = {
community_id: i.props.community_view.community.id,
block: true,
auth,
handleUnblock(i: Sidebar, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let blockCommunityForm: BlockCommunity = {
+ const blockCommunityForm: BlockCommunity = {
community_id: i.props.community_view.community.id,
block: false,
auth,
loading: false,
};
} else {
- let cAuth = myAuth();
+ const cAuth = myAuth();
if (cAuth) {
WebSocketService.Instance.send(
wsClient.getBannedPersons({
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
- let promises: Promise<any>[] = [];
+ const promises: Promise<any>[] = [];
- let auth = req.auth;
+ const auth = req.auth;
if (auth) {
- let bannedPersonsForm: GetBannedPersons = { auth };
+ const bannedPersonsForm: GetBannedPersons = { auth };
promises.push(req.client.getBannedPersons(bannedPersonsForm));
promises.push(req.client.getFederatedInstances({ auth }));
}
}
handleLeaveAdminTeam(i: AdminSettings) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
i.setState({ leaveAdminTeamLoading: true });
WebSocketService.Instance.send(wsClient.leaveAdmin({ auth }));
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
this.setState({ loading: false });
return;
} else if (op == UserOperation.EditSite) {
- let data = wsJsonToRes<SiteResponse>(msg);
+ const data = wsJsonToRes<SiteResponse>(msg);
this.setState(s => ((s.siteRes.site_view = data.site_view), s));
toast(i18n.t("site_saved"));
} else if (op == UserOperation.GetBannedPersons) {
- let data = wsJsonToRes<BannedPersonsResponse>(msg);
+ const data = wsJsonToRes<BannedPersonsResponse>(msg);
this.setState({ banned: data.banned, loading: false });
} else if (op == UserOperation.LeaveAdmin) {
- let data = wsJsonToRes<GetSiteResponse>(msg);
+ const data = wsJsonToRes<GetSiteResponse>(msg);
this.setState(s => ((s.siteRes.site_view = data.site_view), s));
this.setState({ leaveAdminTeamLoading: false });
toast(i18n.t("left_admin_team"));
this.context.router.history.push("/");
} else if (op == UserOperation.GetFederatedInstances) {
- let data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
+ const data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
this.setState({ instancesRes: data });
}
}
props: { form: EmojiForm; index: number },
event: any
) {
- let custom_emojis = [...props.form.state.customEmojis];
- let pagedIndex =
+ const custom_emojis = [...props.form.state.customEmojis];
+ const pagedIndex =
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
- let item = {
+ const item = {
...props.form.state.customEmojis[pagedIndex],
category: event.target.value,
changed: true,
props: { form: EmojiForm; index: number },
event: any
) {
- let custom_emojis = [...props.form.state.customEmojis];
- let pagedIndex =
+ const custom_emojis = [...props.form.state.customEmojis];
+ const pagedIndex =
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
- let item = {
+ const item = {
...props.form.state.customEmojis[pagedIndex],
shortcode: event.target.value,
changed: true,
props: { form: EmojiForm; index: number; overrideValue: string | null },
event: any
) {
- let custom_emojis = [...props.form.state.customEmojis];
- let pagedIndex =
+ const custom_emojis = [...props.form.state.customEmojis];
+ const pagedIndex =
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
- let item = {
+ const item = {
...props.form.state.customEmojis[pagedIndex],
image_url: props.overrideValue ?? event.target.value,
changed: true,
props: { form: EmojiForm; index: number },
event: any
) {
- let custom_emojis = [...props.form.state.customEmojis];
- let pagedIndex =
+ const custom_emojis = [...props.form.state.customEmojis];
+ const pagedIndex =
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
- let item = {
+ const item = {
...props.form.state.customEmojis[pagedIndex],
alt_text: event.target.value,
changed: true,
props: { form: EmojiForm; index: number },
event: any
) {
- let custom_emojis = [...props.form.state.customEmojis];
- let pagedIndex =
+ const custom_emojis = [...props.form.state.customEmojis];
+ const pagedIndex =
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
- let item = {
+ const item = {
...props.form.state.customEmojis[pagedIndex],
keywords: event.target.value,
changed: true,
index: number;
cv: CustomEmojiViewForm;
}) {
- let pagedIndex =
+ const pagedIndex =
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
if (props.cv.id != 0) {
const deleteForm: DeleteCustomEmoji = {
};
WebSocketService.Instance.send(wsClient.deleteCustomEmoji(deleteForm));
} else {
- let custom_emojis = [...props.form.state.customEmojis];
+ const custom_emojis = [...props.form.state.customEmojis];
custom_emojis.splice(Number(pagedIndex), 1);
props.form.setState({ customEmojis: custom_emojis });
}
handleAddEmojiClick(form: EmojiForm, event: any) {
event.preventDefault();
- let custom_emojis = [...form.state.customEmojis];
+ const custom_emojis = [...form.state.customEmojis];
const page =
1 + Math.floor(form.state.customEmojis.length / form.itemsPerPage);
- let item: CustomEmojiViewForm = {
+ const item: CustomEmojiViewForm = {
id: 0,
shortcode: "",
alt_text: "",
pictrsDeleteToast(file.name, res.delete_url as string);
} else {
toast(JSON.stringify(res), "danger");
- let hash = res.files?.at(0)?.file;
- let url = `${res.url}/${hash}`;
+ const hash = res.files?.at(0)?.file;
+ const url = `${res.url}/${hash}`;
props.form.handleEmojiImageUrlChange(
{ form: props.form, index: props.index, overrideValue: url },
event
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
this.setState({ loading: false });
return;
} else if (op == UserOperation.CreateCustomEmoji) {
- let data = wsJsonToRes<CustomEmojiResponse>(msg);
+ const data = wsJsonToRes<CustomEmojiResponse>(msg);
const custom_emoji_view = data.custom_emoji;
updateEmojiDataModel(custom_emoji_view);
- let currentEmojis = this.state.customEmojis;
- let newEmojiIndex = currentEmojis.findIndex(
+ const currentEmojis = this.state.customEmojis;
+ const newEmojiIndex = currentEmojis.findIndex(
x => x.shortcode == custom_emoji_view.custom_emoji.shortcode
);
currentEmojis[newEmojiIndex].id = custom_emoji_view.custom_emoji.id;
toast(i18n.t("saved_emoji"));
this.setState({ loading: false });
} else if (op == UserOperation.EditCustomEmoji) {
- let data = wsJsonToRes<CustomEmojiResponse>(msg);
+ const data = wsJsonToRes<CustomEmojiResponse>(msg);
const custom_emoji_view = data.custom_emoji;
updateEmojiDataModel(data.custom_emoji);
- let currentEmojis = this.state.customEmojis;
- let newEmojiIndex = currentEmojis.findIndex(
+ const currentEmojis = this.state.customEmojis;
+ const newEmojiIndex = currentEmojis.findIndex(
x => x.shortcode == custom_emoji_view.custom_emoji.shortcode
);
currentEmojis[newEmojiIndex].changed = false;
toast(i18n.t("saved_emoji"));
this.setState({ loading: false });
} else if (op == UserOperation.DeleteCustomEmoji) {
- let data = wsJsonToRes<DeleteCustomEmojiResponse>(msg);
+ const data = wsJsonToRes<DeleteCustomEmojiResponse>(msg);
if (data.success) {
removeFromEmojiDataModel(data.id);
- let custom_emojis = [
+ const custom_emojis = [
...this.state.customEmojis.filter(x => x.id != data.id),
];
this.setState({ customEmojis: custom_emojis });
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
- let promises: Promise<any>[] = [];
+ const promises: Promise<any>[] = [];
promises.push(req.client.getFederatedInstances({}));
}
render() {
- let federated_instances = this.state.instancesRes?.federated_instances;
+ const federated_instances = this.state.instancesRes?.federated_instances;
return federated_instances ? (
<div className="container-lg">
<HtmlTags
);
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
this.setState({ loading: false });
return;
} else if (op == UserOperation.GetFederatedInstances) {
- let data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
+ const data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
this.setState({ loading: false, instancesRes: data });
}
}
}
render() {
- let legal = this.state.siteRes.site_view.local_site.legal_information;
+ const legal = this.state.siteRes.site_view.local_site.legal_information;
return (
<div className="container-lg">
<HtmlTags
handleLoginSubmit(i: Login, event: any) {
event.preventDefault();
i.setState({ loginLoading: true });
- let lForm = i.state.form;
- let username_or_email = lForm.username_or_email;
- let password = lForm.password;
- let totp_2fa_token = lForm.totp_2fa_token;
+ const lForm = i.state.form;
+ const username_or_email = lForm.username_or_email;
+ const password = lForm.password;
+ const totp_2fa_token = lForm.totp_2fa_token;
if (username_or_email && password) {
- let form: LoginI = {
+ const form: LoginI = {
username_or_email,
password,
totp_2fa_token,
handlePasswordReset(i: Login, event: any) {
event.preventDefault();
- let email = i.state.form.username_or_email;
+ const email = i.state.form.username_or_email;
if (email) {
- let resetForm: PasswordReset = { email };
+ const resetForm: PasswordReset = { email };
WebSocketService.Instance.send(wsClient.passwordReset(resetForm));
}
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
// If the error comes back that the token is missing, show the TOTP field
}
} else {
if (op == UserOperation.Login) {
- let data = wsJsonToRes<LoginResponse>(msg);
+ const data = wsJsonToRes<LoginResponse>(msg);
UserService.Instance.login(data);
this.props.history.push("/");
location.reload();
} else if (op == UserOperation.PasswordReset) {
toast(i18n.t("reset_password_mail_sent"));
} else if (op == UserOperation.GetSite) {
- let data = wsJsonToRes<GetSiteResponse>(msg);
+ const data = wsJsonToRes<GetSiteResponse>(msg);
this.setState({ siteRes: data });
}
}
event.preventDefault();
i.setState({ userLoading: true });
event.preventDefault();
- let cForm = i.state.form;
+ const cForm = i.state.form;
if (cForm.username && cForm.password && cForm.password_verify) {
- let form: Register = {
+ const form: Register = {
username: cForm.username,
password: cForm.password,
password_verify: cForm.password_verify,
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
this.setState({ userLoading: false });
return;
} else if (op == UserOperation.Register) {
- let data = wsJsonToRes<LoginResponse>(msg);
+ const data = wsJsonToRes<LoginResponse>(msg);
this.setState({ userLoading: false });
UserService.Instance.login(data);
if (UserService.Instance.jwtInfo) {
}
get documentTitle(): string {
- let siteView = this.state.siteRes.site_view;
+ const siteView = this.state.siteRes.site_view;
return `${this.titleName(siteView)} - ${siteView.site.name}`;
}
}
registerForm() {
- let siteView = this.state.siteRes.site_view;
+ const siteView = this.state.siteRes.site_view;
return (
<form onSubmit={linkEvent(this, this.handleRegisterSubmit)}>
<h5>{this.titleName(siteView)}</h5>
}
showCaptcha() {
- let captchaRes = this.state.captcha?.ok;
+ const captchaRes = this.state.captcha?.ok;
return captchaRes ? (
<div className="col-sm-4">
<>
}
get passwordStrength(): string | undefined {
- let password = this.state.form.password;
+ const password = this.state.form.password;
return password
? passwordStrength(password, passwordStrengthOptions).value
: undefined;
}
get passwordColorClass(): string {
- let strength = this.passwordStrength;
+ const strength = this.passwordStrength;
if (strength && ["weak", "medium"].includes(strength)) {
return "text-warning";
handleRegisterSubmit(i: Signup, event: any) {
event.preventDefault();
i.setState({ registerLoading: true });
- let cForm = i.state.form;
+ const cForm = i.state.form;
if (cForm.username && cForm.password && cForm.password_verify) {
- let form: Register = {
+ const form: Register = {
username: cForm.username,
password: cForm.password,
password_verify: cForm.password_verify,
handleCaptchaPlay(i: Signup) {
// This was a bad bug, it should only build the new audio on a new file.
// Replays would stop prematurely if this was rebuilt every time.
- let captchaRes = i.state.captcha?.ok;
+ const captchaRes = i.state.captcha?.ok;
if (captchaRes) {
if (!i.audio) {
- let base64 = `data:audio/wav;base64,${captchaRes.wav}`;
+ const base64 = `data:audio/wav;base64,${captchaRes.wav}`;
i.audio = new Audio(base64);
i.audio.play();
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
return;
} else {
if (op == UserOperation.Register) {
- let data = wsJsonToRes<LoginResponse>(msg);
+ const data = wsJsonToRes<LoginResponse>(msg);
// Only log them in if a jwt was set
if (data.jwt) {
UserService.Instance.login(data);
this.props.history.push("/");
}
} else if (op == UserOperation.GetCaptcha) {
- let data = wsJsonToRes<GetCaptchaResponse>(msg);
+ const data = wsJsonToRes<GetCaptchaResponse>(msg);
if (data.ok) {
this.setState({ captcha: data });
this.setState(s => ((s.form.captcha_uuid = data.ok?.uuid), s));
} else if (op == UserOperation.PasswordReset) {
toast(i18n.t("reset_password_mail_sent"));
} else if (op == UserOperation.GetSite) {
- let data = wsJsonToRes<GetSiteResponse>(msg);
+ const data = wsJsonToRes<GetSiteResponse>(msg);
this.setState({ siteRes: data });
}
}
this.handleDiscussionLanguageChange =
this.handleDiscussionLanguageChange.bind(this);
- let site = this.props.siteRes.site_view.site;
- let ls = this.props.siteRes.site_view.local_site;
+ const site = this.props.siteRes.site_view.site;
+ const ls = this.props.siteRes.site_view.local_site;
this.state = {
...this.state,
siteForm: {
}
render() {
- let siteSetup = this.props.siteRes.site_view.local_site.site_setup;
+ const siteSetup = this.props.siteRes.site_view.local_site.site_setup;
return (
<>
<Prompt
handleCreateSiteSubmit(i: SiteForm, event: any) {
event.preventDefault();
i.setState({ loading: true });
- let auth = myAuth() ?? "TODO";
+ const auth = myAuth() ?? "TODO";
i.setState(s => ((s.siteForm.auth = auth), s));
if (i.props.siteRes.site_view.local_site.site_setup) {
WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm));
} else {
- let sForm = i.state.siteForm;
- let form: CreateSite = {
+ const sForm = i.state.siteForm;
+ const form: CreateSite = {
name: sForm.name ?? "My site",
sidebar: sForm.sidebar,
description: sForm.description,
}
handleTaglineChange(i: SiteForm, index: number, val: string) {
- let taglines = i.state.siteForm.taglines;
+ const taglines = i.state.siteForm.taglines;
if (taglines) {
taglines[index] = val;
i.setState(i.state);
event: InfernoMouseEvent<HTMLButtonElement>
) {
event.preventDefault();
- let taglines = i.state.siteForm.taglines;
+ const taglines = i.state.siteForm.taglines;
if (taglines) {
taglines.splice(index, 1);
i.state.siteForm.taglines = undefined;
}
siteInfo() {
- let site = this.props.site;
+ const site = this.props.site;
return (
<div>
{site.description && <h6>{site.description}</h6>}
}
badges(siteAggregates: SiteAggregates) {
- let counts = siteAggregates;
- let online = this.props.online ?? 1;
+ const counts = siteAggregates;
+ const online = this.props.online ?? 1;
return (
<ul className="my-2 list-inline">
<li className="list-inline-item badge badge-secondary">
}
handleTaglineChange(i: TaglineForm, index: number, val: string) {
- let taglines = i.state.siteForm.taglines;
+ const taglines = i.state.siteForm.taglines;
if (taglines) {
taglines[index] = val;
i.setState(i.state);
event: any
) {
event.preventDefault();
- let taglines = props.form.state.siteForm.taglines;
+ const taglines = props.form.state.siteForm.taglines;
if (taglines) {
taglines.splice(props.index, 1);
props.form.state.siteForm.taglines = undefined;
handleSaveClick(i: TaglineForm) {
i.setState({ loading: true });
- let auth = myAuth() ?? "TODO";
+ const auth = myAuth() ?? "TODO";
i.setState(s => ((s.siteForm.auth = auth), s));
WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm));
i.setState({ ...i.state, editingRow: undefined });
}
get documentTitle(): string {
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
return mui
? `@${mui.local_user_view.person.name} ${i18n.t("inbox")} - ${
this.state.siteRes.site_view.site.name
}
render() {
- let auth = myAuth();
- let inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined;
+ const auth = myAuth();
+ const inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined;
return (
<div className="container-lg">
{this.state.loading ? (
}
buildCombined(): ReplyType[] {
- let replies: ReplyType[] = this.state.replies.map(r =>
+ const replies: ReplyType[] = this.state.replies.map(r =>
this.replyToReplyType(r)
);
- let mentions: ReplyType[] = this.state.mentions.map(r =>
+ const mentions: ReplyType[] = this.state.mentions.map(r =>
this.mentionToReplyType(r)
);
- let messages: ReplyType[] = this.state.messages.map(r =>
+ const messages: ReplyType[] = this.state.messages.map(r =>
this.messageToReplyType(r)
);
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
- let promises: Promise<any>[] = [];
+ const promises: Promise<any>[] = [];
- let sort: CommentSortType = "New";
- let auth = req.auth;
+ const sort: CommentSortType = "New";
+ const auth = req.auth;
if (auth) {
// It can be /u/me, or /username/1
- let repliesForm: GetReplies = {
+ const repliesForm: GetReplies = {
sort: "New",
unread_only: true,
page: 1,
};
promises.push(req.client.getReplies(repliesForm));
- let personMentionsForm: GetPersonMentions = {
+ const personMentionsForm: GetPersonMentions = {
sort,
unread_only: true,
page: 1,
};
promises.push(req.client.getPersonMentions(personMentionsForm));
- let privateMessagesForm: GetPrivateMessages = {
+ const privateMessagesForm: GetPrivateMessages = {
unread_only: true,
page: 1,
limit: fetchLimit,
}
refetch() {
- let sort = this.state.sort;
- let unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
- let page = this.state.page;
- let limit = fetchLimit;
- let auth = myAuth();
+ const sort = this.state.sort;
+ const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
+ const page = this.state.page;
+ const limit = fetchLimit;
+ const auth = myAuth();
if (auth) {
- let repliesForm: GetReplies = {
+ const repliesForm: GetReplies = {
sort,
unread_only,
page,
};
WebSocketService.Instance.send(wsClient.getReplies(repliesForm));
- let personMentionsForm: GetPersonMentions = {
+ const personMentionsForm: GetPersonMentions = {
sort,
unread_only,
page,
wsClient.getPersonMentions(personMentionsForm)
);
- let privateMessagesForm: GetPrivateMessages = {
+ const privateMessagesForm: GetPrivateMessages = {
unread_only,
page,
limit,
}
markAllAsRead(i: Inbox) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
WebSocketService.Instance.send(
wsClient.markAllAsRead({
}
sendUnreadCount(read: boolean) {
- let urcs = UserService.Instance.unreadInboxCountSub;
+ const urcs = UserService.Instance.unreadInboxCountSub;
if (read) {
urcs.next(urcs.getValue() - 1);
} else {
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
} else if (msg.reconnect) {
this.refetch();
} else if (op == UserOperation.GetReplies) {
- let data = wsJsonToRes<GetRepliesResponse>(msg);
+ const data = wsJsonToRes<GetRepliesResponse>(msg);
this.setState({ replies: data.replies });
this.setState({ combined: this.buildCombined(), loading: false });
window.scrollTo(0, 0);
setupTippy();
} else if (op == UserOperation.GetPersonMentions) {
- let data = wsJsonToRes<GetPersonMentionsResponse>(msg);
+ const data = wsJsonToRes<GetPersonMentionsResponse>(msg);
this.setState({ mentions: data.mentions });
this.setState({ combined: this.buildCombined() });
window.scrollTo(0, 0);
setupTippy();
} else if (op == UserOperation.GetPrivateMessages) {
- let data = wsJsonToRes<PrivateMessagesResponse>(msg);
+ const data = wsJsonToRes<PrivateMessagesResponse>(msg);
this.setState({ messages: data.private_messages });
this.setState({ combined: this.buildCombined() });
window.scrollTo(0, 0);
setupTippy();
} else if (op == UserOperation.EditPrivateMessage) {
- let data = wsJsonToRes<PrivateMessageResponse>(msg);
- let found = this.state.messages.find(
+ const data = wsJsonToRes<PrivateMessageResponse>(msg);
+ const found = this.state.messages.find(
m =>
m.private_message.id === data.private_message_view.private_message.id
);
if (found) {
- let combinedView = this.state.combined.find(
+ const combinedView = this.state.combined.find(
i => i.id == data.private_message_view.private_message.id
)?.view as PrivateMessageView | undefined;
if (combinedView) {
}
this.setState(this.state);
} else if (op == UserOperation.DeletePrivateMessage) {
- let data = wsJsonToRes<PrivateMessageResponse>(msg);
- let found = this.state.messages.find(
+ const data = wsJsonToRes<PrivateMessageResponse>(msg);
+ const found = this.state.messages.find(
m =>
m.private_message.id === data.private_message_view.private_message.id
);
if (found) {
- let combinedView = this.state.combined.find(
+ const combinedView = this.state.combined.find(
i => i.id == data.private_message_view.private_message.id
)?.view as PrivateMessageView | undefined;
if (combinedView) {
}
this.setState(this.state);
} else if (op == UserOperation.MarkPrivateMessageAsRead) {
- let data = wsJsonToRes<PrivateMessageResponse>(msg);
- let found = this.state.messages.find(
+ const data = wsJsonToRes<PrivateMessageResponse>(msg);
+ const found = this.state.messages.find(
m =>
m.private_message.id === data.private_message_view.private_message.id
);
if (found) {
- let combinedView = this.state.combined.find(
+ const combinedView = this.state.combined.find(
i =>
i.id == data.private_message_view.private_message.id &&
i.type_ == ReplyEnum.Message
op == UserOperation.DeleteComment ||
op == UserOperation.RemoveComment
) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
editCommentRes(data.comment_view, this.state.replies);
this.setState(this.state);
} else if (op == UserOperation.MarkCommentReplyAsRead) {
- let data = wsJsonToRes<CommentReplyResponse>(msg);
+ const data = wsJsonToRes<CommentReplyResponse>(msg);
- let found = this.state.replies.find(
+ const found = this.state.replies.find(
c => c.comment_reply.id == data.comment_reply_view.comment_reply.id
);
if (found) {
- let combinedView = this.state.combined.find(
+ const combinedView = this.state.combined.find(
i =>
i.id == data.comment_reply_view.comment_reply.id &&
i.type_ == ReplyEnum.Reply
this.sendUnreadCount(data.comment_reply_view.comment_reply.read);
this.setState(this.state);
} else if (op == UserOperation.MarkPersonMentionAsRead) {
- let data = wsJsonToRes<PersonMentionResponse>(msg);
+ const data = wsJsonToRes<PersonMentionResponse>(msg);
// TODO this might not be correct, it might need to use the comment id
- let found = this.state.mentions.find(
+ const found = this.state.mentions.find(
c => c.person_mention.id == data.person_mention_view.person_mention.id
);
if (found) {
- let combinedView = this.state.combined.find(
+ const combinedView = this.state.combined.find(
i =>
i.id == data.person_mention_view.person_mention.id &&
i.type_ == ReplyEnum.Mention
this.sendUnreadCount(data.person_mention_view.person_mention.read);
this.setState(this.state);
} else if (op == UserOperation.CreatePrivateMessage) {
- let data = wsJsonToRes<PrivateMessageResponse>(msg);
- let mui = UserService.Instance.myUserInfo;
+ const data = wsJsonToRes<PrivateMessageResponse>(msg);
+ const mui = UserService.Instance.myUserInfo;
if (
data.private_message_view.recipient.id == mui?.local_user_view.person.id
) {
this.setState(this.state);
}
} else if (op == UserOperation.SaveComment) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
saveCommentRes(data.comment_view, this.state.replies);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.CreateCommentLike) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
createCommentLikeRes(data.comment_view, this.state.replies);
this.setState(this.state);
} else if (op == UserOperation.BlockPerson) {
- let data = wsJsonToRes<BlockPersonResponse>(msg);
+ const data = wsJsonToRes<BlockPersonResponse>(msg);
updatePersonBlock(data);
} else if (op == UserOperation.CreatePostReport) {
- let data = wsJsonToRes<PostReportResponse>(msg);
+ const data = wsJsonToRes<PostReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
} else if (op == UserOperation.CreateCommentReport) {
- let data = wsJsonToRes<CommentReportResponse>(msg);
+ const data = wsJsonToRes<CommentReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
} else if (op == UserOperation.CreatePrivateMessageReport) {
- let data = wsJsonToRes<PrivateMessageReportResponse>(msg);
+ const data = wsJsonToRes<PrivateMessageReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
event.preventDefault();
i.setState({ loading: true });
- let password = i.state.form.password;
- let password_verify = i.state.form.password_verify;
+ const password = i.state.form.password;
+ const password_verify = i.state.form.password_verify;
if (password && password_verify) {
- let form: PasswordChangeAfterReset = {
+ const form: PasswordChangeAfterReset = {
token: i.state.form.token,
password,
password_verify,
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
this.setState({ loading: false });
return;
} else if (op == UserOperation.PasswordChangeAfterReset) {
- let data = wsJsonToRes<LoginResponse>(msg);
+ const data = wsJsonToRes<LoginResponse>(msg);
UserService.Instance.login(data);
this.props.history.push("/");
location.reload();
renderItemType(i: ItemType) {
switch (i.type_) {
case ItemEnum.Comment: {
- let c = i.view as CommentView;
+ const c = i.view as CommentView;
return (
<CommentNodes
key={i.id}
);
}
case ItemEnum.Post: {
- let p = i.view as PostView;
+ const p = i.view as PostView;
return (
<PostListing
key={i.id}
overview() {
let id = 0;
- let comments: ItemType[] = this.props.personRes.comments.map(r => ({
+ const comments: ItemType[] = this.props.personRes.comments.map(r => ({
id: id++,
type_: ItemEnum.Comment,
view: r,
published: r.comment.published,
score: r.counts.score,
}));
- let posts: ItemType[] = this.props.personRes.posts.map(r => ({
+ const posts: ItemType[] = this.props.personRes.posts.map(r => ({
id: id++,
type_: ItemEnum.Post,
view: r,
score: r.counts.score,
}));
- let combined = [...comments, ...posts];
+ const combined = [...comments, ...posts];
// Sort it
if (this.props.sort === "New") {
}
render() {
- let person = this.props.person;
- let local = person.local;
+ const person = this.props.person;
+ const local = person.local;
let apubName: string, link: string;
if (local) {
apubName = `@${person.name}`;
link = `/u/${person.name}`;
} else {
- let domain = hostname(person.actor_id);
+ const domain = hostname(person.actor_id);
apubName = `@${person.name}@${domain}`;
link = !this.props.realLink
? `/u/${person.name}@${domain}`
}
avatarAndName(displayName: string) {
- let avatar = this.props.person.avatar;
+ const avatar = this.props.person.avatar;
return (
<>
{avatar &&
}
get documentTitle(): string {
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
return mui
? `@${mui.local_user_view.person.name} ${i18n.t(
"registration_applications"
}
applicationList() {
- let res = this.state.listRegistrationApplicationsResponse;
+ const res = this.state.listRegistrationApplicationsResponse;
return (
res && (
<div>
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
- let promises: Promise<any>[] = [];
+ const promises: Promise<any>[] = [];
- let auth = req.auth;
+ const auth = req.auth;
if (auth) {
- let form: ListRegistrationApplications = {
+ const form: ListRegistrationApplications = {
unread_only: true,
page: 1,
limit: fetchLimit,
}
refetch() {
- let unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
- let auth = myAuth();
+ const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
+ const auth = myAuth();
if (auth) {
- let form: ListRegistrationApplications = {
+ const form: ListRegistrationApplications = {
unread_only: unread_only,
page: this.state.page,
limit: fetchLimit,
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
} else if (msg.reconnect) {
this.refetch();
} else if (op == UserOperation.ListRegistrationApplications) {
- let data = wsJsonToRes<ListRegistrationApplicationsResponse>(msg);
+ const data = wsJsonToRes<ListRegistrationApplicationsResponse>(msg);
this.setState({
listRegistrationApplicationsResponse: data,
loading: false,
});
window.scrollTo(0, 0);
} else if (op == UserOperation.ApproveRegistrationApplication) {
- let data = wsJsonToRes<RegistrationApplicationResponse>(msg);
+ const data = wsJsonToRes<RegistrationApplicationResponse>(msg);
updateRegistrationApplicationRes(
data.registration_application,
this.state.listRegistrationApplicationsResponse
?.registration_applications
);
- let uacs = UserService.Instance.unreadApplicationCountSub;
+ const uacs = UserService.Instance.unreadApplicationCountSub;
// Minor bug, where if the application switches from deny to approve, the count will still go down
uacs.next(uacs.getValue() - 1);
this.setState(this.state);
}
get documentTitle(): string {
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
return mui
? `@${mui.local_user_view.person.name} ${i18n.t("reports")} - ${
this.state.siteRes.site_view.site.name
// .map(r => r.comment_reports)
// .unwrapOr([])
// .map(r => this.commentReportToItemType(r));
- let comments =
+ const comments =
this.state.listCommentReportsResponse?.comment_reports.map(
this.commentReportToItemType
) ?? [];
- let posts =
+ const posts =
this.state.listPostReportsResponse?.post_reports.map(
this.postReportToItemType
) ?? [];
- let privateMessages =
+ const privateMessages =
this.state.listPrivateMessageReportsResponse?.private_message_reports.map(
this.privateMessageReportToItemType
) ?? [];
}
commentReports() {
- let reports = this.state.listCommentReportsResponse?.comment_reports;
+ const reports = this.state.listCommentReportsResponse?.comment_reports;
return (
reports && (
<div>
}
postReports() {
- let reports = this.state.listPostReportsResponse?.post_reports;
+ const reports = this.state.listPostReportsResponse?.post_reports;
return (
reports && (
<div>
}
privateMessageReports() {
- let reports =
+ const reports =
this.state.listPrivateMessageReportsResponse?.private_message_reports;
return (
reports && (
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
- let promises: Promise<any>[] = [];
+ const promises: Promise<any>[] = [];
- let unresolved_only = true;
- let page = 1;
- let limit = fetchLimit;
- let auth = req.auth;
+ const unresolved_only = true;
+ const page = 1;
+ const limit = fetchLimit;
+ const auth = req.auth;
if (auth) {
- let commentReportsForm: ListCommentReports = {
+ const commentReportsForm: ListCommentReports = {
unresolved_only,
page,
limit,
};
promises.push(req.client.listCommentReports(commentReportsForm));
- let postReportsForm: ListPostReports = {
+ const postReportsForm: ListPostReports = {
unresolved_only,
page,
limit,
promises.push(req.client.listPostReports(postReportsForm));
if (amAdmin()) {
- let privateMessageReportsForm: ListPrivateMessageReports = {
+ const privateMessageReportsForm: ListPrivateMessageReports = {
unresolved_only,
page,
limit,
}
refetch() {
- let unresolved_only = this.state.unreadOrAll == UnreadOrAll.Unread;
- let page = this.state.page;
- let limit = fetchLimit;
- let auth = myAuth();
+ const unresolved_only = this.state.unreadOrAll == UnreadOrAll.Unread;
+ const page = this.state.page;
+ const limit = fetchLimit;
+ const auth = myAuth();
if (auth) {
- let commentReportsForm: ListCommentReports = {
+ const commentReportsForm: ListCommentReports = {
unresolved_only,
page,
limit,
wsClient.listCommentReports(commentReportsForm)
);
- let postReportsForm: ListPostReports = {
+ const postReportsForm: ListPostReports = {
unresolved_only,
page,
limit,
WebSocketService.Instance.send(wsClient.listPostReports(postReportsForm));
if (amAdmin()) {
- let privateMessageReportsForm: ListPrivateMessageReports = {
+ const privateMessageReportsForm: ListPrivateMessageReports = {
unresolved_only,
page,
limit,
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
} else if (msg.reconnect) {
this.refetch();
} else if (op == UserOperation.ListCommentReports) {
- let data = wsJsonToRes<ListCommentReportsResponse>(msg);
+ const data = wsJsonToRes<ListCommentReportsResponse>(msg);
this.setState({ listCommentReportsResponse: data });
this.setState({ combined: this.buildCombined(), loading: false });
// this.sendUnreadCount();
window.scrollTo(0, 0);
setupTippy();
} else if (op == UserOperation.ListPostReports) {
- let data = wsJsonToRes<ListPostReportsResponse>(msg);
+ const data = wsJsonToRes<ListPostReportsResponse>(msg);
this.setState({ listPostReportsResponse: data });
this.setState({ combined: this.buildCombined(), loading: false });
// this.sendUnreadCount();
window.scrollTo(0, 0);
setupTippy();
} else if (op == UserOperation.ListPrivateMessageReports) {
- let data = wsJsonToRes<ListPrivateMessageReportsResponse>(msg);
+ const data = wsJsonToRes<ListPrivateMessageReportsResponse>(msg);
this.setState({ listPrivateMessageReportsResponse: data });
this.setState({ combined: this.buildCombined(), loading: false });
// this.sendUnreadCount();
window.scrollTo(0, 0);
setupTippy();
} else if (op == UserOperation.ResolvePostReport) {
- let data = wsJsonToRes<PostReportResponse>(msg);
+ const data = wsJsonToRes<PostReportResponse>(msg);
updatePostReportRes(
data.post_report_view,
this.state.listPostReportsResponse?.post_reports
);
- let urcs = UserService.Instance.unreadReportCountSub;
+ const urcs = UserService.Instance.unreadReportCountSub;
if (data.post_report_view.post_report.resolved) {
urcs.next(urcs.getValue() - 1);
} else {
}
this.setState(this.state);
} else if (op == UserOperation.ResolveCommentReport) {
- let data = wsJsonToRes<CommentReportResponse>(msg);
+ const data = wsJsonToRes<CommentReportResponse>(msg);
updateCommentReportRes(
data.comment_report_view,
this.state.listCommentReportsResponse?.comment_reports
);
- let urcs = UserService.Instance.unreadReportCountSub;
+ const urcs = UserService.Instance.unreadReportCountSub;
if (data.comment_report_view.comment_report.resolved) {
urcs.next(urcs.getValue() - 1);
} else {
}
this.setState(this.state);
} else if (op == UserOperation.ResolvePrivateMessageReport) {
- let data = wsJsonToRes<PrivateMessageReportResponse>(msg);
+ const data = wsJsonToRes<PrivateMessageReportResponse>(msg);
updatePrivateMessageReportRes(
data.private_message_report_view,
this.state.listPrivateMessageReportsResponse?.private_message_reports
);
- let urcs = UserService.Instance.unreadReportCountSub;
+ const urcs = UserService.Instance.unreadReportCountSub;
if (data.private_message_report_view.private_message_report.resolved) {
urcs.next(urcs.getValue() - 1);
} else {
}
saveUserSettingsHtmlForm() {
- let selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
+ const selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
return (
<>
}
totpSection() {
- let totpUrl =
+ const totpUrl =
UserService.Instance.myUserInfo?.local_user_view.local_user.totp_2fa_url;
return (
handleShowAvatarsChange(i: Settings, event: any) {
i.state.saveUserSettingsForm.show_avatars = event.target.checked;
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
mui.local_user_view.local_user.show_avatars = event.target.checked;
}
handleShowScoresChange(i: Settings, event: any) {
i.state.saveUserSettingsForm.show_scores = event.target.checked;
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
mui.local_user_view.local_user.show_scores = event.target.checked;
}
handleGenerateTotp(i: Settings, event: any) {
// Coerce false to undefined here, so it won't generate it.
- let checked: boolean | undefined = event.target.checked || undefined;
+ const checked: boolean | undefined = event.target.checked || undefined;
if (checked) {
toast(i18n.t("two_factor_setup_instructions"));
}
handleRemoveTotp(i: Settings, event: any) {
// Coerce true to undefined here, so it won't generate it.
- let checked: boolean | undefined = !event.target.checked && undefined;
+ const checked: boolean | undefined = !event.target.checked && undefined;
i.state.saveUserSettingsForm.generate_totp_2fa = checked;
i.setState(i.state);
}
handleSaveSettingsSubmit(i: Settings, event: any) {
event.preventDefault();
i.setState({ saveUserSettingsLoading: true });
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: SaveUserSettings = { ...i.state.saveUserSettingsForm, auth };
+ const form: SaveUserSettings = { ...i.state.saveUserSettingsForm, auth };
WebSocketService.Instance.send(wsClient.saveUserSettings(form));
}
}
handleChangePasswordSubmit(i: Settings, event: any) {
event.preventDefault();
i.setState({ changePasswordLoading: true });
- let auth = myAuth();
- let pForm = i.state.changePasswordForm;
- let new_password = pForm.new_password;
- let new_password_verify = pForm.new_password_verify;
- let old_password = pForm.old_password;
+ const auth = myAuth();
+ const pForm = i.state.changePasswordForm;
+ const new_password = pForm.new_password;
+ const new_password_verify = pForm.new_password_verify;
+ const old_password = pForm.old_password;
if (auth && new_password && old_password && new_password_verify) {
- let form: ChangePassword = {
+ const form: ChangePassword = {
new_password,
new_password_verify,
old_password,
handleDeleteAccount(i: Settings, event: any) {
event.preventDefault();
i.setState({ deleteAccountLoading: true });
- let auth = myAuth();
- let password = i.state.deleteAccountForm.password;
+ const auth = myAuth();
+ const password = i.state.deleteAccountForm.password;
if (auth && password) {
- let form: DeleteAccount = {
+ const form: DeleteAccount = {
password,
auth,
};
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
this.setState({
toast(i18n.t("saved"));
window.scrollTo(0, 0);
} else if (op == UserOperation.ChangePassword) {
- let data = wsJsonToRes<LoginResponse>(msg);
+ const data = wsJsonToRes<LoginResponse>(msg);
UserService.Instance.login(data);
this.setState({ changePasswordLoading: false });
window.scrollTo(0, 0);
UserService.Instance.logout();
window.location.href = "/";
} else if (op == UserOperation.BlockPerson) {
- let data = wsJsonToRes<BlockPersonResponse>(msg);
+ const data = wsJsonToRes<BlockPersonResponse>(msg);
updatePersonBlock(data);
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
this.setState({ personBlocks: mui.person_blocks });
}
} else if (op == UserOperation.BlockCommunity) {
- let data = wsJsonToRes<BlockCommunityResponse>(msg);
+ const data = wsJsonToRes<BlockCommunityResponse>(msg);
updateCommunityBlock(data);
- let mui = UserService.Instance.myUserInfo;
+ const mui = UserService.Instance.myUserInfo;
if (mui) {
this.setState({ communityBlocks: mui.community_blocks });
}
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
this.props.history.push("/");
return;
} else if (op == UserOperation.VerifyEmail) {
- let data = wsJsonToRes(msg);
+ const data = wsJsonToRes(msg);
if (data) {
toast(i18n.t("email_verified"));
this.props.history.push("/login");
}
render() {
- let post = this.props.post;
+ const post = this.props.post;
return (
<>
{!this.state.expanded && post.embed_title && post.url && (
}
render() {
- let firstLang = this.state.form.language_id;
- let selectedLangs = firstLang ? Array.of(firstLang) : undefined;
+ const firstLang = this.state.form.language_id;
+ const selectedLangs = firstLang ? Array.of(firstLang) : undefined;
- let url = this.state.form.url;
+ const url = this.state.form.url;
return (
<div>
<Prompt
i.setState(s => ((s.form.url = undefined), s));
}
- let pForm = i.state.form;
- let pv = i.props.post_view;
- let auth = myAuth();
+ const pForm = i.state.form;
+ const pv = i.props.post_view;
+ const auth = myAuth();
if (auth) {
if (pv) {
- let form: EditPost = {
+ const form: EditPost = {
name: pForm.name,
url: pForm.url,
body: pForm.body,
WebSocketService.Instance.send(wsClient.editPost(form));
} else {
if (pForm.name && pForm.community_id) {
- let form: CreatePost = {
+ const form: CreatePost = {
name: pForm.name,
community_id: pForm.community_id,
url: pForm.url,
}
copySuggestedTitle(i: PostForm) {
- let sTitle = i.state.suggestedTitle;
+ const sTitle = i.state.suggestedTitle;
if (sTitle) {
i.setState(
s => ((s.form.name = sTitle?.substring(0, MAX_POST_TITLE_LENGTH)), s)
);
i.setState({ suggestedTitle: undefined });
setTimeout(() => {
- let textarea: any = document.getElementById("post-title");
+ const textarea: any = document.getElementById("post-title");
autosize.update(textarea);
}, 10);
}
}
fetchPageTitle() {
- let url = this.state.form.url;
+ const url = this.state.form.url;
if (url && validURL(url)) {
- let form: Search = {
+ const form: Search = {
q: url,
type_: "Url",
sort: "TopAll",
}
fetchSimilarPosts() {
- let q = this.state.form.name;
+ const q = this.state.form.name;
if (q && q !== "") {
- let form: Search = {
+ const form: Search = {
q,
type_: "Posts",
sort: "TopAll",
}
handleImageUploadPaste(i: PostForm, event: any) {
- let image = event.clipboardData.files[0];
+ const image = event.clipboardData.files[0];
if (image) {
i.handleImageUpload(i, image);
}
}
parseMessage(msg: any) {
- let mui = UserService.Instance.myUserInfo;
- let op = wsUserOp(msg);
+ const mui = UserService.Instance.myUserInfo;
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
// Errors handled by top level pages
this.setState({ loading: false });
return;
} else if (op == UserOperation.CreatePost) {
- let data = wsJsonToRes<PostResponse>(msg);
+ const data = wsJsonToRes<PostResponse>(msg);
if (data.post_view.creator.id == mui?.local_user_view.person.id) {
this.props.onCreate?.(data.post_view);
}
} else if (op == UserOperation.EditPost) {
- let data = wsJsonToRes<PostResponse>(msg);
+ const data = wsJsonToRes<PostResponse>(msg);
if (data.post_view.creator.id == mui?.local_user_view.person.id) {
this.setState({ loading: false });
this.props.onEdit?.(data.post_view);
}
} else if (op == UserOperation.Search) {
- let data = wsJsonToRes<SearchResponse>(msg);
+ const data = wsJsonToRes<SearchResponse>(msg);
if (data.type_ == "Posts") {
this.setState({ suggestedPosts: data.posts });
}
body() {
- let body = this.props.post_view.post.body;
+ const body = this.props.post_view.post.body;
return body ? (
<div className="col-12 card my-2 p-2">
{this.state.viewSource ? (
}
get img() {
- let src = this.imageSrc;
+ const src = this.imageSrc;
return src ? (
<>
<div className="offset-sm-3 my-2 d-none d-sm-block">
}
imgThumb(src: string) {
- let post_view = this.props.post_view;
+ const post_view = this.props.post_view;
return (
<PictrsImage
src={src}
}
get imageSrc(): string | undefined {
- let post = this.props.post_view.post;
- let url = post.url;
- let thumbnail = post.thumbnail_url;
+ const post = this.props.post_view.post;
+ const url = post.url;
+ const thumbnail = post.thumbnail_url;
if (url && isImage(url)) {
if (url.includes("pictrs")) {
}
thumbnail() {
- let post = this.props.post_view.post;
- let url = post.url;
- let thumbnail = post.thumbnail_url;
+ const post = this.props.post_view.post;
+ const url = post.url;
+ const thumbnail = post.thumbnail_url;
if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
return (
}
createdLine() {
- let post_view = this.props.post_view;
- let url = post_view.post.url;
- let body = post_view.post.body;
+ const post_view = this.props.post_view;
+ const url = post_view.post.url;
+ const body = post_view.post.body;
return (
<ul className="list-inline mb-1 text-muted small">
<li className="list-inline-item">
}
get postLink() {
- let post = this.props.post_view.post;
+ const post = this.props.post_view.post;
return (
<Link
className={`d-inline-block ${
}
postTitleLine() {
- let post = this.props.post_view.post;
- let url = post.url;
+ const post = this.props.post_view.post;
+ const url = post.url;
return (
<div className="post-title overflow-hidden">
}
duplicatesLine() {
- let dupes = this.props.duplicates;
+ const dupes = this.props.duplicates;
return dupes && dupes.length > 0 ? (
<ul className="list-inline mb-1 small text-muted">
<>
}
commentsLine(mobile = false) {
- let post = this.props.post_view.post;
+ const post = this.props.post_view.post;
return (
<div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
postActions(mobile = false) {
// Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
// Possible enhancement: Make each button a component.
- let post_view = this.props.post_view;
+ const post_view = this.props.post_view;
return (
<>
{this.saveButton}
}
get commentsButton() {
- let post_view = this.props.post_view;
+ const post_view = this.props.post_view;
return (
<button className="btn btn-link text-muted py-0 pl-0">
<Link
}
get unreadCount(): number | undefined {
- let pv = this.props.post_view;
+ const pv = this.props.post_view;
return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
? undefined
: pv.unread_comments;
get mobileVotes() {
// TODO: make nicer
- let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
+ const tippy = showScores()
+ ? { "data-tippy-content": this.pointsTippy }
+ : {};
return (
<>
<div>
}
get saveButton() {
- let saved = this.props.post_view.saved;
- let label = saved ? i18n.t("unsave") : i18n.t("save");
+ const saved = this.props.post_view.saved;
+ const label = saved ? i18n.t("unsave") : i18n.t("save");
return (
<button
className="btn btn-link btn-animate text-muted py-0"
}
get deleteButton() {
- let deleted = this.props.post_view.post.deleted;
- let label = !deleted ? i18n.t("delete") : i18n.t("restore");
+ const deleted = this.props.post_view.post.deleted;
+ const label = !deleted ? i18n.t("delete") : i18n.t("restore");
return (
<button
className="btn btn-link btn-animate text-muted py-0"
}
get lockButton() {
- let locked = this.props.post_view.post.locked;
- let label = locked ? i18n.t("unlock") : i18n.t("lock");
+ const locked = this.props.post_view.post.locked;
+ const label = locked ? i18n.t("unlock") : i18n.t("lock");
return (
<button
className="btn btn-link btn-animate text-muted py-0"
}
get modRemoveButton() {
- let removed = this.props.post_view.post.removed;
+ const removed = this.props.post_view.post.removed;
return (
<button
className="btn btn-link btn-animate text-muted py-0"
*/
userActionsLine() {
// TODO: make nicer
- let post_view = this.props.post_view;
+ const post_view = this.props.post_view;
return (
this.state.showAdvanced && (
<>
}
removeAndBanDialogs() {
- let post = this.props.post_view;
- let purgeTypeText =
+ const post = this.props.post_view;
+ const purgeTypeText =
this.state.purgeType == PurgeType.Post
? i18n.t("purge_post")
: `${i18n.t("purge")} ${post.creator.name}`;
}
mobileThumbnail() {
- let post = this.props.post_view.post;
+ const post = this.props.post_view.post;
return post.thumbnail_url || (post.url && isImage(post.url)) ? (
<div className="row">
<div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
}
showMobilePreview() {
- let body = this.props.post_view.post.body;
+ const body = this.props.post_view.post.body;
return !this.showBody && body ? (
<div className="md-div mb-1 preview-lines">{body}</div>
) : (
this.context.router.history.push(`/login`);
}
- let myVote = this.state.my_vote;
- let newVote = myVote == 1 ? 0 : 1;
+ const myVote = this.state.my_vote;
+ const newVote = myVote == 1 ? 0 : 1;
if (myVote == 1) {
this.setState({
this.setState({ my_vote: newVote });
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: CreatePostLike = {
+ const form: CreatePostLike = {
post_id: this.props.post_view.post.id,
score: newVote,
auth,
this.context.router.history.push(`/login`);
}
- let myVote = this.state.my_vote;
- let newVote = myVote == -1 ? 0 : -1;
+ const myVote = this.state.my_vote;
+ const newVote = myVote == -1 ? 0 : -1;
if (myVote == 1) {
this.setState({
this.setState({ my_vote: newVote });
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: CreatePostLike = {
+ const form: CreatePostLike = {
post_id: this.props.post_view.post.id,
score: newVote,
auth,
handleReportSubmit(i: PostListing, event: any) {
event.preventDefault();
- let auth = myAuth();
- let reason = i.state.reportReason;
+ const auth = myAuth();
+ const reason = i.state.reportReason;
if (auth && reason) {
- let form: CreatePostReport = {
+ const form: CreatePostReport = {
post_id: i.props.post_view.post.id,
reason,
auth,
}
handleBlockUserClick(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let blockUserForm: BlockPerson = {
+ const blockUserForm: BlockPerson = {
person_id: i.props.post_view.creator.id,
block: true,
auth,
}
handleDeleteClick(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let deleteForm: DeletePost = {
+ const deleteForm: DeletePost = {
post_id: i.props.post_view.post.id,
deleted: !i.props.post_view.post.deleted,
auth,
}
handleSavePostClick(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let saved =
+ const saved =
i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
- let form: SavePost = {
+ const form: SavePost = {
post_id: i.props.post_view.post.id,
save: saved,
auth,
}
crossPostBody(): string | undefined {
- let post = this.props.post_view.post;
- let body = post.body;
+ const post = this.props.post_view.post;
+ const body = post.body;
return body
? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
handleModRemoveSubmit(i: PostListing, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: RemovePost = {
+ const form: RemovePost = {
post_id: i.props.post_view.post.id,
removed: !i.props.post_view.post.removed,
reason: i.state.removeReason,
}
handleModLock(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: LockPost = {
+ const form: LockPost = {
post_id: i.props.post_view.post.id,
locked: !i.props.post_view.post.locked,
auth,
}
handleModFeaturePostLocal(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: FeaturePost = {
+ const form: FeaturePost = {
post_id: i.props.post_view.post.id,
feature_type: "Local",
featured: !i.props.post_view.post.featured_local,
}
handleModFeaturePostCommunity(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: FeaturePost = {
+ const form: FeaturePost = {
post_id: i.props.post_view.post.id,
feature_type: "Community",
featured: !i.props.post_view.post.featured_community,
handlePurgeSubmit(i: PostListing, event: any) {
event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
if (i.state.purgeType == PurgeType.Person) {
- let form: PurgePerson = {
+ const form: PurgePerson = {
person_id: i.props.post_view.creator.id,
reason: i.state.purgeReason,
auth,
};
WebSocketService.Instance.send(wsClient.purgePerson(form));
} else if (i.state.purgeType == PurgeType.Post) {
- let form: PurgePost = {
+ const form: PurgePost = {
post_id: i.props.post_view.post.id,
reason: i.state.purgeReason,
auth,
handleModBanBothSubmit(i: PostListing, event?: any) {
if (event) event.preventDefault();
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let ban = !i.props.post_view.creator_banned_from_community;
- let person_id = i.props.post_view.creator.id;
- let remove_data = i.state.removeData;
- let reason = i.state.banReason;
- let expires = futureDaysToUnixTime(i.state.banExpireDays);
+ const ban = !i.props.post_view.creator_banned_from_community;
+ const person_id = i.props.post_view.creator.id;
+ const remove_data = i.state.removeData;
+ const reason = i.state.banReason;
+ const expires = futureDaysToUnixTime(i.state.banExpireDays);
if (i.state.banType == BanType.Community) {
// If its an unban, restore all their data
i.setState({ removeData: false });
}
- let form: BanFromCommunity = {
+ const form: BanFromCommunity = {
person_id,
community_id: i.props.post_view.community.id,
ban,
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
} else {
// If its an unban, restore all their data
- let ban = !i.props.post_view.creator.banned;
+ const ban = !i.props.post_view.creator.banned;
if (ban == false) {
i.setState({ removeData: false });
}
- let form: BanPerson = {
+ const form: BanPerson = {
person_id,
ban,
remove_data,
}
handleAddModToCommunity(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: AddModToCommunity = {
+ const form: AddModToCommunity = {
person_id: i.props.post_view.creator.id,
community_id: i.props.post_view.community.id,
added: !i.creatorIsMod_,
}
handleAddAdmin(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: AddAdmin = {
+ const form: AddAdmin = {
person_id: i.props.post_view.creator.id,
added: !i.creatorIsAdmin_,
auth,
}
handleTransferCommunity(i: PostListing) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: TransferCommunity = {
+ const form: TransferCommunity = {
community_id: i.props.post_view.community.id,
person_id: i.props.post_view.creator.id,
auth,
}
get pointsTippy(): string {
- let points = i18n.t("number_of_points", {
+ const points = i18n.t("number_of_points", {
count: Number(this.state.score),
formattedCount: Number(this.state.score),
});
- let upvotes = i18n.t("number_of_upvotes", {
+ const upvotes = i18n.t("number_of_upvotes", {
count: Number(this.state.upvotes),
formattedCount: Number(this.state.upvotes),
});
- let downvotes = i18n.t("number_of_downvotes", {
+ const downvotes = i18n.t("number_of_downvotes", {
count: Number(this.state.downvotes),
formattedCount: Number(this.state.downvotes),
});
removeDuplicates(): PostView[] {
// Must use a spread to clone the props, because splice will fail below otherwise.
- let posts = [...this.props.posts];
+ const posts = [...this.props.posts];
// A map from post url to list of posts (dupes)
- let urlMap = new Map<string, PostView[]>();
+ const urlMap = new Map<string, PostView[]>();
// Loop over the posts, find ones with same urls
- for (let pv of posts) {
- let url = pv.post.url;
+ for (const pv of posts) {
+ const url = pv.post.url;
if (
!pv.post.deleted &&
!pv.post.removed &&
// Sort by oldest
// Remove the ones that have no length
- for (let e of urlMap.entries()) {
+ for (const e of urlMap.entries()) {
if (e[1].length == 1) {
urlMap.delete(e[0]);
} else {
}
for (let i = 0; i < posts.length; i++) {
- let pv = posts[i];
- let url = pv.post.url;
+ const pv = posts[i];
+ const url = pv.post.url;
if (url) {
- let found = urlMap.get(url);
+ const found = urlMap.get(url);
if (found) {
// If its the oldest, add
if (pv.post.id == found[0].post.id) {
}
render() {
- let r = this.props.report;
- let resolver = r.resolver;
- let post = r.post;
- let tippyContent = i18n.t(
+ const r = this.props.report;
+ const resolver = r.resolver;
+ const post = r.post;
+ const tippyContent = i18n.t(
r.post_report.resolved ? "unresolve_report" : "resolve_report"
);
post.name = r.post_report.original_post_name;
post.url = r.post_report.original_post_url;
post.body = r.post_report.original_post_body;
- let pv: PostView = {
+ const pv: PostView = {
post,
creator: r.post_creator,
community: r.community,
}
handleResolveReport(i: PostReport) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: ResolvePostReport = {
+ const form: ResolvePostReport = {
report_id: i.props.report.post_report.id,
resolved: !i.props.report.post_report.resolved,
auth,
}
fetchPost() {
- let auth = myAuth(false);
- let postForm: GetPost = {
+ const auth = myAuth(false);
+ const postForm: GetPost = {
id: this.state.postId,
comment_id: this.state.commentId,
auth,
};
WebSocketService.Instance.send(wsClient.getPost(postForm));
- let commentsForm: GetComments = {
+ const commentsForm: GetComments = {
post_id: this.state.postId,
parent_id: this.state.commentId,
max_depth: commentTreeMaxDepth,
}
fetchCrossPosts() {
- let q = this.state.postRes?.post_view.post.url;
+ const q = this.state.postRes?.post_view.post.url;
if (q) {
- let form: Search = {
+ const form: Search = {
q,
type_: "Url",
sort: "TopAll",
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
- let pathSplit = req.path.split("/");
- let promises: Promise<any>[] = [];
+ const pathSplit = req.path.split("/");
+ const promises: Promise<any>[] = [];
- let pathType = pathSplit.at(1);
- let id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined;
- let auth = req.auth;
+ const pathType = pathSplit.at(1);
+ const id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined;
+ const auth = req.auth;
- let postForm: GetPost = {
+ const postForm: GetPost = {
auth,
};
- let commentsForm: GetComments = {
+ const commentsForm: GetComments = {
max_depth: commentTreeMaxDepth,
sort: "Hot",
type_: "All",
};
get documentTitle(): string {
- let name_ = this.state.postRes?.post_view.post.name;
- let siteName = this.state.siteRes.site_view.site.name;
+ const name_ = this.state.postRes?.post_view.post.name;
+ const siteName = this.state.siteRes.site_view.site.name;
return name_ ? `${name_} - ${siteName}` : "";
}
get imageTag(): string | undefined {
- let post = this.state.postRes?.post_view.post;
- let thumbnail = post?.thumbnail_url;
- let url = post?.url;
+ const post = this.state.postRes?.post_view.post;
+ const thumbnail = post?.thumbnail_url;
+ const url = post?.url;
return thumbnail || (url && isImage(url) ? url : undefined);
}
render() {
- let res = this.state.postRes;
- let description = res?.post_view.post.body;
+ const res = this.state.postRes;
+ const description = res?.post_view.post.body;
return (
<div className="container-lg">
{this.state.loading ? (
commentsFlat() {
// These are already sorted by new
- let commentsRes = this.state.commentsRes;
- let postRes = this.state.postRes;
+ const commentsRes = this.state.commentsRes;
+ const postRes = this.state.postRes;
return (
commentsRes &&
postRes && (
}
sidebar() {
- let res = this.state.postRes;
+ const res = this.state.postRes;
return (
res && (
<div className="mb-3">
}
handleCommentViewTypeChange(i: Post, event: any) {
- let comments = i.state.commentsRes?.comments;
+ const comments = i.state.commentsRes?.comments;
if (comments) {
i.setState({
commentViewType: Number(event.target.value),
}
handleViewPost(i: Post) {
- let id = i.state.postRes?.post_view.post.id;
+ const id = i.state.postRes?.post_view.post.id;
if (id) {
i.context.router.history.push(`/post/${id}`);
}
}
handleViewContext(i: Post) {
- let parentId = getCommentParentId(
+ const parentId = getCommentParentId(
i.state.commentsRes?.comments?.at(0)?.comment
);
if (parentId) {
}
commentsTree() {
- let res = this.state.postRes;
- let firstComment = this.state.commentTree.at(0)?.comment_view.comment;
- let depth = getDepthFromComment(firstComment);
- let showContextButton = depth ? depth > 0 : false;
+ const res = this.state.postRes;
+ const firstComment = this.state.commentTree.at(0)?.comment_view.comment;
+ const depth = getDepthFromComment(firstComment);
+ const showContextButton = depth ? depth > 0 : false;
return (
res && (
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
return;
} else if (msg.reconnect) {
- let post_id = this.state.postRes?.post_view.post.id;
+ const post_id = this.state.postRes?.post_view.post.id;
if (post_id) {
WebSocketService.Instance.send(wsClient.postJoin({ post_id }));
WebSocketService.Instance.send(
);
}
} else if (op == UserOperation.GetPost) {
- let data = wsJsonToRes<GetPostResponse>(msg);
+ const data = wsJsonToRes<GetPostResponse>(msg);
this.setState({ postRes: data });
// join the rooms
this.scrollIntoCommentSection();
}
} else if (op == UserOperation.GetComments) {
- let data = wsJsonToRes<GetCommentsResponse>(msg);
+ const data = wsJsonToRes<GetCommentsResponse>(msg);
// This section sets the comments res
- let comments = this.state.commentsRes?.comments;
+ const comments = this.state.commentsRes?.comments;
if (comments) {
// You might need to append here, since this could be building more comments from a tree fetch
// Remove the first comment, since it is the parent
- let newComments = data.comments;
+ const newComments = data.comments;
newComments.shift();
comments.push(...newComments);
} else {
this.setState({ commentsRes: data });
}
- let cComments = this.state.commentsRes?.comments ?? [];
+ const cComments = this.state.commentsRes?.comments ?? [];
this.setState({
commentTree: buildCommentsTree(cComments, !!this.state.commentId),
loading: false,
});
} else if (op == UserOperation.CreateComment) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
// Don't get comments from the post room, if the creator is blocked
- let creatorBlocked = UserService.Instance.myUserInfo?.person_blocks
+ const creatorBlocked = UserService.Instance.myUserInfo?.person_blocks
.map(pb => pb.target.id)
.includes(data.comment_view.creator.id);
// Necessary since it might be a user reply, which has the recipients, to avoid double
- let postRes = this.state.postRes;
- let commentsRes = this.state.commentsRes;
+ const postRes = this.state.postRes;
+ const commentsRes = this.state.commentsRes;
if (
data.recipient_ids.length == 0 &&
!creatorBlocked &&
op == UserOperation.DeleteComment ||
op == UserOperation.RemoveComment
) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
editCommentRes(data.comment_view, this.state.commentsRes?.comments);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.SaveComment) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
saveCommentRes(data.comment_view, this.state.commentsRes?.comments);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.CreateCommentLike) {
- let data = wsJsonToRes<CommentResponse>(msg);
+ const data = wsJsonToRes<CommentResponse>(msg);
createCommentLikeRes(data.comment_view, this.state.commentsRes?.comments);
this.setState(this.state);
} else if (op == UserOperation.CreatePostLike) {
- let data = wsJsonToRes<PostResponse>(msg);
+ const data = wsJsonToRes<PostResponse>(msg);
createPostLikeRes(data.post_view, this.state.postRes?.post_view);
this.setState(this.state);
} else if (
op == UserOperation.FeaturePost ||
op == UserOperation.SavePost
) {
- let data = wsJsonToRes<PostResponse>(msg);
- let res = this.state.postRes;
+ const data = wsJsonToRes<PostResponse>(msg);
+ const res = this.state.postRes;
if (res) {
res.post_view = data.post_view;
this.setState(this.state);
op == UserOperation.RemoveCommunity ||
op == UserOperation.FollowCommunity
) {
- let data = wsJsonToRes<CommunityResponse>(msg);
- let res = this.state.postRes;
+ const data = wsJsonToRes<CommunityResponse>(msg);
+ const res = this.state.postRes;
if (res) {
res.community_view = data.community_view;
res.post_view.community = data.community_view.community;
this.setState(this.state);
}
} else if (op == UserOperation.BanFromCommunity) {
- let data = wsJsonToRes<BanFromCommunityResponse>(msg);
+ const data = wsJsonToRes<BanFromCommunityResponse>(msg);
- let res = this.state.postRes;
+ const res = this.state.postRes;
if (res) {
if (res.post_view.creator.id == data.person_view.person.id) {
res.post_view.creator_banned_from_community = data.banned;
.forEach(c => (c.creator_banned_from_community = data.banned));
this.setState(this.state);
} else if (op == UserOperation.AddModToCommunity) {
- let data = wsJsonToRes<AddModToCommunityResponse>(msg);
- let res = this.state.postRes;
+ const data = wsJsonToRes<AddModToCommunityResponse>(msg);
+ const res = this.state.postRes;
if (res) {
res.moderators = data.moderators;
this.setState(this.state);
}
} else if (op == UserOperation.BanPerson) {
- let data = wsJsonToRes<BanPersonResponse>(msg);
+ const data = wsJsonToRes<BanPersonResponse>(msg);
this.state.commentsRes?.comments
.filter(c => c.creator.id == data.person_view.person.id)
.forEach(c => (c.creator.banned = data.banned));
- let res = this.state.postRes;
+ const res = this.state.postRes;
if (res) {
if (res.post_view.creator.id == data.person_view.person.id) {
res.post_view.creator.banned = data.banned;
}
this.setState(this.state);
} else if (op == UserOperation.AddAdmin) {
- let data = wsJsonToRes<AddAdminResponse>(msg);
+ const data = wsJsonToRes<AddAdminResponse>(msg);
this.setState(s => ((s.siteRes.admins = data.admins), s));
} else if (op == UserOperation.Search) {
- let data = wsJsonToRes<SearchResponse>(msg);
- let xPosts = data.posts.filter(
+ const data = wsJsonToRes<SearchResponse>(msg);
+ const xPosts = data.posts.filter(
p => p.post.ap_id != this.state.postRes?.post_view.post.ap_id
);
this.setState({ crossPosts: xPosts.length > 0 ? xPosts : undefined });
} else if (op == UserOperation.LeaveAdmin) {
- let data = wsJsonToRes<GetSiteResponse>(msg);
+ const data = wsJsonToRes<GetSiteResponse>(msg);
this.setState({ siteRes: data });
} else if (op == UserOperation.TransferCommunity) {
- let data = wsJsonToRes<GetCommunityResponse>(msg);
- let res = this.state.postRes;
+ const data = wsJsonToRes<GetCommunityResponse>(msg);
+ const res = this.state.postRes;
if (res) {
res.community_view = data.community_view;
res.post_view.community = data.community_view.community;
this.setState(this.state);
}
} else if (op == UserOperation.BlockPerson) {
- let data = wsJsonToRes<BlockPersonResponse>(msg);
+ const data = wsJsonToRes<BlockPersonResponse>(msg);
updatePersonBlock(data);
} else if (op == UserOperation.CreatePostReport) {
- let data = wsJsonToRes<PostReportResponse>(msg);
+ const data = wsJsonToRes<PostReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
} else if (op == UserOperation.CreateCommentReport) {
- let data = wsJsonToRes<CommentReportResponse>(msg);
+ const data = wsJsonToRes<CommentReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
op == UserOperation.PurgeComment ||
op == UserOperation.PurgeCommunity
) {
- let data = wsJsonToRes<PurgeItemResponse>(msg);
+ const data = wsJsonToRes<PurgeItemResponse>(msg);
if (data.success) {
toast(i18n.t("purge_success"));
this.context.router.history.push(`/`);
}
fetchPersonDetails() {
- let form: GetPersonDetails = {
+ const form: GetPersonDetails = {
person_id: this.state.recipient_id,
sort: "New",
saved_only: false,
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
- let person_id = Number(req.path.split("/").pop());
- let form: GetPersonDetails = {
+ const person_id = Number(req.path.split("/").pop());
+ const form: GetPersonDetails = {
person_id,
sort: "New",
saved_only: false,
}
get documentTitle(): string {
- let name_ = this.state.recipientDetailsRes?.person_view.person.name;
+ const name_ = this.state.recipientDetailsRes?.person_view.person.name;
return name_ ? `${i18n.t("create_private_message")} - ${name_}` : "";
}
}
render() {
- let res = this.state.recipientDetailsRes;
+ const res = this.state.recipientDetailsRes;
return (
<div className="container-lg">
<HtmlTags
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
this.setState({ loading: false });
return;
} else if (op == UserOperation.GetPersonDetails) {
- let data = wsJsonToRes<GetPersonDetailsResponse>(msg);
+ const data = wsJsonToRes<GetPersonDetailsResponse>(msg);
this.setState({ recipientDetailsRes: data, loading: false });
}
}
handlePrivateMessageSubmit(i: PrivateMessageForm, event: any) {
event.preventDefault();
- let pm = i.props.privateMessageView;
- let auth = myAuth();
- let content = i.state.content;
+ const pm = i.props.privateMessageView;
+ const auth = myAuth();
+ const content = i.state.content;
if (auth && content) {
if (pm) {
- let form: EditPrivateMessage = {
+ const form: EditPrivateMessage = {
private_message_id: pm.private_message.id,
content,
auth,
};
WebSocketService.Instance.send(wsClient.editPrivateMessage(form));
} else {
- let form: CreatePrivateMessage = {
+ const form: CreatePrivateMessage = {
content,
recipient_id: i.props.recipient.id,
auth,
}
parseMessage(msg: any) {
- let op = wsUserOp(msg);
+ const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
op == UserOperation.DeletePrivateMessage ||
op == UserOperation.MarkPrivateMessageAsRead
) {
- let data = wsJsonToRes<PrivateMessageResponse>(msg);
+ const data = wsJsonToRes<PrivateMessageResponse>(msg);
this.setState({ loading: false });
this.props.onEdit?.(data.private_message_view);
} else if (op == UserOperation.CreatePrivateMessage) {
- let data = wsJsonToRes<PrivateMessageResponse>(msg);
+ const data = wsJsonToRes<PrivateMessageResponse>(msg);
this.props.onCreate?.(data.private_message_view);
}
}
}
render() {
- let r = this.props.report;
- let pmr = r.private_message_report;
- let tippyContent = i18n.t(
+ const r = this.props.report;
+ const pmr = r.private_message_report;
+ const tippyContent = i18n.t(
r.private_message_report.resolved ? "unresolve_report" : "resolve_report"
);
}
handleResolveReport(i: PrivateMessageReport) {
- let pmr = i.props.report.private_message_report;
- let auth = myAuth();
+ const pmr = i.props.report.private_message_report;
+ const auth = myAuth();
if (auth) {
- let form: ResolvePrivateMessageReport = {
+ const form: ResolvePrivateMessageReport = {
report_id: pmr.id,
resolved: !pmr.resolved,
auth,
}
render() {
- let message_view = this.props.private_message_view;
- let otherPerson: Person = this.mine
+ const message_view = this.props.private_message_view;
+ const otherPerson: Person = this.mine
? message_view.recipient
: message_view.creator;
}
get messageUnlessRemoved(): string {
- let message = this.props.private_message_view.private_message;
+ const message = this.props.private_message_view.private_message;
return message.deleted ? `*${i18n.t("deleted")}*` : message.content;
}
}
handleDeleteClick(i: PrivateMessage) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: DeletePrivateMessage = {
+ const form: DeletePrivateMessage = {
private_message_id: i.props.private_message_view.private_message.id,
deleted: !i.props.private_message_view.private_message.deleted,
auth,
}
handleMarkRead(i: PrivateMessage) {
- let auth = myAuth();
+ const auth = myAuth();
if (auth) {
- let form: MarkPrivateMessageAsRead = {
+ const form: MarkPrivateMessageAsRead = {
private_message_id: i.props.private_message_view.private_message.id,
read: !i.props.private_message_view.private_message.read,
auth,
handleReportSubmit(i: PrivateMessage, event: any) {
event.preventDefault();
- let auth = myAuth();
- let reason = i.state.reportReason;
+ const auth = myAuth();
+ const reason = i.state.reportReason;
if (auth && reason) {
- let form: CreatePrivateMessageReport = {
+ const form: CreatePrivateMessageReport = {
private_message_id: i.props.private_message_view.private_message.id,
reason,
auth,
}
public login(res: LoginResponse) {
- let expires = new Date();
+ const expires = new Date();
expires.setDate(expires.getDate() + 365);
if (res.jwt) {
toast(i18n.t("logged_in"));
}
public auth(throwErr = true): string | undefined {
- let jwt = this.jwtInfo?.jwt;
+ const jwt = this.jwtInfo?.jwt;
if (jwt) {
return jwt;
} else {
- let msg = "No JWT cookie found";
+ const msg = "No JWT cookie found";
if (throwErr && isBrowser()) {
console.error(msg);
toast(i18n.t("not_logged_in"), "danger");
}
private setJwtInfo() {
- let jwt: string | undefined = IsomorphicCookie.load("jwt");
+ const jwt: string | undefined = IsomorphicCookie.load("jwt");
if (jwt) {
this.jwtInfo = { jwt, claims: jwt_decode(jwt) };
console.log(`Connected to ${getWsUri()}`);
if (!firstConnect) {
- let res = {
+ const res = {
reconnect: true,
};
obs.next(res);
adminMatrixIds?: string[];
}
-let customEmojis: EmojiMartCategory[] = [];
+const customEmojis: EmojiMartCategory[] = [];
export let customEmojisLookup: Map<string, CustomEmojiView> = new Map<
string,
CustomEmojiView
export function hotRank(score: number, timeStr: string): number {
// Rank = ScaleFactor * sign(Score) * log(1 + abs(Score)) / (Time + 2)^Gravity
- let date: Date = new Date(timeStr + "Z"); // Add Z to convert from UTC date
- let now: Date = new Date();
- let hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5;
+ const date: Date = new Date(timeStr + "Z"); // Add Z to convert from UTC date
+ const now: Date = new Date();
+ const hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5;
- let rank =
+ const rank =
(10000 * Math.log10(Math.max(1, 3 + Number(score)))) /
Math.pow(hoursElapsed + 2, 1.8);
.concat(mods?.map(m => m.moderator.id) ?? []) ?? [];
if (myUserInfo) {
- let myIndex = adminsThenMods.findIndex(
+ const myIndex = adminsThenMods.findIndex(
id => id == myUserInfo.local_user_view.person.id
);
if (myIndex == -1) {
mods?: CommunityModeratorView[],
myUserInfo = UserService.Instance.myUserInfo
): boolean {
- let myId = myUserInfo?.local_user_view.person.id;
+ const myId = myUserInfo?.local_user_view.person.id;
// Don't allow mod actions on yourself
return myId == mods?.at(0)?.moderator.id && myId != creator_id;
}
admins?: PersonView[],
myUserInfo = UserService.Instance.myUserInfo
): boolean {
- let myId = myUserInfo?.local_user_view.person.id;
+ const myId = myUserInfo?.local_user_view.person.id;
return myId == admins?.at(0)?.person.id && myId != creator_id;
}
}
export function communityRSSUrl(actorId: string, sort: string): string {
- let url = new URL(actorId);
+ const url = new URL(actorId);
return `${url.origin}/feeds${url.pathname}.xml?sort=${sort}`;
}
export function validEmail(email: string) {
- let re =
+ const re =
/^(([^\s"(),.:;<>@[\\\]]+(\.[^\s"(),.:;<>@[\\\]]+)*)|(".+"))@((\[(?:\d{1,3}\.){3}\d{1,3}])|(([\dA-Za-z\-]+\.)+[A-Za-z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
}
export async function getSiteMetadata(url: string) {
- let form: GetSiteMetadata = { url };
- let client = new LemmyHttp(getHttpBase());
+ const form: GetSiteMetadata = { url };
+ const client = new LemmyHttp(getHttpBase());
return client.getSiteMetadata(form);
}
override?: string,
myUserInfo = UserService.Instance.myUserInfo
): string[] {
- let myLang = myUserInfo?.local_user_view.local_user.interface_language;
- let lang = override || myLang || "browser";
+ const myLang = myUserInfo?.local_user_view.local_user.interface_language;
+ const lang = override || myLang || "browser";
if (lang == "browser" && isBrowser()) {
return getBrowserLanguages();
function getBrowserLanguages(): string[] {
// Intersect lemmy's langs, with the browser langs
- let langs = languages ? languages.map(l => l.code) : ["en"];
+ const langs = languages ? languages.map(l => l.code) : ["en"];
// NOTE, mobile browsers seem to be missing this list, so append en
- let allowedLangs = navigator.languages
+ const allowedLangs = navigator.languages
.concat("en")
.filter(v => langs.includes(v));
return allowedLangs;
theme = "darkly";
}
- let themeList = await fetchThemeList();
+ const themeList = await fetchThemeList();
// Unload all the other themes
for (var i = 0; i < themeList.length; i++) {
- let styleSheet = document.getElementById(themeList[i]);
+ const styleSheet = document.getElementById(themeList[i]);
if (styleSheet) {
styleSheet.setAttribute("disabled", "disabled");
}
document.getElementById("default-dark")?.setAttribute("disabled", "disabled");
// Load the theme dynamically
- let cssLoc = `/css/themes/${theme}.css`;
+ const cssLoc = `/css/themes/${theme}.css`;
loadCss(theme, cssLoc);
document.getElementById(theme)?.removeAttribute("disabled");
export function messageToastify(info: NotifyInfo, router: any) {
if (isBrowser()) {
- let htmlBody = info.body ? md.render(info.body) : "";
- let backgroundColor = `var(--light)`;
+ const htmlBody = info.body ? md.render(info.body) : "";
+ const backgroundColor = `var(--light)`;
- let toast = Toastify({
+ const toast = Toastify({
text: `${htmlBody}<br />${info.name}`,
avatar: info.icon,
backgroundColor: backgroundColor,
}
export function notifyPost(post_view: PostView, router: any) {
- let info: NotifyInfo = {
+ const info: NotifyInfo = {
name: post_view.community.name,
icon: post_view.community.icon,
link: `/post/${post_view.post.id}`,
}
export function notifyComment(comment_view: CommentView, router: any) {
- let info: NotifyInfo = {
+ const info: NotifyInfo = {
name: comment_view.creator.name,
icon: comment_view.creator.avatar,
link: `/comment/${comment_view.comment.id}`,
}
export function notifyPrivateMessage(pmv: PrivateMessageView, router: any) {
- let info: NotifyInfo = {
+ const info: NotifyInfo = {
name: pmv.creator.name,
icon: pmv.creator.avatar,
link: `/inbox`,
{
trigger: ":",
menuItemTemplate: (item: any) => {
- let shortName = `:${item.original.key}:`;
+ const shortName = `:${item.original.key}:`;
return `${item.original.val} ${shortName}`;
},
selectTemplate: (item: any) => {
- let customEmoji = customEmojisLookup.get(
+ const customEmoji = customEmojisLookup.get(
item.original.key
)?.custom_emoji;
if (customEmoji == undefined) return `${item.original.val}`;
{
trigger: "@",
selectTemplate: (item: any) => {
- let it: PersonTribute = item.original;
+ const it: PersonTribute = item.original;
return `[${it.key}](${it.view.person.actor_id})`;
},
values: debounce(async (text: string, cb: any) => {
{
trigger: "!",
selectTemplate: (item: any) => {
- let it: CommunityTribute = item.original;
+ const it: CommunityTribute = item.original;
return `[${it.key}](${it.view.community.actor_id})`;
},
values: debounce(async (text: string, cb: any) => {
}
function setupEmojiDataModel(custom_emoji_views: CustomEmojiView[]) {
- let groupedEmojis = groupBy(custom_emoji_views, x => x.custom_emoji.category);
+ const groupedEmojis = groupBy(
+ custom_emoji_views,
+ x => x.custom_emoji.category
+ );
for (const [category, emojis] of Object.entries(groupedEmojis)) {
customEmojis.push({
id: category,
keywords: custom_emoji_view.keywords.map(x => x.keyword),
skins: [{ src: custom_emoji_view.custom_emoji.image_url }],
};
- let categoryIndex = customEmojis.findIndex(
+ const categoryIndex = customEmojis.findIndex(
x => x.id == custom_emoji_view.custom_emoji.category
);
if (categoryIndex == -1) {
emojis: [emoji],
});
} else {
- let emojiIndex = customEmojis[categoryIndex].emojis.findIndex(
+ const emojiIndex = customEmojis[categoryIndex].emojis.findIndex(
x => x.id == custom_emoji_view.custom_emoji.shortcode
);
if (emojiIndex == -1) {
export function removeFromEmojiDataModel(id: number) {
let view: CustomEmojiView | undefined;
- for (let item of customEmojisLookup.values()) {
+ for (const item of customEmojisLookup.values()) {
if (item.custom_emoji.id === id) {
view = item;
break;
}
async function personSearch(text: string): Promise<PersonTribute[]> {
- let users = (await fetchUsers(text)).users;
- let persons: PersonTribute[] = users.map(pv => {
- let tribute: PersonTribute = {
+ const users = (await fetchUsers(text)).users;
+ const persons: PersonTribute[] = users.map(pv => {
+ const tribute: PersonTribute = {
key: `@${pv.person.name}@${hostname(pv.person.actor_id)}`,
view: pv,
};
}
async function communitySearch(text: string): Promise<CommunityTribute[]> {
- let comms = (await fetchCommunities(text)).communities;
- let communities: CommunityTribute[] = comms.map(cv => {
- let tribute: CommunityTribute = {
+ const comms = (await fetchCommunities(text)).communities;
+ const communities: CommunityTribute[] = comms.map(cv => {
+ const tribute: CommunityTribute = {
key: `!${cv.community.name}@${hostname(cv.community.actor_id)}`,
view: cv,
};
}
export function getIdFromProps(props: any): number | undefined {
- let id = props.match.params.post_id;
+ const id = props.match.params.post_id;
return id ? Number(id) : undefined;
}
export function getCommentIdFromProps(props: any): number | undefined {
- let id = props.match.params.comment_id;
+ const id = props.match.params.comment_id;
return id ? Number(id) : undefined;
}
export function editCommentRes(data: CommentView, comments?: CommentView[]) {
- let found = comments?.find(c => c.comment.id == data.comment.id);
+ const found = comments?.find(c => c.comment.id == data.comment.id);
if (found) {
found.comment.content = data.comment.content;
found.comment.distinguished = data.comment.distinguished;
}
export function saveCommentRes(data: CommentView, comments?: CommentView[]) {
- let found = comments?.find(c => c.comment.id == data.comment.id);
+ const found = comments?.find(c => c.comment.id == data.comment.id);
if (found) {
found.saved = data.saved;
}
data: BlockPersonResponse,
myUserInfo: MyUserInfo | undefined = UserService.Instance.myUserInfo
) {
- let mui = myUserInfo;
+ const mui = myUserInfo;
if (mui) {
if (data.blocked) {
mui.person_blocks.push({
data: BlockCommunityResponse,
myUserInfo: MyUserInfo | undefined = UserService.Instance.myUserInfo
) {
- let mui = myUserInfo;
+ const mui = myUserInfo;
if (mui) {
if (data.blocked) {
mui.community_blocks.push({
data: CommentView,
comments?: CommentView[]
) {
- let found = comments?.find(c => c.comment.id === data.comment.id);
+ const found = comments?.find(c => c.comment.id === data.comment.id);
if (found) {
found.counts.score = data.counts.score;
found.counts.upvotes = data.counts.upvotes;
}
export function createPostLikeFindRes(data: PostView, posts?: PostView[]) {
- let found = posts?.find(p => p.post.id == data.post.id);
+ const found = posts?.find(p => p.post.id == data.post.id);
if (found) {
createPostLikeRes(data, found);
}
}
export function editPostFindRes(data: PostView, posts?: PostView[]) {
- let found = posts?.find(p => p.post.id == data.post.id);
+ const found = posts?.find(p => p.post.id == data.post.id);
if (found) {
editPostRes(data, found);
}
data: PostReportView,
reports?: PostReportView[]
) {
- let found = reports?.find(p => p.post_report.id == data.post_report.id);
+ const found = reports?.find(p => p.post_report.id == data.post_report.id);
if (found) {
found.post_report = data.post_report;
}
data: CommentReportView,
reports?: CommentReportView[]
) {
- let found = reports?.find(c => c.comment_report.id == data.comment_report.id);
+ const found = reports?.find(
+ c => c.comment_report.id == data.comment_report.id
+ );
if (found) {
found.comment_report = data.comment_report;
}
data: PrivateMessageReportView,
reports?: PrivateMessageReportView[]
) {
- let found = reports?.find(
+ const found = reports?.find(
c => c.private_message_report.id == data.private_message_report.id
);
if (found) {
data: RegistrationApplicationView,
applications?: RegistrationApplicationView[]
) {
- let found = applications?.find(
+ const found = applications?.find(
ra => ra.registration_application.id == data.registration_application.id
);
if (found) {
}
export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] {
- let nodes: CommentNodeI[] = [];
- for (let comment of comments) {
+ const nodes: CommentNodeI[] = [];
+ for (const comment of comments) {
nodes.push({ comment_view: comment, children: [], depth: 0 });
}
return nodes;
comments: CommentView[],
parentComment: boolean
): CommentNodeI[] {
- let map = new Map<number, CommentNodeI>();
- let depthOffset = !parentComment
+ const map = new Map<number, CommentNodeI>();
+ const depthOffset = !parentComment
? 0
: getDepthFromComment(comments[0].comment) ?? 0;
- for (let comment_view of comments) {
- let depthI = getDepthFromComment(comment_view.comment) ?? 0;
- let depth = depthI ? depthI - depthOffset : 0;
- let node: CommentNodeI = {
+ for (const comment_view of comments) {
+ const depthI = getDepthFromComment(comment_view.comment) ?? 0;
+ const depth = depthI ? depthI - depthOffset : 0;
+ const node: CommentNodeI = {
comment_view,
children: [],
depth,
map.set(comment_view.comment.id, { ...node });
}
- let tree: CommentNodeI[] = [];
+ const tree: CommentNodeI[] = [];
// if its a parent comment fetch, then push the first comment to the top node.
if (parentComment) {
- let cNode = map.get(comments[0].comment.id);
+ const cNode = map.get(comments[0].comment.id);
if (cNode) {
tree.push(cNode);
}
}
- for (let comment_view of comments) {
- let child = map.get(comment_view.comment.id);
+ for (const comment_view of comments) {
+ const child = map.get(comment_view.comment.id);
if (child) {
- let parent_id = getCommentParentId(comment_view.comment);
+ const parent_id = getCommentParentId(comment_view.comment);
if (parent_id) {
- let parent = map.get(parent_id);
+ const parent = map.get(parent_id);
// Necessary because blocked comment might not exist
if (parent) {
parent.children.push(child);
}
export function getCommentParentId(comment?: CommentI): number | undefined {
- let split = comment?.path.split(".");
+ const split = comment?.path.split(".");
// remove the 0
split?.shift();
}
export function getDepthFromComment(comment?: CommentI): number | undefined {
- let len = comment?.path.split(".").length;
+ const len = comment?.path.split(".").length;
return len ? len - 2 : undefined;
}
parentComment: boolean
) {
// Building a fake node to be used for later
- let node: CommentNodeI = {
+ const node: CommentNodeI = {
comment_view: cv,
children: [],
depth: 0,
};
- let parentId = getCommentParentId(cv.comment);
+ const parentId = getCommentParentId(cv.comment);
if (parentId) {
- let parent_comment = searchCommentTree(tree, parentId);
+ const parent_comment = searchCommentTree(tree, parentId);
if (parent_comment) {
node.depth = parent_comment.depth + 1;
parent_comment.children.unshift(node);
tree: CommentNodeI[],
id: number
): CommentNodeI | undefined {
- for (let node of tree) {
+ for (const node of tree) {
if (node.comment_view.comment.id === id) {
return node;
}
for (const child of node.children) {
- let res = searchCommentTree([child], id);
+ const res = searchCommentTree([child], id);
if (res) {
return res;
}
export function hostname(url: string): string {
- let cUrl = new URL(url);
+ const cUrl = new URL(url);
return cUrl.port ? `${cUrl.hostname}:${cUrl.port}` : `${cUrl.hostname}`;
}
});
export function saveScrollPosition(context: any) {
- let path: string = context.router.route.location.pathname;
- let y = window.scrollY;
+ const path: string = context.router.route.location.pathname;
+ const y = window.scrollY;
sessionStorage.setItem(`scrollPosition_${path}`, y.toString());
}
export function restoreScrollPosition(context: any) {
- let path: string = context.router.route.location.pathname;
- let y = Number(sessionStorage.getItem(`scrollPosition_${path}`));
+ const path: string = context.router.route.location.pathname;
+ const y = Number(sessionStorage.getItem(`scrollPosition_${path}`));
window.scrollTo(0, y);
}
}
export async function fetchCommunities(q: string) {
- let form: Search = {
+ const form: Search = {
q,
type_: "Communities",
sort: "TopAll",
limit: fetchLimit,
auth: myAuth(false),
};
- let client = new LemmyHttp(getHttpBase());
+ const client = new LemmyHttp(getHttpBase());
return client.search(form);
}
export async function fetchUsers(q: string) {
- let form: Search = {
+ const form: Search = {
q,
type_: "Users",
sort: "TopAll",
limit: fetchLimit,
auth: myAuth(false),
};
- let client = new LemmyHttp(getHttpBase());
+ const client = new LemmyHttp(getHttpBase());
return client.search(form);
}
}
export function isBanned(ps: Person): boolean {
- let expires = ps.ban_expires;
+ const expires = ps.ban_expires;
// Add Z to convert from UTC date
// TODO this check probably isn't necessary anymore
if (expires) {
pv: PostView,
myUserInfo = UserService.Instance.myUserInfo
): boolean {
- let nsfw = pv.post.nsfw || pv.community.nsfw;
- let myShowNsfw = myUserInfo?.local_user_view.local_user.show_nsfw ?? false;
+ const nsfw = pv.post.nsfw || pv.community.nsfw;
+ const myShowNsfw = myUserInfo?.local_user_view.local_user.show_nsfw ?? false;
return !nsfw || (nsfw && myShowNsfw);
}
showSite?: boolean,
myUserInfo = UserService.Instance.myUserInfo
): Language[] {
- let allLangIds = allLanguages.map(l => l.id);
+ const allLangIds = allLanguages.map(l => l.id);
let myLangs = myUserInfo?.discussion_languages ?? allLangIds;
myLangs = myLangs.length == 0 ? allLangIds : myLangs;
- let siteLangs = siteLanguages.length == 0 ? allLangIds : siteLanguages;
+ const siteLangs = siteLanguages.length == 0 ? allLangIds : siteLanguages;
if (showAll) {
return allLanguages;