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

Ignore notification close event & clear notifications when marking accounts unread chat as noticed #4010

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- Fix the problem of Quit menu item on WebXDC apps closes the whole DC app #3995
- minor performance improvements #3981
- fix chat list items (e.g. Archive) and contacts not showing up sometimes #4004
- fix bug notifications not being removed on Mac #4010
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you forgot to mention the fix for clear account notifications

- fix bug "Mark All as Read" does not remove notifications #4002

<a id="1_46_1"></a>

Expand Down
11 changes: 9 additions & 2 deletions src/main/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ function showNotification(_event: IpcMainInvokeEvent, data: DcNotification) {
notify.close()
})
notify.on('close', () => {
notifications[chatId] =
notifications[chatId]?.filter(n => n !== notify) || []
// on Window and Linux this can be triggered by system time out
// when the message is moved to notification center so only close
// the notification on this event on Mac
if (isMac) {
notifications[chatId] =
notifications[chatId]?.filter(n => n !== notify) || []
}
/* ignore-console-log */
console.log('Notification close event triggered', notify)
})

if (notifications[chatId]) {
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/backend-com.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export namespace EffectfulBackendActions {
await BackendRemote.rpc.deleteChat(accountId, chatId)
clearNotificationsForChat(accountId, chatId)
}

export async function marknoticedChat(accountId: number, chatId: number) {
await BackendRemote.rpc.marknoticedChat(accountId, chatId)
clearNotificationsForChat(accountId, chatId)
}
}

type ContextEvents = { ALL: (event: DcEvent) => void } & {
Expand Down
14 changes: 8 additions & 6 deletions src/renderer/components/AccountListSidebar/AccountItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React, { useEffect, useState } from 'react'
import classNames from 'classnames'
import debounce from 'debounce'

import { BackendRemote, onDCEvent } from '../../backend-com'
import {
BackendRemote,
onDCEvent,
EffectfulBackendActions,
} from '../../backend-com'
import { avatarInitial } from '../Avatar'
import { getLogger } from '../../../shared/logger'
import useTranslationFunction from '../../hooks/useTranslationFunction'
Expand Down Expand Up @@ -201,9 +205,7 @@ async function markAccountAsRead(accountId: number) {
}
}

await Promise.all(
[...uniqueChatIds].map(chatId =>
BackendRemote.rpc.marknoticedChat(accountId, chatId)
)
)
for (const chatId of uniqueChatIds) {
await EffectfulBackendActions.marknoticedChat(accountId, chatId)
}
}
4 changes: 2 additions & 2 deletions src/renderer/components/chat/ChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { T, C } from '@deltachat/jsonrpc-client'

import Timestamp from '../conversations/Timestamp'
import { Avatar } from '../Avatar'
import { BackendRemote, Type } from '../../backend-com'
import { Type, EffectfulBackendActions } from '../../backend-com'
import { mapCoreMsgStatus2String } from '../helpers/MapMsgStatus'
import { getLogger } from '../../../shared/logger'
import { useContextMenuWithActiveState } from '../ContextMenu'
Expand Down Expand Up @@ -150,7 +150,7 @@ function ChatListItemArchiveLink({
{
label: tx('mark_all_as_read'),
action: () => {
BackendRemote.rpc.marknoticedChat(
EffectfulBackendActions.marknoticedChat(
selectedAccountId(),
C.DC_CHAT_ID_ARCHIVED_LINK
)
Expand Down
Loading