Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): fix chat in nav bar #929

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
39 changes: 18 additions & 21 deletions src/routes/chat/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import { type MessageGroup as MessageGroupType } from "$lib/types"
import EncryptedNotice from "$lib/components/messaging/EncryptedNotice.svelte"
import { Store } from "$lib/state/Store"
import { derived, get } from "svelte/store"
import { derived, get, writable } from "svelte/store"
import { goto } from "$app/navigation"
import { UIStore } from "$lib/state/ui"
import CreateGroup from "$lib/components/group/CreateGroup.svelte"
Expand Down Expand Up @@ -58,23 +58,15 @@
import { routes } from "$lib/defaults/routes"
import BottomNavBarMobile from "$lib/layouts/BottomNavBarMobile.svelte"

enum Permission {
UNDEFINED,
ALLOWED,
DENIED,
}
let loading = false
let contentAsideOpen = false
let showBrowseFilesModal = false
let clipboardWrite = false

const checkClipboardPermission = async () => {
try {
let items = await navigator.clipboard.read()
await navigator.clipboard.write(items)
clipboardWrite = true
} catch (err) {
clipboardWrite = false
}
}
onMount(async () => {
await checkClipboardPermission()
})
$: clipboardWrite = writable(Permission.UNDEFINED)

$: sidebarOpen = UIStore.state.sidebarOpen
$: activeChat = Store.state.activeChat
Expand Down Expand Up @@ -227,7 +219,7 @@
copy(message.text.join("\n"))
},
},
...(file && file.kind === MessageAttachmentKind.Image && clipboardWrite
...(file && file.kind === MessageAttachmentKind.Image && $clipboardWrite !== Permission.DENIED
? [
{
id: "copy-image",
Expand Down Expand Up @@ -308,11 +300,16 @@
if (attachment.kind !== MessageAttachmentKind.Image) return
let result = await RaygunStoreInstance.getAttachmentRaw($conversation!.id, message, attachment.name, { size: attachment.size, type: "image/png" })
result.onSuccess(async blob => {
await navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob,
}),
])
try {
await navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob,
}),
])
$clipboardWrite = Permission.ALLOWED
} catch (err) {
$clipboardWrite = Permission.DENIED
}
})
}

Expand Down
Loading