feat: adds in notifications dot: updated setBadgeCount and using global unread message count

pull/3216/head
Emily 9 months ago
parent 16c7975719
commit 62300dcb5b

@ -1,3 +1,4 @@
import { ipcRenderer } from 'electron';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
@ -13,6 +14,8 @@ import { syncConfigurationIfNeeded } from '../../session/utils/sync/syncUtils';
import { clearSearch } from '../../state/ducks/search'; import { clearSearch } from '../../state/ducks/search';
import { resetLeftOverlayMode, SectionType, showLeftPaneSection } from '../../state/ducks/section'; import { resetLeftOverlayMode, SectionType, showLeftPaneSection } from '../../state/ducks/section';
import { import {
_getGlobalUnreadCount,
_getSortedConversations,
getGlobalUnreadMessageCount, getGlobalUnreadMessageCount,
getOurPrimaryConversation, getOurPrimaryConversation,
} from '../../state/selectors/conversations'; } from '../../state/selectors/conversations';
@ -37,18 +40,18 @@ import { LeftPaneSectionContainer } from './LeftPaneSectionContainer';
import { SettingsKey } from '../../data/settings-key'; import { SettingsKey } from '../../data/settings-key';
import { useFetchLatestReleaseFromFileServer } from '../../hooks/useFetchLatestReleaseFromFileServer'; import { useFetchLatestReleaseFromFileServer } from '../../hooks/useFetchLatestReleaseFromFileServer';
import { useHotkey } from '../../hooks/useHotkey';
import { import {
forceRefreshRandomSnodePool, forceRefreshRandomSnodePool,
getFreshSwarmFor, getFreshSwarmFor,
} from '../../session/apis/snode_api/snodePool'; } from '../../session/apis/snode_api/snodePool';
import { ConfigurationSync } from '../../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { ConfigurationSync } from '../../session/utils/job_runners/jobs/ConfigurationSyncJob';
import { getIsModalVisble } from '../../state/selectors/modal';
import { useIsDarkTheme } from '../../state/selectors/theme'; import { useIsDarkTheme } from '../../state/selectors/theme';
import { switchThemeTo } from '../../themes/switchTheme'; import { switchThemeTo } from '../../themes/switchTheme';
import { ReleasedFeatures } from '../../util/releaseFeature'; import { ReleasedFeatures } from '../../util/releaseFeature';
import { getOppositeTheme } from '../../util/theme'; import { getOppositeTheme } from '../../util/theme';
import { SessionNotificationCount } from '../icon/SessionNotificationCount'; import { SessionNotificationCount } from '../icon/SessionNotificationCount';
import { useHotkey } from '../../hooks/useHotkey';
import { getIsModalVisble } from '../../state/selectors/modal';
const Section = (props: { type: SectionType }) => { const Section = (props: { type: SectionType }) => {
const ourNumber = useSelector(getOurNumber); const ourNumber = useSelector(getOurNumber);
@ -216,6 +219,12 @@ const doAppStartUp = async () => {
}, 20000); }, 20000);
}; };
global.setTimeout(() => {
const unreadMessageCount = useSelector(getGlobalUnreadMessageCount);
// Send the calculated count to the main process to update the badge count
ipcRenderer.send('update-badge-count', unreadMessageCount);
}, 3000);
/** /**
* ActionsPanel is the far left banner (not the left pane). * ActionsPanel is the far left banner (not the left pane).
* The panel with buttons to switch between the message/contact/settings/theme views * The panel with buttons to switch between the message/contact/settings/theme views

@ -10,6 +10,7 @@ import {
dialog, dialog,
protocol as electronProtocol, protocol as electronProtocol,
ipcMain as ipc, ipcMain as ipc,
ipcMain,
IpcMainEvent, IpcMainEvent,
Menu, Menu,
nativeTheme, nativeTheme,
@ -1023,6 +1024,14 @@ ipc.on('get-start-in-tray', event => {
} }
}); });
ipcMain.on('update-badge-count', (_event, count) => {
if (count === 0) {
app.setBadgeCount(0); // Clear the badge
} else {
app.setBadgeCount(count); // Set the badge count
}
});
ipc.on('get-opengroup-pruning', event => { ipc.on('get-opengroup-pruning', event => {
try { try {
const val = userConfig.get('opengroupPruning'); const val = userConfig.get('opengroupPruning');

@ -306,7 +306,9 @@ const _getContacts = (
}); });
}; };
const _getGlobalUnreadCount = (sortedConversations: Array<ReduxConversationType>): number => { export const _getGlobalUnreadCount = (
sortedConversations: Array<ReduxConversationType>
): number => {
let globalUnreadCount = 0; let globalUnreadCount = 0;
for (const conversation of sortedConversations) { for (const conversation of sortedConversations) {
// Blocked conversation are now only visible from the settings, not in the conversation list, so don't add it neither to the contacts list nor the conversation list // Blocked conversation are now only visible from the settings, not in the conversation list, so don't add it neither to the contacts list nor the conversation list

Loading…
Cancel
Save