Updating translations.

This commit is contained in:
Dessalines 2021-09-27 21:00:38 -04:00
parent 65be5c7833
commit 033b60a4ba
8 changed files with 683 additions and 9 deletions

@ -1 +1 @@
Subproject commit 7dd7b98da76477222f9fd9720b4b25e14e3ddc97 Subproject commit 9a584ef77e7861466bd5f44dd87d3681d4871a60

View file

@ -0,0 +1,107 @@
import { Component, linkEvent } from "inferno";
import { T } from "inferno-i18next-dess";
import {
CommentReportView,
CommentView,
ResolveCommentReport,
} from "lemmy-js-client";
import { i18n } from "../../i18next";
import { CommentNode as CommentNodeI } from "../../interfaces";
import { WebSocketService } from "../../services";
import { authField, wsClient } from "../../utils";
import { Icon } from "../common/icon";
import { PersonListing } from "../person/person-listing";
import { CommentNode } from "./comment-node";
interface CommentReportProps {
report: CommentReportView;
}
export class CommentReport extends Component<CommentReportProps, any> {
constructor(props: any, context: any) {
super(props, context);
}
render() {
let r = this.props.report;
let comment = r.comment;
// Set the original post data ( a troll could change it )
comment.content = r.comment_report.original_comment_text;
let comment_view: CommentView = {
comment,
creator: r.comment_creator,
post: r.post,
community: r.community,
creator_banned_from_community: r.creator_banned_from_community,
counts: r.counts,
subscribed: false,
saved: false,
creator_blocked: false,
my_vote: r.my_vote,
};
let node: CommentNodeI = {
comment_view,
};
return (
<div>
<CommentNode
node={node}
moderators={[]}
admins={[]}
enableDownvotes={true}
/>
<div>
{i18n.t("reporter")}: <PersonListing person={r.creator} />
</div>
<div>
{i18n.t("reason")}: {r.comment_report.reason}
</div>
{r.resolver && (
<div>
{r.comment_report.resolved ? (
<T i18nKey="resolved_by">
#
<PersonListing person={r.resolver} />
</T>
) : (
<T i18nKey="unresolved_by">
#
<PersonListing person={r.resolver} />
</T>
)}
</div>
)}
<button
className="btn btn-link btn-animate text-muted py-0"
onClick={linkEvent(this, this.handleResolveReport)}
data-tippy-content={
r.comment_report.resolved ? "unresolve_report" : "resolve_report"
}
aria-label={
r.comment_report.resolved ? "unresolve_report" : "resolve_report"
}
>
<Icon
icon="check"
classes={`icon-inline ${
r.comment_report.resolved ? "text-success" : "text-danger"
}`}
/>
</button>
</div>
);
}
handleResolveReport(i: CommentReport) {
let form: ResolveCommentReport = {
report_id: i.props.report.comment_report.id,
resolved: !i.props.report.comment_report.resolved,
auth: authField(),
};
WebSocketService.Instance.send(wsClient.resolveCommentReport(form));
}
}

View file

@ -765,7 +765,7 @@ export class Inbox extends Component<any, InboxState> {
} }
sendUnreadCount() { sendUnreadCount() {
UserService.Instance.unreadCountSub.next(this.unreadCount()); UserService.Instance.unreadInboxCountSub.next(this.unreadCount());
} }
unreadCount(): number { unreadCount(): number {

View file

@ -0,0 +1,445 @@
import { Component, linkEvent } from "inferno";
import {
CommentReportResponse,
CommentReportView,
ListCommentReports,
ListCommentReportsResponse,
ListPostReports,
ListPostReportsResponse,
PostReportResponse,
PostReportView,
SiteView,
UserOperation,
} from "lemmy-js-client";
import { Subscription } from "rxjs";
import { i18n } from "../../i18next";
import { InitialFetchRequest } from "../../interfaces";
import { UserService, WebSocketService } from "../../services";
import {
authField,
fetchLimit,
isBrowser,
setIsoData,
setupTippy,
toast,
updateCommentReportRes,
updatePostReportRes,
wsClient,
wsJsonToRes,
wsSubscribe,
wsUserOp,
} from "../../utils";
import { CommentReport } from "../comment/comment_report";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
import { Paginator } from "../common/paginator";
import { PostReport } from "../post/post_report";
enum UnreadOrAll {
Unread,
All,
}
enum MessageType {
All,
CommentReport,
PostReport,
}
enum MessageEnum {
CommentReport,
PostReport,
}
type ItemType = {
id: number;
type_: MessageEnum;
view: CommentReportView | PostReportView;
published: string;
};
interface ReportsState {
unreadOrAll: UnreadOrAll;
messageType: MessageType;
commentReports: CommentReportView[];
postReports: PostReportView[];
combined: ItemType[];
page: number;
site_view: SiteView;
loading: boolean;
}
export class Reports extends Component<any, ReportsState> {
private isoData = setIsoData(this.context);
private subscription: Subscription;
private emptyState: ReportsState = {
unreadOrAll: UnreadOrAll.Unread,
messageType: MessageType.All,
commentReports: [],
postReports: [],
combined: [],
page: 1,
site_view: this.isoData.site_res.site_view,
loading: true,
};
constructor(props: any, context: any) {
super(props, context);
this.state = this.emptyState;
this.handlePageChange = this.handlePageChange.bind(this);
if (!UserService.Instance.myUserInfo && isBrowser()) {
toast(i18n.t("not_logged_in"), "danger");
this.context.router.history.push(`/login`);
}
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
// Only fetch the data if coming from another route
if (this.isoData.path == this.context.router.route.match.url) {
this.state.commentReports =
this.isoData.routeData[0].comment_reports || [];
this.state.postReports = this.isoData.routeData[1].post_reports || [];
this.state.combined = this.buildCombined();
this.state.loading = false;
console.log(this.isoData.routeData[1]);
} else {
this.refetch();
}
}
componentWillUnmount() {
if (isBrowser()) {
this.subscription.unsubscribe();
}
}
get documentTitle(): string {
return `@${
UserService.Instance.myUserInfo.local_user_view.person.name
} ${i18n.t("reports")} - ${this.state.site_view.site.name}`;
}
render() {
return (
<div class="container">
{this.state.loading ? (
<h5>
<Spinner large />
</h5>
) : (
<div class="row">
<div class="col-12">
<HtmlTags
title={this.documentTitle}
path={this.context.router.route.match.url}
/>
<h5 class="mb-2">{i18n.t("reports")}</h5>
{this.selects()}
{this.state.messageType == MessageType.All && this.all()}
{this.state.messageType == MessageType.CommentReport &&
this.commentReports()}
{this.state.messageType == MessageType.PostReport &&
this.postReports()}
<Paginator
page={this.state.page}
onChange={this.handlePageChange}
/>
</div>
</div>
)}
</div>
);
}
unreadOrAllRadios() {
return (
<div class="btn-group btn-group-toggle flex-wrap mb-2">
<label
className={`btn btn-outline-secondary pointer
${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
`}
>
<input
type="radio"
value={UnreadOrAll.Unread}
checked={this.state.unreadOrAll == UnreadOrAll.Unread}
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
/>
{i18n.t("unread")}
</label>
<label
className={`btn btn-outline-secondary pointer
${this.state.unreadOrAll == UnreadOrAll.All && "active"}
`}
>
<input
type="radio"
value={UnreadOrAll.All}
checked={this.state.unreadOrAll == UnreadOrAll.All}
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
/>
{i18n.t("all")}
</label>
</div>
);
}
messageTypeRadios() {
return (
<div class="btn-group btn-group-toggle flex-wrap mb-2">
<label
className={`btn btn-outline-secondary pointer
${this.state.messageType == MessageType.All && "active"}
`}
>
<input
type="radio"
value={MessageType.All}
checked={this.state.messageType == MessageType.All}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
{i18n.t("all")}
</label>
<label
className={`btn btn-outline-secondary pointer
${this.state.messageType == MessageType.CommentReport && "active"}
`}
>
<input
type="radio"
value={MessageType.CommentReport}
checked={this.state.messageType == MessageType.CommentReport}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
{i18n.t("comments")}
</label>
<label
className={`btn btn-outline-secondary pointer
${this.state.messageType == MessageType.PostReport && "active"}
`}
>
<input
type="radio"
value={MessageType.PostReport}
checked={this.state.messageType == MessageType.PostReport}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
{i18n.t("posts")}
</label>
</div>
);
}
selects() {
return (
<div className="mb-2">
<span class="mr-3">{this.unreadOrAllRadios()}</span>
<span class="mr-3">{this.messageTypeRadios()}</span>
</div>
);
}
replyToReplyType(r: CommentReportView): ItemType {
return {
id: r.comment_report.id,
type_: MessageEnum.CommentReport,
view: r,
published: r.comment_report.published,
};
}
mentionToReplyType(r: PostReportView): ItemType {
return {
id: r.post_report.id,
type_: MessageEnum.PostReport,
view: r,
published: r.post_report.published,
};
}
buildCombined(): ItemType[] {
let comments: ItemType[] = this.state.commentReports.map(r =>
this.replyToReplyType(r)
);
let posts: ItemType[] = this.state.postReports.map(r =>
this.mentionToReplyType(r)
);
return [...comments, ...posts].sort((a, b) =>
b.published.localeCompare(a.published)
);
}
renderItemType(i: ItemType) {
switch (i.type_) {
case MessageEnum.CommentReport:
return (
<CommentReport key={i.id} report={i.view as CommentReportView} />
);
case MessageEnum.PostReport:
return <PostReport key={i.id} report={i.view as PostReportView} />;
default:
return <div />;
}
}
all() {
return (
<div>
{this.state.combined.map(i => (
<>
<hr />
{this.renderItemType(i)}
</>
))}
</div>
);
}
commentReports() {
return (
<div>
{this.state.commentReports.map(cr => (
<>
<hr />
<CommentReport key={cr.comment_report.id} report={cr} />
</>
))}
</div>
);
}
postReports() {
return (
<div>
{this.state.postReports.map(pr => (
<>
<hr />
<PostReport key={pr.post_report.id} report={pr} />
</>
))}
</div>
);
}
handlePageChange(page: number) {
this.setState({ page });
this.refetch();
}
handleUnreadOrAllChange(i: Reports, event: any) {
i.state.unreadOrAll = Number(event.target.value);
i.state.page = 1;
i.setState(i.state);
i.refetch();
}
handleMessageTypeChange(i: Reports, event: any) {
i.state.messageType = Number(event.target.value);
i.state.page = 1;
i.setState(i.state);
i.refetch();
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let promises: Promise<any>[] = [];
let commentReportsForm: ListCommentReports = {
// TODO community_id
unresolved_only: true,
page: 1,
limit: fetchLimit,
auth: req.auth,
};
promises.push(req.client.listCommentReports(commentReportsForm));
let postReportsForm: ListPostReports = {
// TODO community_id
unresolved_only: true,
page: 1,
limit: fetchLimit,
auth: req.auth,
};
promises.push(req.client.listPostReports(postReportsForm));
return promises;
}
refetch() {
let unresolved_only = this.state.unreadOrAll == UnreadOrAll.Unread;
let commentReportsForm: ListCommentReports = {
// TODO community_id
unresolved_only,
page: this.state.page,
limit: fetchLimit,
auth: authField(),
};
WebSocketService.Instance.send(
wsClient.listCommentReports(commentReportsForm)
);
let postReportsForm: ListPostReports = {
// TODO community_id
unresolved_only,
page: this.state.page,
limit: fetchLimit,
auth: authField(),
};
WebSocketService.Instance.send(wsClient.listPostReports(postReportsForm));
}
parseMessage(msg: any) {
let op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
return;
} else if (msg.reconnect) {
this.refetch();
} else if (op == UserOperation.ListCommentReports) {
let data = wsJsonToRes<ListCommentReportsResponse>(msg).data;
this.state.commentReports = data.comment_reports;
this.state.combined = this.buildCombined();
this.state.loading = false;
// this.sendUnreadCount();
window.scrollTo(0, 0);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.ListPostReports) {
let data = wsJsonToRes<ListPostReportsResponse>(msg).data;
this.state.postReports = data.post_reports;
this.state.combined = this.buildCombined();
this.state.loading = false;
// this.sendUnreadCount();
window.scrollTo(0, 0);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.ResolvePostReport) {
let data = wsJsonToRes<PostReportResponse>(msg).data;
updatePostReportRes(data.post_report_view, this.state.postReports);
let urcs = UserService.Instance.unreadReportCountSub;
if (data.post_report_view.post_report.resolved) {
urcs.next(urcs.getValue() - 1);
} else {
urcs.next(urcs.getValue() + 1);
}
this.setState(this.state);
} else if (op == UserOperation.ResolveCommentReport) {
let data = wsJsonToRes<CommentReportResponse>(msg).data;
updateCommentReportRes(
data.comment_report_view,
this.state.commentReports
);
let urcs = UserService.Instance.unreadReportCountSub;
if (data.comment_report_view.comment_report.resolved) {
urcs.next(urcs.getValue() - 1);
} else {
urcs.next(urcs.getValue() + 1);
}
this.setState(this.state);
}
}
}

View file

@ -0,0 +1,99 @@
import { Component, linkEvent } from "inferno";
import { T } from "inferno-i18next-dess";
import { PostReportView, PostView, ResolvePostReport } from "lemmy-js-client";
import { i18n } from "../../i18next";
import { WebSocketService } from "../../services";
import { authField, wsClient } from "../../utils";
import { Icon } from "../common/icon";
import { PersonListing } from "../person/person-listing";
import { PostListing } from "./post-listing";
interface PostReportProps {
report: PostReportView;
}
export class PostReport extends Component<PostReportProps, any> {
constructor(props: any, context: any) {
super(props, context);
}
render() {
let r = this.props.report;
let post = r.post;
// Set the original post data ( a troll could change it )
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 = {
post,
creator: r.post_creator,
community: r.community,
creator_banned_from_community: r.creator_banned_from_community,
counts: r.counts,
subscribed: false,
saved: false,
read: false,
creator_blocked: false,
my_vote: r.my_vote,
};
return (
<div>
<PostListing
post_view={pv}
showCommunity={true}
enableDownvotes={true}
enableNsfw={true}
/>
<div>
{i18n.t("reporter")}: <PersonListing person={r.creator} />
</div>
<div>
{i18n.t("reason")}: {r.post_report.reason}
</div>
{r.resolver && (
<div>
{r.post_report.resolved ? (
<T i18nKey="resolved_by">
#
<PersonListing person={r.resolver} />
</T>
) : (
<T i18nKey="unresolved_by">
#
<PersonListing person={r.resolver} />
</T>
)}
</div>
)}
<button
className="btn btn-link btn-animate text-muted py-0"
onClick={linkEvent(this, this.handleResolveReport)}
data-tippy-content={
r.post_report.resolved ? "unresolve_report" : "resolve_report"
}
aria-label={
r.post_report.resolved ? "unresolve_report" : "resolve_report"
}
>
<Icon
icon="check"
classes={`icon-inline ${
r.post_report.resolved ? "text-success" : "text-danger"
}`}
/>
</button>
</div>
);
}
handleResolveReport(i: PostReport) {
let form: ResolvePostReport = {
report_id: i.props.report.post_report.id,
resolved: !i.props.report.post_report.resolved,
auth: authField(),
};
WebSocketService.Instance.send(wsClient.resolvePostReport(form));
}
}

View file

@ -16,9 +16,10 @@ export class UserService {
public myUserInfo: MyUserInfo; public myUserInfo: MyUserInfo;
public claims: Claims; public claims: Claims;
public jwtSub: Subject<string> = new Subject<string>(); public jwtSub: Subject<string> = new Subject<string>();
public unreadCountSub: BehaviorSubject<number> = new BehaviorSubject<number>( public unreadInboxCountSub: BehaviorSubject<number> =
0 new BehaviorSubject<number>(0);
); public unreadReportCountSub: BehaviorSubject<number> =
new BehaviorSubject<number>(0);
private constructor() { private constructor() {
if (this.auth) { if (this.auth) {

View file

@ -2,6 +2,7 @@ import emojiShortName from "emoji-short-name";
import { import {
BlockCommunityResponse, BlockCommunityResponse,
BlockPersonResponse, BlockPersonResponse,
CommentReportView,
CommentView, CommentView,
CommunityBlockView, CommunityBlockView,
CommunityView, CommunityView,
@ -13,6 +14,7 @@ import {
MyUserInfo, MyUserInfo,
PersonBlockView, PersonBlockView,
PersonViewSafe, PersonViewSafe,
PostReportView,
PostView, PostView,
PrivateMessageView, PrivateMessageView,
Search, Search,
@ -1055,6 +1057,26 @@ export function editPostRes(data: PostView, post: PostView) {
} }
} }
export function updatePostReportRes(
data: PostReportView,
reports: PostReportView[]
) {
let found = reports.find(p => p.post.id == data.post.id);
if (found) {
found.post_report = data.post_report;
}
}
export function updateCommentReportRes(
data: CommentReportView,
reports: CommentReportView[]
) {
let found = reports.find(c => c.comment.id == data.comment.id);
if (found) {
found.comment_report = data.comment_report;
}
}
export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] { export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] {
let nodes: CommentNodeI[] = []; let nodes: CommentNodeI[] = [];
for (let comment of comments) { for (let comment of comments) {

View file

@ -4709,10 +4709,10 @@ lcid@^1.0.0:
dependencies: dependencies:
invert-kv "^1.0.0" invert-kv "^1.0.0"
lemmy-js-client@0.12.0: lemmy-js-client@0.12.3-rc.5:
version "0.12.0" version "0.12.3-rc.5"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.12.0.tgz#2337aca9d8b38d92908d7f7a9479f0066a9eaeae" resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.12.3-rc.5.tgz#26bc2d8443c5ab2bea1ed73697b202592fd00e15"
integrity sha512-PSebUBkojM7OUlfSXKQhL4IcYKaKF+Xj2G0+pybaCvP9sJvviy32qHUi9BQeIhRHXgw8ILRH0Y+xZGKu0a3wvQ== integrity sha512-3Rs1G7b/MYhQkMYJqBgQ+piSE+anYa+C2tr1DqY7+JrO1vbepu2+GyDg3jjzPuoZ3GPPOWYtKJU5pt9GqLb1lg==
levn@^0.4.1: levn@^0.4.1:
version "0.4.1" version "0.4.1"