feat: Add private messages
This commit is contained in:
1 parent
1a0881f9ce
commit
7113dc8463
9 files changed
+176
-46
No files matched your search
@@ -5,6 +5,7 @@
|
|||||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
|
|
||||||
export let postId: number
|
export let postId: number
|
||||||
export let parentId: number | undefined = undefined
|
export let parentId: number | undefined = undefined
|
||||||
@@ -48,11 +49,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="max-w-lg flex flex-col gap-2">
|
<div class="max-w-lg flex flex-col gap-2">
|
||||||
<textarea
|
<TextArea
|
||||||
rows="3"
|
rows={3}
|
||||||
class="w-full bg-slate-100 dark:bg-zinc-900 border border-slate-200
|
placeholder="What are you thinking?"
|
||||||
dark:border-zinc-800 p-4 outline-none focus:border-black
|
class="bg-slate-100 dark:bg-zinc-900"
|
||||||
focus:dark:border-white transition-colors rounded-md"
|
|
||||||
bind:value={newComment}
|
bind:value={newComment}
|
||||||
/>
|
/>
|
||||||
<div class="w-24 ml-auto flex flex-row gap-2">
|
<div class="w-24 ml-auto flex flex-row gap-2">
|
||||||
|
|||||||
@@ -89,13 +89,18 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
<span class="text-xs opacity-80 text-left mx-4 my-2">Profile</span>
|
<span class="text-xs opacity-80 text-left mx-4 my-2">
|
||||||
{#if !$user}
|
{$user ? $user.person_view.person.name : 'Profile'}
|
||||||
|
</span>
|
||||||
|
{#if !$user || !$authData}
|
||||||
<MenuButton link href="/login">
|
<MenuButton link href="/login">
|
||||||
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
|
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{:else}
|
{:else}
|
||||||
<MenuButton link href="/u/{$user.person_view.person.name}">
|
<MenuButton
|
||||||
|
link
|
||||||
|
href="/u/{$user.person_view.person.name}@{$authData.instance}"
|
||||||
|
>
|
||||||
<Icon src={UserCircle} mini width={16} /> Profile
|
<Icon src={UserCircle} mini width={16} /> Profile
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuButton link href="/inbox">
|
<MenuButton link href="/inbox">
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="sticky top-20 bg-white shadow-md border-slate-200
|
class="sticky top-20 bg-white shadow-md border-slate-200
|
||||||
dark:border-zinc-800 dark:bg-zinc-900 break-words hidden lg:flex
|
dark:border-zinc-800 dark:bg-zinc-900 break-words hidden lg:flex
|
||||||
flex-col gap-4 p-8 max-w-sm rounded-md h-max max-h-[calc(100vh-6rem)] overflow-auto"
|
flex-col gap-4 p-8 max-w-sm rounded-md h-max max-h-[calc(100vh-6rem)]
|
||||||
|
overflow-auto w-full"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
class="items-center flex flex-row gap-2 hover:underline"
|
class="items-center flex flex-row gap-1 hover:underline"
|
||||||
href={linkFromCommunity(user)}
|
href={linkFromCommunity(user)}
|
||||||
>
|
>
|
||||||
{#if avatar}
|
{#if avatar}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-row gap-4 justify-between">
|
<div class="flex flex-row gap-4 w-full">
|
||||||
<div class="flex flex-col gap-4 max-w-full w-full">
|
<div class="flex flex-col gap-4 max-w-full w-full">
|
||||||
<div class="flex flex-col sm:flex-row gap-4 max-w-full w-full">
|
<div class="flex flex-col sm:flex-row gap-4 max-w-full w-full">
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { CommentReplyView, PersonMentionView } from 'lemmy-js-client'
|
import type {
|
||||||
|
CommentReplyView,
|
||||||
|
PersonMentionView,
|
||||||
|
PrivateMessageView,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
import InboxItem from './InboxItem.svelte'
|
import InboxItem from './InboxItem.svelte'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { Check, Icon } from 'svelte-hero-icons'
|
import { Check, Icon } from 'svelte-hero-icons'
|
||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
|
||||||
export let data: {
|
export let data: {
|
||||||
data: PersonMentionView[] | CommentReplyView[]
|
data: PersonMentionView[] | CommentReplyView[] | PrivateMessageView[]
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRead(item: PersonMentionView | CommentReplyView) {
|
function isRead(
|
||||||
console.log('running...')
|
item: PersonMentionView | CommentReplyView | PrivateMessageView
|
||||||
|
) {
|
||||||
if ('person_mention' in item) {
|
if ('person_mention' in item) {
|
||||||
return (item as PersonMentionView).person_mention.read
|
return (item as PersonMentionView).person_mention.read
|
||||||
}
|
}
|
||||||
@@ -21,6 +26,10 @@
|
|||||||
return (item as CommentReplyView).comment_reply.read
|
return (item as CommentReplyView).comment_reply.read
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('private_message' in item) {
|
||||||
|
return (item as PrivateMessageView).private_message.read
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +38,8 @@
|
|||||||
auth: $authData!.token,
|
auth: $authData!.token,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$user.unreads = 0
|
||||||
|
|
||||||
goto($page.url, {
|
goto($page.url, {
|
||||||
invalidateAll: true,
|
invalidateAll: true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,7 +26,11 @@ export async function load() {
|
|||||||
client.getPrivateMessages(params),
|
client.getPrivateMessages(params),
|
||||||
])
|
])
|
||||||
|
|
||||||
const data = [...replies.replies, ...mentions.mentions].sort(
|
const data = [
|
||||||
|
...replies.replies,
|
||||||
|
...mentions.mentions,
|
||||||
|
...privateMessages.private_messages,
|
||||||
|
].sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
Date.parse(getInboxItemPublished(b)) -
|
Date.parse(getInboxItemPublished(b)) -
|
||||||
Date.parse(getInboxItemPublished(a))
|
Date.parse(getInboxItemPublished(a))
|
||||||
|
|||||||
@@ -1,45 +1,154 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
|
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||||
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import type {
|
import type {
|
||||||
CommentReplyView,
|
CommentReplyView,
|
||||||
PersonMentionView,
|
PersonMentionView,
|
||||||
PrivateMessageView,
|
PrivateMessageView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
|
import { ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
|
||||||
export let item: CommentReplyView | PersonMentionView
|
export let item: CommentReplyView | PersonMentionView | PrivateMessageView
|
||||||
export let read: boolean
|
export let read: boolean
|
||||||
|
|
||||||
|
function isPrivateMessage(
|
||||||
|
item: CommentReplyView | PersonMentionView | PrivateMessageView
|
||||||
|
) {
|
||||||
|
return 'private_message' in item
|
||||||
|
}
|
||||||
|
|
||||||
|
// I hate how you can't type cast in Svelte easily
|
||||||
|
const replyItem = item as CommentReplyView | PersonMentionView
|
||||||
|
const messageItem = item as PrivateMessageView
|
||||||
|
|
||||||
|
let replying = false
|
||||||
|
let reply = ''
|
||||||
|
let loading = false
|
||||||
|
|
||||||
|
async function replyToMessage() {
|
||||||
|
if (!$authData) return
|
||||||
|
|
||||||
|
loading = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
await getClient().createPrivateMessage({
|
||||||
|
auth: $authData.token,
|
||||||
|
content: reply,
|
||||||
|
recipient_id: messageItem.creator.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
addToast(
|
||||||
|
'Success',
|
||||||
|
'Successfully replied to that message.',
|
||||||
|
ToastType.success
|
||||||
|
)
|
||||||
|
|
||||||
|
replying = false
|
||||||
|
|
||||||
|
goto($page.url, {
|
||||||
|
invalidateAll: true,
|
||||||
|
replaceState: true,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
addToast('Error', error as any, ToastType.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card class="flex flex-col bg-white rounded-md p-4 max-w-full">
|
<Card class="flex flex-col bg-white rounded-md p-4 max-w-full">
|
||||||
<div class="flex flex-row items-center">
|
{#if !isPrivateMessage(item)}
|
||||||
<div
|
<div class="flex flex-row items-center">
|
||||||
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
|
<div
|
||||||
|
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
|
||||||
overflow-hidden {read ? 'opacity-50' : ''}"
|
overflow-hidden {read ? 'opacity-50' : ''}"
|
||||||
>
|
|
||||||
<span class="font-bold">
|
|
||||||
{item.creator.display_name ?? item.creator.name}
|
|
||||||
</span>
|
|
||||||
replied to you in
|
|
||||||
<a
|
|
||||||
href="/post/{item.post.id}"
|
|
||||||
class="font-bold max-w-[48ch] overflow-hidden text-ellipsis
|
|
||||||
whitespace-nowrap inline hover:underline"
|
|
||||||
>
|
>
|
||||||
{item.post.name}
|
<span class="font-bold">
|
||||||
</a>
|
{replyItem.creator.display_name ?? replyItem.creator.name}
|
||||||
</div>
|
</span>
|
||||||
|
replied to you in
|
||||||
|
<a
|
||||||
|
href="/post/{replyItem.post.id}"
|
||||||
|
class="font-bold max-w-[48ch] overflow-hidden text-ellipsis
|
||||||
|
whitespace-nowrap inline hover:underline"
|
||||||
|
>
|
||||||
|
{replyItem.post.name}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="w-max ml-auto">
|
<div class="w-max ml-auto">
|
||||||
<Link href="/post/{item.post.id}#{item.comment.id}">Jump</Link>
|
<Link href="/post/{replyItem.post.id}#{replyItem.comment.id}">
|
||||||
|
Jump
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div>
|
||||||
<div>
|
<Comment
|
||||||
<Comment
|
postId={replyItem.post.id}
|
||||||
postId={item.post.id}
|
node={{ children: [], comment_view: replyItem, depth: 1 }}
|
||||||
node={{ children: [], comment_view: item, depth: 1 }}
|
replying={false}
|
||||||
replying={false}
|
/>
|
||||||
/>
|
</div>
|
||||||
</div>
|
{:else}
|
||||||
|
<div class="flex flex-row items-center">
|
||||||
|
<div
|
||||||
|
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
|
||||||
|
overflow-hidden flex flex-row items-center gap-1 {read ? 'opacity-80' : ''}"
|
||||||
|
>
|
||||||
|
<span class="font-bold">
|
||||||
|
{#if messageItem.creator.id == $user?.person_view.person.id}
|
||||||
|
You
|
||||||
|
{:else}
|
||||||
|
<UserLink avatar user={messageItem.creator} />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
<span>messaged</span>
|
||||||
|
<span class="font-bold">
|
||||||
|
{#if messageItem.recipient.id == $user?.person_view.person.id}
|
||||||
|
You
|
||||||
|
{:else}
|
||||||
|
<UserLink avatar user={messageItem.recipient} />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="text-sm py-2">
|
||||||
|
<Markdown source={messageItem.private_message.content} />
|
||||||
|
</p>
|
||||||
|
{#if messageItem.recipient.id == $user?.person_view.person.id}
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<Button color={Color.ghost} on:click={() => (replying = !replying)}>
|
||||||
|
<Icon mini src={ChatBubbleOvalLeft} width={16} />
|
||||||
|
Reply
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#if replying}
|
||||||
|
<div class="mt-2 flex flex-col gap-2">
|
||||||
|
<TextArea placeholder="Message" bind:value={reply} rows={3} />
|
||||||
|
<div class="ml-auto w-24">
|
||||||
|
<Button
|
||||||
|
disabled={loading}
|
||||||
|
{loading}
|
||||||
|
large
|
||||||
|
on:click={replyToMessage}
|
||||||
|
color={Color.accent}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
</Card>
|
</Card>
|
||||||
@@ -60,8 +60,8 @@
|
|||||||
<title>{data.user.person_view.person.name}</title>
|
<title>{data.user.person_view.person.name}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex flex-row gap-4 max-w-full">
|
<div class="flex flex-row gap-4 max-w-full w-full">
|
||||||
<div class="flex flex-col gap-4 max-w-full">
|
<div class="flex flex-col gap-4 max-w-full w-full">
|
||||||
{#each items as item}
|
{#each items as item}
|
||||||
{#if item.post}
|
{#if item.post}
|
||||||
<Post post={item.item} />
|
<Post post={item.item} />
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="max-w-sm w-full hidden xl:block">
|
<div class="max-w-sm w-full hidden lg:block">
|
||||||
<StickyCard>
|
<StickyCard>
|
||||||
<Avatar
|
<Avatar
|
||||||
width={64}
|
width={64}
|
||||||
|
|||||||
Reference in new issue
Block a user