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

Show an unread badge when there are unread notifs from other accounts #3398

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Added

- Add an unread badge if there are unread notifs from other accounts

### Changed

### Fixed
Expand Down
20 changes: 20 additions & 0 deletions scss/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,23 @@
-webkit-transform: translateX(-100%);
}
}

@keyframes unread-badge-bg-anim {
from {
background-color: var(--unreadBadgeColor1);
}
to {
background-color: var(--unreadBadgeColor2);
}
}
div.unread-badge {
width: 14px;
height: 14px;
border-radius: 50%;
position: relative;
animation-duration: 1.5s;
animation-name: unread-badge-bg-anim;
animation-iteration-count: infinite;
animation-direction: alternate;
background-color: var(--unreadBadgeColor1);
}
57 changes: 57 additions & 0 deletions src/renderer/components/OtherAccountsUnreadBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useEffect, useState } from 'react'
import { BackendRemote, onDCEvent } from '../backend-com'
import { selectedAccountId } from '../ScreenController'
import { runtime } from '../runtime'
import { useSettingsStore } from '../stores/settings'
import { DesktopSettingsType } from '../../shared/shared-types'

// Tip of the Day: Keep as many ice creams as you can in your fridge
// for the ice cream outage days. FREE ICE CREAM FOR EVERY1! --Farooq
farooqkz marked this conversation as resolved.
Show resolved Hide resolved

type ComponentProps = {
top: string
left: string
}

export default function OtherAccountsUnreadBadge(props: ComponentProps) {
const [
haveOtherAccountsUnread,
setHaveOtherAccountsUnread,
] = useState<boolean>(false)

const settings = useSettingsStore()[0]

useEffect(() => {
if (settings === null) return
if (settings.desktopSettings.syncAllAccounts === false) return
let updating = false
const update = () => {
if (updating) return
updating = true
BackendRemote.rpc.getAllAccountIds().then(accountIds => {
accountIds = accountIds.filter(id => id !== selectedAccountId())
for (const accountId of accountIds) {
BackendRemote.rpc.getFreshMsgs(accountId).then(ids => {
if (ids.length > 0) setHaveOtherAccountsUnread(true)
})
}
})
updating = false
}
update()

BackendRemote.rpc
.getAllAccountIds()
.then(accountIds =>
accountIds.map(id => onDCEvent(id, 'IncomingMsg', update))
)

return update
}, [settings])
farooqkz marked this conversation as resolved.
Show resolved Hide resolved

if (settings && settings.desktopSettings.syncAllAccounts && haveOtherAccountsUnread) {
return <div className='unread-badge' style={{ ...props }} />
} else {
return null
}
}
2 changes: 2 additions & 0 deletions src/renderer/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EffectfulBackendActions,
onDCEvent,
} from '../backend-com'
import OtherAccountsUnreadBadge from './OtherAccountsUnreadBadge'

export type SidebarState = 'init' | 'visible' | 'invisible'

Expand Down Expand Up @@ -180,6 +181,7 @@ const Sidebar = React.memo(
</div>
<div key='logout' className='sidebar-item' onClick={onLogout}>
{tx('switch_account')}
<OtherAccountsUnreadBadge top='-38px' left='-14px' />
</div>
<div className='footer'>
<Link href='https://delta.chat' label={'Delta Chat Desktop'} />
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/screens/MainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ import SettingsStoreInstance, { useSettingsStore } from '../../stores/settings'
import { Type } from '../../backend-com'
import { InlineVerifiedIcon } from '../VerifiedIcon'
import { SettingsProfileDialog } from '../dialogs/Settings-Profile'
import OtherAccountsUnreadBadge from '../OtherAccountsUnreadBadge'

const log = getLogger('renderer/main-screen')

export default function MainScreen() {
const [queryStr, setQueryStr] = useState('')
const [queryChatId, setQueryChatId] = useState<null | number>(null)
const [sidebarState, setSidebarState] = useState<SidebarState>('init')
const [showArchivedChats, setShowArchivedChats] = useState(false)
const [showArchivedChats, setShowArchivedChats] = useState<boolean>(false)

// Small hack/misuse of keyBindingAction to setShowArchivedChats from other components (especially
// ViewProfile when selecting a shared chat/group)
useKeyBindingAction(KeybindAction.ChatList_SwitchToArchiveView, () =>
Expand Down Expand Up @@ -202,6 +204,7 @@ export default function MainScreen() {
id='hamburger-menu-button'
>
<Icon icon='menu' aria-label={tx('main_menu')} iconSize={20} />
<OtherAccountsUnreadBadge top='-26px' left='14px' />
</div>
{queryStr.length === 0 && showArchivedChats && (
<>
Expand Down
3 changes: 3 additions & 0 deletions themes/_themebase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ $hover-contrast-change: 2%;
--ovalButtonBgHover: #{changeContrast($ovalButtonBg, 70%)};
--ovalButtonText: #{$ovalButtonText};
--ovalButtonTextHover: #{desaturate(invert($ovalButtonText), 1)};
/* UnreadBadge */
--unreadBadgeColor1: #{$colorPrimary};
--unreadBadgeColor2: mix(#{$colorPrimary}, transparent, 20%);
/* NavBar */
--navBarBackground: #{$bgNavBar};
--navBarText: #{$textNavBar};
Expand Down