Skip to content

Commit

Permalink
fix(chat): fix chat in nav bar (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flemmli97 authored Dec 9, 2024
1 parent d788d5d commit 6eb4ec1
Showing 1 changed file with 18 additions and 21 deletions.
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

0 comments on commit 6eb4ec1

Please sign in to comment.