Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions src/providers/piefed/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const fromPageParams = lemmyCompat.fromPageParams;

export function toComment(
comment: components["schemas"]["Comment"],
creator_id: number, // TODO piefed types are wrong, this isn't being returned rn
creator_id: number // TODO piefed types are wrong, this isn't being returned rn
) {
return {
...comment,
Expand All @@ -18,7 +18,7 @@ export function toComment(
}

export function toCommentReplyView(
reply: components["schemas"]["CommentReplyView"],
reply: components["schemas"]["CommentReplyView"]
) {
return {
...reply,
Expand All @@ -31,26 +31,35 @@ export function toCommentReplyView(
};
}

export function toCommentView(comment: components["schemas"]["CommentView"]) {
export function toCommentView(
comment: components["schemas"]["CommentView"]
): types.CommentView {
return {
...comment,
comment: toComment(comment.comment, comment.creator.id),
community: toCommunity(comment.community),
creator: toPerson(comment.creator),
post: toPost(comment.post),

// TODO: is this correct? Piefed types are wide (string) here
subscribed: comment.subscribed as types.CommentView["subscribed"],
};
}

export function toCommunity(community: components["schemas"]["Community"]) {
export function toCommunity(
community: components["schemas"]["Community"]
): types.Community {
return {
...community,
banner: community.banner ?? undefined,
icon: community.icon ?? undefined,
posting_restricted_to_mods: community.restricted_to_mods,
visibility: "Public" as const,
};
}

export function toCommunityModeratorView(
view: components["schemas"]["CommunityModeratorView"],
view: components["schemas"]["CommunityModeratorView"]
) {
return {
...view,
Expand All @@ -60,7 +69,7 @@ export function toCommunityModeratorView(
}

export function toCommunityView(
community: components["schemas"]["CommunityView"],
community: components["schemas"]["CommunityView"]
): types.CommunityView {
return {
...community,
Expand All @@ -78,7 +87,7 @@ export function toCommunityView(
}

export function toGetCommunityResponse(
response: components["schemas"]["GetCommunityResponse"],
response: components["schemas"]["GetCommunityResponse"]
) {
return {
community_view: toCommunityView(response.community_view),
Expand All @@ -87,7 +96,7 @@ export function toGetCommunityResponse(
}

export function toLocalSite(
site: components["schemas"]["Site"],
site: components["schemas"]["Site"]
): types.LocalSite {
return {
captcha_enabled: false,
Expand All @@ -100,18 +109,21 @@ export function toLocalSite(
};
}

export function toPerson(person: components["schemas"]["Person"]) {
export function toPerson(
person: components["schemas"]["Person"]
): types.Person {
return {
...person,
avatar: person.avatar ?? undefined, // TODO piefed types are wrong, this is returned as null if not set
bot_account: person.bot,
display_name: person.title ?? undefined, // TODO piefed types are wrong, this is returned as null if not set
name: person.user_name!,
published: person.published!,
};
}

export function toPersonMentionView(
mention: components["schemas"]["CommentReplyView"],
mention: components["schemas"]["CommentReplyView"]
): types.PersonMentionView {
return {
...mention,
Expand Down Expand Up @@ -143,7 +155,7 @@ export function toPost(post: components["schemas"]["Post"]) {
}

export function toPostView(
post: components["schemas"]["PostView"],
post: components["schemas"]["PostView"]
): types.PostView {
return {
...post,
Expand All @@ -155,11 +167,18 @@ export function toPostView(
}

export function toPrivateMessageView(
message: components["schemas"]["PrivateMessageView"],
message: components["schemas"]["PrivateMessageView"]
) {
return {
...message,
creator: toPerson(message.creator),
recipient: toPerson(message.recipient),
};
}

export function toSite(site: components["schemas"]["Site"]): types.Site {
return {
...site,
icon: site.icon ?? undefined,
};
}
Loading