mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 11:42:30 +03:00
Freeze chat autoscroll and notifications read when the window is out of focus (#6971)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
This commit is contained in:
parent
a0b9a9830b
commit
49f608bc98
@ -104,6 +104,7 @@
|
||||
|
||||
let isPageHidden = false
|
||||
let lastMsgBeforeFreeze: Ref<ActivityMessage> | undefined = undefined
|
||||
let needUpdateTimestamp = false
|
||||
|
||||
$: messages = $messagesStore
|
||||
$: notifyContext = $contextByDocStore.get(doc._id)
|
||||
@ -149,14 +150,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleWindowFocus (): void {
|
||||
checkWindowVisibility(false)
|
||||
}
|
||||
|
||||
function handleWindowBlur (): void {
|
||||
checkWindowVisibility(true)
|
||||
}
|
||||
|
||||
function handleVisibilityChange (): void {
|
||||
if (document.hidden) {
|
||||
checkWindowVisibility(document.hidden)
|
||||
}
|
||||
|
||||
function checkWindowVisibility (hidden: boolean): void {
|
||||
if (document.hidden || !document.hasFocus() || hidden) {
|
||||
if (isPageHidden) return
|
||||
isPageHidden = true
|
||||
needUpdateTimestamp = true
|
||||
lastMsgBeforeFreeze = shouldScrollToNew ? messages[messages.length - 1]?._id : undefined
|
||||
} else {
|
||||
if (isPageHidden) {
|
||||
isPageHidden = false
|
||||
void provider.updateNewTimestamp(notifyContext)
|
||||
needUpdateTimestamp = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,7 +230,10 @@
|
||||
|
||||
function scrollToStartOfNew (): void {
|
||||
if (scrollDiv == null || lastMsgBeforeFreeze === undefined) return
|
||||
|
||||
if (needUpdateTimestamp) {
|
||||
void provider.updateNewTimestamp(notifyContext)
|
||||
needUpdateTimestamp = false
|
||||
}
|
||||
const lastIndex = messages.findIndex(({ _id }) => _id === lastMsgBeforeFreeze)
|
||||
if (lastIndex === -1) return
|
||||
const firstNewMessage = messages.find(({ createdBy }, index) => index > lastIndex && createdBy !== me._id)
|
||||
@ -545,12 +563,16 @@
|
||||
onMount(() => {
|
||||
chatReadMessagesStore.update(() => new Set())
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange)
|
||||
window.addEventListener('focus', handleWindowFocus)
|
||||
window.addEventListener('blur', handleWindowBlur)
|
||||
addTxListener(newMessageTxListener)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
unsubscribe()
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange)
|
||||
window.removeEventListener('focus', handleWindowFocus)
|
||||
window.removeEventListener('blur', handleWindowBlur)
|
||||
removeTxListener(newMessageTxListener)
|
||||
})
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user