Skip to content

Commit

Permalink
Using auto-generated types from ts-rs. (LemmyNet#1003)
Browse files Browse the repository at this point in the history
* Using auto-generated types from ts-rs.

- Fixes LemmyNet#998
- Added support for new `GetFederatedInstances`
- Fixed a few bugs in the process.

* Update imports to use SleeplessOne1917's fix.
  • Loading branch information
dessalines authored May 11, 2023
1 parent 06bfb7e commit c5fd084
Show file tree
Hide file tree
Showing 48 changed files with 751 additions and 748 deletions.
2 changes: 1 addition & 1 deletion lemmy-translations
Submodule lemmy-translations updated 54 files
+13 −0 .woodpecker.yml
+3 −1 README.md
+16 −16 email/fi.json
+11 −11 email/it.json
+16 −16 email/ko.json
+16 −16 email/pt.json
+486 −486 translations/ar.json
+78 −78 translations/as.json
+393 −393 translations/bg.json
+106 −106 translations/bn.json
+309 −309 translations/ca.json
+373 −373 translations/cs.json
+28 −28 translations/cy.json
+478 −281 translations/da.json
+357 −357 translations/de.json
+463 −463 translations/el.json
+480 −481 translations/en.json
+478 −475 translations/eo.json
+478 −475 translations/es.json
+439 −439 translations/eu.json
+297 −297 translations/fa.json
+467 −467 translations/fi.json
+376 −376 translations/fr.json
+330 −330 translations/ga.json
+455 −455 translations/gl.json
+35 −35 translations/got.json
+64 −64 translations/hi.json
+414 −414 translations/hu.json
+398 −398 translations/id.json
+419 −419 translations/it.json
+458 −415 translations/ja.json
+227 −227 translations/ka.json
+440 −440 translations/ko.json
+278 −278 translations/lt.json
+182 −182 translations/ml.json
+15 −15 translations/mnc.json
+43 −43 translations/nb_NO.json
+393 −393 translations/nl.json
+412 −412 translations/oc.json
+478 −478 translations/pl.json
+414 −414 translations/pt.json
+460 −460 translations/pt_BR.json
+410 −410 translations/ru.json
+28 −28 translations/sk.json
+239 −239 translations/sq.json
+56 −56 translations/sr_Latn.json
+360 −360 translations/sv.json
+139 −139 translations/th.json
+250 −250 translations/tr.json
+323 −323 translations/uk.json
+376 −376 translations/vi.json
+379 −379 translations/zh.json
+396 −396 translations/zh_Hant.json
+140 −140 translators.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"inferno-server": "^8.1.1",
"isomorphic-cookie": "^1.2.4",
"jwt-decode": "^3.1.2",
"lemmy-js-client": "0.17.2-rc.5",
"lemmy-js-client": "0.17.2-rc.14",
"markdown-it": "^13.0.1",
"markdown-it-container": "^3.0.0",
"markdown-it-emoji": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/app/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Footer extends Component<FooterProps, any> {
</NavLink>
</li>
)}
{this.props.site.federated_instances && (
{this.props.site.site_view.local_site.federation_enabled && (
<li className="nav-item">
<NavLink className="nav-link" to="/instances">
{i18n.t("instances")}
Expand Down
30 changes: 15 additions & 15 deletions src/shared/components/app/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ interface NavbarProps {

interface NavbarState {
expanded: boolean;
unreadInboxCount: number;
unreadReportCount: number;
unreadApplicationCount: number;
unreadInboxCount: bigint;
unreadReportCount: bigint;
unreadApplicationCount: bigint;
showDropdown: boolean;
onSiteBanner?(url: string): any;
}
Expand All @@ -54,9 +54,9 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
private unreadReportCountSub: Subscription;
private unreadApplicationCountSub: Subscription;
state: NavbarState = {
unreadInboxCount: 0,
unreadReportCount: 0,
unreadApplicationCount: 0,
unreadInboxCount: 0n,
unreadReportCount: 0n,
unreadApplicationCount: 0n,
expanded: false,
showDropdown: false,
};
Expand Down Expand Up @@ -144,7 +144,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
className="p-1 navbar-toggler nav-link border-0"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_messages", {
count: this.state.unreadInboxCount,
count: Number(this.state.unreadInboxCount),
formattedCount: numToSI(this.state.unreadInboxCount),
})}
>
Expand All @@ -165,7 +165,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
className="p-1 navbar-toggler nav-link border-0"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_reports", {
count: this.state.unreadReportCount,
count: Number(this.state.unreadReportCount),
formattedCount: numToSI(this.state.unreadReportCount),
})}
>
Expand All @@ -187,7 +187,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
className="p-1 navbar-toggler nav-link border-0"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_registration_applications", {
count: this.state.unreadApplicationCount,
count: Number(this.state.unreadApplicationCount),
formattedCount: numToSI(
this.state.unreadApplicationCount
),
Expand Down Expand Up @@ -305,7 +305,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
to="/inbox"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_messages", {
count: this.state.unreadInboxCount,
count: Number(this.state.unreadInboxCount),
formattedCount: numToSI(this.state.unreadInboxCount),
})}
>
Expand All @@ -326,7 +326,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
to="/reports"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_reports", {
count: this.state.unreadReportCount,
count: Number(this.state.unreadReportCount),
formattedCount: numToSI(this.state.unreadReportCount),
})}
>
Expand All @@ -348,7 +348,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
className="nav-link"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_registration_applications", {
count: this.state.unreadApplicationCount,
count: Number(this.state.unreadApplicationCount),
formattedCount: numToSI(
this.state.unreadApplicationCount
),
Expand Down Expand Up @@ -512,7 +512,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
unreadReportCount:
data.post_reports +
data.comment_reports +
(data.private_message_reports ?? 0),
(data.private_message_reports ?? 0n),
});
this.sendReportUnread();
} else if (op == UserOperation.GetUnreadRegistrationApplicationCount) {
Expand All @@ -528,7 +528,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
data.recipient_ids.includes(mui.local_user_view.local_user.id)
) {
this.setState({
unreadInboxCount: this.state.unreadInboxCount + 1,
unreadInboxCount: this.state.unreadInboxCount + 1n,
});
this.sendUnreadCount();
notifyComment(data.comment_view, this.context.router);
Expand All @@ -541,7 +541,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
UserService.Instance.myUserInfo?.local_user_view.person.id
) {
this.setState({
unreadInboxCount: this.state.unreadInboxCount + 1,
unreadInboxCount: this.state.unreadInboxCount + 1n,
});
this.sendUnreadCount();
notifyPrivateMessage(data.private_message_view, this.context.router);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/comment/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component } from "inferno";
import { T } from "inferno-i18next-dess";
import { Link } from "inferno-router";
import {
CommentNode as CommentNodeI,
CommentResponse,
CreateComment,
EditComment,
Expand All @@ -12,6 +11,7 @@ import {
wsUserOp,
} from "lemmy-js-client";
import { Subscription } from "rxjs";
import { CommentNodeI } from "shared/interfaces";
import { i18n } from "../../i18next";
import { UserService, WebSocketService } from "../../services";
import {
Expand Down
75 changes: 40 additions & 35 deletions src/shared/components/comment/comment-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ import {
BanFromCommunity,
BanPerson,
BlockPerson,
CommentNode as CommentNodeI,
CommentReplyView,
CommentView,
CommunityModeratorView,
CreateCommentLike,
CreateCommentReport,
DeleteComment,
EditComment,
DistinguishComment,
GetComments,
Language,
ListingType,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
PersonMentionView,
PersonViewSafe,
PersonView,
PurgeComment,
PurgePerson,
RemoveComment,
Expand All @@ -30,7 +28,12 @@ import {
} from "lemmy-js-client";
import moment from "moment";
import { i18n } from "../../i18next";
import { BanType, CommentViewType, PurgeType } from "../../interfaces";
import {
BanType,
CommentNodeI,
CommentViewType,
PurgeType,
} from "../../interfaces";
import { UserService, WebSocketService } from "../../services";
import {
amCommunityCreator,
Expand Down Expand Up @@ -81,17 +84,17 @@ interface CommentNodeState {
showReportDialog: boolean;
reportReason?: string;
my_vote?: number;
score: number;
upvotes: number;
downvotes: number;
score: bigint;
upvotes: bigint;
downvotes: bigint;
readLoading: boolean;
saveLoading: boolean;
}

interface CommentNodeProps {
node: CommentNodeI;
moderators?: CommunityModeratorView[];
admins?: PersonViewSafe[];
admins?: PersonView[];
noBorder?: boolean;
noIndent?: boolean;
viewOnly?: boolean;
Expand Down Expand Up @@ -296,8 +299,8 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
<span
className="mr-1 font-weight-bold"
aria-label={i18n.t("number_of_points", {
count: this.state.score,
formattedCount: this.state.score,
count: Number(this.state.score),
formattedCount: numToSI(this.state.score),
})}
>
{numToSI(this.state.score)}
Expand Down Expand Up @@ -835,7 +838,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
>
{i18n.t("x_more_replies", {
count: node.comment_view.counts.child_count,
formattedCount: numToSI(node.comment_view.counts.child_count),
formattedCount: numToSI(
BigInt(node.comment_view.counts.child_count)
),
})}{" "}
</button>
Expand Down Expand Up @@ -1152,19 +1157,19 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {

if (myVote == 1) {
this.setState({
score: this.state.score - 1,
upvotes: this.state.upvotes - 1,
score: this.state.score - 1n,
upvotes: this.state.upvotes - 1n,
});
} else if (myVote == -1) {
this.setState({
downvotes: this.state.downvotes - 1,
upvotes: this.state.upvotes + 1,
score: this.state.score + 2,
downvotes: this.state.downvotes - 1n,
upvotes: this.state.upvotes + 1n,
score: this.state.score + 2n,
});
} else {
this.setState({
score: this.state.score + 1,
upvotes: this.state.upvotes + 1,
score: this.state.score + 1n,
upvotes: this.state.upvotes + 1n,
});
}

Expand All @@ -1189,19 +1194,19 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {

if (myVote == 1) {
this.setState({
downvotes: this.state.downvotes + 1,
upvotes: this.state.upvotes - 1,
score: this.state.score - 2,
downvotes: this.state.downvotes + 1n,
upvotes: this.state.upvotes - 1n,
score: this.state.score - 2n,
});
} else if (myVote == -1) {
this.setState({
downvotes: this.state.downvotes - 1,
score: this.state.score + 1,
downvotes: this.state.downvotes - 1n,
score: this.state.score + 1n,
});
} else {
this.setState({
downvotes: this.state.downvotes + 1,
score: this.state.score - 1,
downvotes: this.state.downvotes + 1n,
score: this.state.score - 1n,
});
}

Expand Down Expand Up @@ -1278,7 +1283,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
let comment = i.props.node.comment_view.comment;
let auth = myAuth();
if (auth) {
let form: EditComment = {
let form: DistinguishComment = {
comment_id: comment.id,
distinguished: !comment.distinguished,
auth,
Expand Down Expand Up @@ -1542,8 +1547,8 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
post_id: i.props.node.comment_view.post.id,
parent_id: i.props.node.comment_view.comment.id,
max_depth: commentTreeMaxDepth,
limit: 999, // TODO
type_: ListingType.All,
limit: 999n, // TODO
type_: "All",
saved_only: false,
auth: myAuth(false),
};
Expand All @@ -1563,18 +1568,18 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {

get pointsTippy(): string {
let points = i18n.t("number_of_points", {
count: this.state.score,
formattedCount: this.state.score,
count: Number(this.state.score),
formattedCount: numToSI(this.state.score),
});

let upvotes = i18n.t("number_of_upvotes", {
count: this.state.upvotes,
formattedCount: this.state.upvotes,
count: Number(this.state.upvotes),
formattedCount: numToSI(this.state.upvotes),
});

let downvotes = i18n.t("number_of_downvotes", {
count: this.state.downvotes,
formattedCount: this.state.downvotes,
count: Number(this.state.downvotes),
formattedCount: numToSI(this.state.downvotes),
});

return `${points}${upvotes}${downvotes}`;
Expand Down
11 changes: 3 additions & 8 deletions src/shared/components/comment/comment-nodes.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { Component } from "inferno";
import {
CommentNode as CommentNodeI,
CommunityModeratorView,
Language,
PersonViewSafe,
} from "lemmy-js-client";
import { CommentViewType } from "../../interfaces";
import { CommunityModeratorView, Language, PersonView } from "lemmy-js-client";
import { CommentNodeI, CommentViewType } from "../../interfaces";
import { CommentNode } from "./comment-node";

interface CommentNodesProps {
nodes: CommentNodeI[];
moderators?: CommunityModeratorView[];
admins?: PersonViewSafe[];
admins?: PersonView[];
maxCommentsShown?: number;
noBorder?: boolean;
noIndent?: boolean;
Expand Down
6 changes: 2 additions & 4 deletions src/shared/components/comment/comment-report.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Component, linkEvent } from "inferno";
import { T } from "inferno-i18next-dess";
import {
CommentNode as CommentNodeI,
CommentReportView,
CommentView,
ResolveCommentReport,
SubscribedType,
} from "lemmy-js-client";
import { i18n } from "../../i18next";
import { CommentViewType } from "../../interfaces";
import { CommentNodeI, CommentViewType } from "../../interfaces";
import { WebSocketService } from "../../services";
import { myAuth, wsClient } from "../../utils";
import { Icon } from "../common/icon";
Expand Down Expand Up @@ -41,7 +39,7 @@ export class CommentReport extends Component<CommentReportProps, any> {
community: r.community,
creator_banned_from_community: r.creator_banned_from_community,
counts: r.counts,
subscribed: SubscribedType.NotSubscribed,
subscribed: "NotSubscribed",
saved: false,
creator_blocked: false,
my_vote: r.my_vote,
Expand Down
8 changes: 4 additions & 4 deletions src/shared/components/common/comment-sort-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export class CommentSortSelect extends Component<
<option disabled aria-hidden="true">
{i18n.t("sort_type")}
</option>
<option value={CommentSortType.Hot}>{i18n.t("hot")}</option>,
<option value={CommentSortType.Top}>{i18n.t("top")}</option>,
<option value={CommentSortType.New}>{i18n.t("new")}</option>
<option value={CommentSortType.Old}>{i18n.t("old")}</option>
<option value={"Hot"}>{i18n.t("hot")}</option>,
<option value={"Top"}>{i18n.t("top")}</option>,
<option value={"New"}>{i18n.t("new")}</option>
<option value={"Old"}>{i18n.t("old")}</option>
</select>
<a
className="text-muted"
Expand Down
Loading

0 comments on commit c5fd084

Please sign in to comment.