Skip to content

Commit 94936f5

Browse files
18202781743deepin-bot[bot]
authored andcommitted
fix: stage doens't adapt replace notify for notification
Notify server adapt replace notify, it will override old notify both DB data and timeout data, and emit NotificationStateChanged. pms: BUG-289863
1 parent 0c07d2c commit 94936f5

16 files changed

+108
-20
lines changed

panels/notification/bubble/bubbleitem.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ uint BubbleItem::replacesId() const
216216
return m_entity.replacesId();
217217
}
218218

219+
bool BubbleItem::isReplace() const
220+
{
221+
return m_entity.isReplace();
222+
}
223+
219224
int BubbleItem::urgency() const
220225
{
221226
return m_urgency;

panels/notification/bubble/bubbleitem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class BubbleItem : public QObject
3030
QString summary() const;
3131
QString body() const;
3232
uint replacesId() const;
33+
bool isReplace() const;
3334
int urgency() const;
3435
QString bodyImagePath() const;
3536
qint64 ctime() const;

panels/notification/bubble/bubblemodel.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,13 @@ void BubbleModel::setDelayRemovedBubble(qint64 newDelayRemovedBubble)
271271

272272
int BubbleModel::replaceBubbleIndex(const BubbleItem *bubble) const
273273
{
274-
if (bubble->replacesId() != NoReplaceId) {
274+
if (bubble->isReplace()) {
275275
for (int i = 0; i < m_bubbles.size(); i++) {
276276
auto item = m_bubbles[i];
277277
if (item->appName() != bubble->appName())
278278
continue;
279279

280-
const bool firstItem = item->replacesId() == NoReplaceId && item->bubbleId() == bubble->replacesId();
281-
const bool laterItem = item->replacesId() == bubble->replacesId();
282-
if (firstItem || laterItem) {
280+
if (item->id() == bubble->id()) {
283281
return i;
284282
}
285283
}

panels/notification/bubble/bubblemodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class BubbleModel : public QAbstractListModel
7676
QList<BubbleItem *> m_bubbles;
7777
int BubbleMaxCount{3};
7878
const int OverlayMaxCount{2};
79-
const int NoReplaceId{0};
8079
QList<qint64> m_delayBubbles;
8180
qint64 m_delayRemovedBubble{-1};
8281
const int DelayRemovBubbleTime{1000};

panels/notification/bubble/bubblepanel.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ void BubblePanel::addBubble(qint64 id)
134134
if (m_bubbles->isReplaceBubble(bubble)) {
135135
auto oldBubble = m_bubbles->replaceBubble(bubble);
136136
if (oldBubble) {
137-
QMetaObject::invokeMethod(m_notificationServer, "notificationReplaced", Qt::DirectConnection,
138-
Q_ARG(qint64, oldBubble->id()));
139137
oldBubble->deleteLater();
140138
}
141139
} else {

panels/notification/center/notifyitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void AppNotifyItem::updateStrongInteractive()
157157
QMap<QString, QVariant>::const_iterator i = hints.constBegin();
158158
while (i != hints.constEnd()) {
159159
if (i.key() == QLatin1String("urgency")) {
160-
ret = i.value().toString() == QLatin1String("SOH");
160+
ret = i.value().toUInt() == NotifyEntity::Critical;
161161
break;
162162
}
163163
++i;

panels/notification/center/notifystagingmodel.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ NotifyEntity NotifyStagingModel::notifyById(qint64 id) const
237237
return {};
238238
}
239239

240+
void NotifyStagingModel::replace(const NotifyEntity &entity)
241+
{
242+
for (int i = 0; i < m_appNotifies.size(); i++) {
243+
auto item = m_appNotifies[i];
244+
if (item->entity().id() == entity.id()) {
245+
item->setEntity(entity);
246+
const auto index = this->index(i, 0, {});
247+
dataChanged(index, index);
248+
break;
249+
}
250+
}
251+
}
252+
240253
QHash<int, QByteArray> NotifyStagingModel::roleNames() const
241254
{
242255
static const QHash<int, QByteArray> roles{{NotifyItemType, "type"},
@@ -281,7 +294,11 @@ void NotifyStagingModel::doEntityReceived(qint64 id)
281294
qWarning(notifyLog) << "Received invalid entity:" << id << ", appName:" << entity.appName();
282295
return;
283296
}
284-
push(entity);
297+
if (entity.isReplace() && notifyById(id).isValid()) {
298+
replace(entity);
299+
} else {
300+
push(entity);
301+
}
285302
}
286303

287304
void NotifyStagingModel::onEntityClosed(qint64 id)

panels/notification/center/notifystagingmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class NotifyStagingModel : public QAbstractListModel
5454

5555
private slots:
5656
void push(const NotifyEntity &entity);
57+
void replace(const NotifyEntity &entity);
5758
void doEntityReceived(qint64 id);
5859
void onEntityClosed(qint64 id);
5960

panels/notification/common/dataaccessor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class DataAccessor
1818
{
1919
}
2020
virtual qint64 addEntity(const NotifyEntity &entity) { Q_UNUSED(entity); return 0; }
21+
virtual qint64 replaceEntity(qint64 id, const NotifyEntity &entity)
22+
{
23+
Q_UNUSED(id);
24+
Q_UNUSED(entity);
25+
return 0;
26+
}
2127

2228
virtual void updateEntityProcessedType(qint64 id, int processedType) { Q_UNUSED(id); Q_UNUSED(processedType); }
2329

panels/notification/common/dbaccessor.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,52 @@ qint64 DBAccessor::addEntity(const NotifyEntity &entity)
222222
return storageId;
223223
}
224224

225+
qint64 DBAccessor::replaceEntity(qint64 id, const NotifyEntity &entity)
226+
{
227+
BENCHMARK();
228+
229+
QMutexLocker locker(&m_mutex);
230+
QSqlQuery query(m_connection);
231+
232+
QString columns = QStringList{QString("%1 = :icon").arg(ColumnIcon),
233+
QString("%1 = :summary").arg(ColumnSummary),
234+
QString("%1 = :body").arg(ColumnBody),
235+
QString("%1 = :appName").arg(ColumnAppName),
236+
QString("%1 = :appId").arg(ColumnAppId),
237+
QString("%1 = :ctime").arg(ColumnCTime),
238+
QString("%1 = :action").arg(ColumnAction),
239+
QString("%1 = :hint").arg(ColumnHint),
240+
QString("%1 = :replacesId").arg(ColumnReplacesId),
241+
QString("%1 = :notifyId").arg(ColumnNotifyId),
242+
QString("%1 = :processedType").arg(ColumnProcessedType)}
243+
.join(", ");
244+
245+
QString sqlCmd = QString("UPDATE %1 SET %2 WHERE ID = :id").arg(TableName_v2).arg(columns);
246+
247+
query.prepare(sqlCmd);
248+
query.bindValue(":icon", entity.appIcon());
249+
query.bindValue(":summary", entity.summary());
250+
query.bindValue(":body", entity.body());
251+
query.bindValue(":appName", entity.appName());
252+
query.bindValue(":appId", entity.appId());
253+
query.bindValue(":ctime", entity.cTime());
254+
query.bindValue(":action", entity.actionsString());
255+
query.bindValue(":hint", entity.hintsString());
256+
query.bindValue(":replacesId", entity.replacesId());
257+
query.bindValue(":notifyId", entity.bubbleId());
258+
query.bindValue(":processedType", entity.processedType());
259+
query.bindValue(":id", id);
260+
261+
if (!query.exec()) {
262+
qWarning(notifyDBLog) << "Update value to database failed: " << query.lastError().text() << query.lastQuery() << entity.bubbleId() << entity.cTime();
263+
return -1;
264+
}
265+
266+
qDebug(notifyDBLog) << "Update entity bubbleId:" << entity.bubbleId() << ", id:" << id << ", affected rows:" << query.numRowsAffected();
267+
268+
return id;
269+
}
270+
225271
void DBAccessor::updateEntityProcessedType(qint64 id, int processedType)
226272
{
227273
BENCHMARK();

0 commit comments

Comments
 (0)