feat: add sorts to user pages

This commit is contained in:
Xyphyn committed 2023-07-27 12:25:26 -07:00
1 parent d427d4b2fc
commit c0aaf08a9f
12 files changed
+129 -69

No files matched your search

+18
View File
@@ -20,3 +20,21 @@ export function getInboxItemPublished(item: InboxItemView): string {
return item.person_mention.published
}
export function isRead(
item: PersonMentionView | CommentReplyView | PrivateMessageView
) {
if ('person_mention' in item) {
return (item as PersonMentionView).person_mention.read
}
if ('comment_reply' in item) {
return (item as CommentReplyView).comment_reply.read
}
if ('private_message' in item) {
return (item as PrivateMessageView).private_message.read
}
return false
}
+26
View File
@@ -0,0 +1,26 @@
import type {
CommentView,
CommunityView,
PersonView,
PostView,
} from 'lemmy-js-client'
export function getItemPublished(
item: PostView | CommentView | PersonView | CommunityView
) {
if ('comment' in item) {
return item.comment.published
} else if ('post' in item) {
return item.post.published
}
if ('person' in item) {
return item.person.published
}
if ('community' in item) {
return item.community.published
}
return ''
}
+18
View File
@@ -0,0 +1,18 @@
import { authData, getClient } from '$lib/lemmy.js'
import type { MyUserInfo, PersonView } from 'lemmy-js-client'
import { get } from 'svelte/store'
export const blockUser = async (block: boolean, id: number) => {
const auth = get(authData)?.token
if (!auth) throw new Error('Unauthorized')
const response = await getClient().blockPerson({
auth: auth,
block: block,
person_id: id,
})
}
export const isBlocked = (me: MyUserInfo, user: number) =>
me.person_blocks.map((b) => b.target.id).includes(user)