diff --git a/src/lib/lemmy/item.ts b/src/lib/lemmy/item.ts index a2e8e43e..ad914bed 100644 --- a/src/lib/lemmy/item.ts +++ b/src/lib/lemmy/item.ts @@ -5,9 +5,9 @@ import type { PostView, } from 'lemmy-js-client' -export function getItemPublished( - item: PostView | CommentView | PersonView | CommunityView -) { +type Result = PostView | CommentView | PersonView | CommunityView + +export function getItemPublished(item: Result) { if ('comment' in item) { return item.comment.published } else if ('post' in item) { @@ -24,3 +24,14 @@ export function getItemPublished( return '' } + +export const isPost = (item: Result): item is PostView => + 'post' in item && !('comment' in item) + +export const isComment = (item: Result): item is CommentView => + 'comment' in item + +export const isCommunity = (item: Result): item is CommunityView => + 'community' in item + +export const isUser = (item: Result): item is PersonView => 'person' in item diff --git a/src/routes/inbox/+page.svelte b/src/routes/inbox/+page.svelte index fccc33be..f89d071a 100644 --- a/src/routes/inbox/+page.svelte +++ b/src/routes/inbox/+page.svelte @@ -1,9 +1,4 @@