@@ -252,26 +252,13 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
252252 }
253253
254254 if (entity.processedType () != NotifyEntity::None) {
255- qint64 id = -1 ;
256- if (entity.isReplace ()) {
257- auto lastEntity = m_persistence->fetchLastEntity (entity.bubbleId ());
258- if (lastEntity.isValid ()) {
259- removePendingEntity (entity);
260- id = m_persistence->replaceEntity (lastEntity.id (), entity);
261- } else {
262- qWarning () << " Not exist notification to replace for the replaceId" << replacesId;
263- }
264- }
265- if (id == -1 ) {
266- id = m_persistence->addEntity (entity);
267- }
268-
269- if (id == -1 ) {
270- qWarning (notifyLog) << " Failed on saving DB, bubbleId:" << entity.bubbleId () << " , appName" << appName;
255+ if (!recordNotification (entity)) {
271256 return 0 ;
272257 }
273258
274- entity.setId (id);
259+ if (entity.isReplace () && m_persistence->fetchLastEntity (entity.bubbleId ()).isValid ()) {
260+ removePendingEntity (entity);
261+ }
275262
276263 emitRecordCountChanged ();
277264
@@ -372,6 +359,39 @@ bool NotificationManager::isDoNotDisturb() const
372359 return dndMode && m_setting->systemValue (NotificationSetting::OpenByTimeInterval).toBool ();
373360}
374361
362+ bool NotificationManager::recordNotification (NotifyEntity &entity)
363+ {
364+ qint64 id = -1 ;
365+ if (entity.isReplace ()) {
366+ auto lastEntity = m_persistence->fetchLastEntity (entity.bubbleId ());
367+ if (lastEntity.isValid ()) {
368+ bool showInNotifyCenter = true ;
369+ if (entity.hints ().contains (" x-deepin-ShowInNotifyCenter" )) {
370+ showInNotifyCenter = entity.hints ()[" x-deepin-ShowInNotifyCenter" ].toBool ();
371+ }
372+ if (showInNotifyCenter) {
373+ m_persistence->updateEntityProcessedType (lastEntity.id (), NotifyEntity::Processed);
374+ } else {
375+ id = m_persistence->replaceEntity (lastEntity.id (), entity);
376+ }
377+ } else {
378+ qWarning () << " Not exist notification to replace for the replaceId" << entity.replacesId ();
379+ }
380+ }
381+ if (id == -1 ) {
382+ id = m_persistence->addEntity (entity);
383+ }
384+
385+ if (id == -1 ) {
386+ qWarning (notifyLog) << " Failed on saving DB, bubbleId:" << entity.bubbleId () << " , appName" << entity.appName ();
387+ return false ;
388+ }
389+
390+ entity.setId (id);
391+
392+ return true ;
393+ }
394+
375395void NotificationManager::tryPlayNotificationSound (const NotifyEntity &entity, const QString &appId, bool dndMode) const
376396{
377397 const auto hints = entity.hints ();
@@ -445,7 +465,10 @@ void NotificationManager::updateEntityProcessed(const NotifyEntity &entity)
445465{
446466 const auto id = entity.id ();
447467 const bool removed = entity.processedType () == NotifyEntity::Removed;
448- const auto showInCenter = m_setting->appValue (entity.appId (), NotificationSetting::ShowInCenter).toBool ();
468+ bool showInCenter = m_setting->appValue (entity.appId (), NotificationSetting::ShowInCenter).toBool ();
469+ if (entity.hints ().contains (" x-deepin-ShowInNotifyCenter" )) {
470+ showInCenter = entity.hints ()[" x-deepin-ShowInNotifyCenter" ].toBool ();
471+ }
449472 // "cancel"表示正在发送蓝牙文件,不需要发送到通知中心
450473 const auto bluetooth = entity.body ().contains (" %" ) && entity.actions ().contains (" cancel" );
451474 const bool removeEntity = removed || !showInCenter || bluetooth;
0 commit comments