-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { BackendRemote, onDCEvent } from '../backend-com' | ||
import { selectedAccountId } from '../ScreenController' | ||
import { runtime } from '../runtime' | ||
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 | ||
|
||
type ComponentProps = { | ||
top: string | ||
left: string | ||
} | ||
|
||
export default function OtherAccountsUnreadBadge(props: ComponentProps) { | ||
const [ | ||
haveOtherAccountsUnread, | ||
setHaveOtherAccountsUnread, | ||
] = useState<boolean>(false) | ||
const [isSyncAllEnabled, setIsSyncAllEnabled] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
runtime | ||
.getDesktopSettings() | ||
.then((settings: DesktopSettingsType) => | ||
setIsSyncAllEnabled(settings.syncAllAccounts) | ||
) | ||
}) | ||
|
||
useEffect(() => { | ||
if (!isSyncAllEnabled) 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 | ||
}, [isSyncAllEnabled]) | ||
|
||
if (haveOtherAccountsUnread) { | ||
return <div className='unread-badge' style={{ ...props }} /> | ||
} else { | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters