Skip to content
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
5 changes: 5 additions & 0 deletions panels/notification/bubble/bubbleitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ uint BubbleItem::replacesId() const
return m_entity.replacesId();
}

bool BubbleItem::isReplace() const
{
return m_entity.isReplace();
}

int BubbleItem::urgency() const
{
return m_urgency;
Expand Down
1 change: 1 addition & 0 deletions panels/notification/bubble/bubbleitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BubbleItem : public QObject
QString summary() const;
QString body() const;
uint replacesId() const;
bool isReplace() const;
int urgency() const;
QString bodyImagePath() const;
qint64 ctime() const;
Expand Down
6 changes: 2 additions & 4 deletions panels/notification/bubble/bubblemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,13 @@ void BubbleModel::setDelayRemovedBubble(qint64 newDelayRemovedBubble)

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

const bool firstItem = item->replacesId() == NoReplaceId && item->bubbleId() == bubble->replacesId();
const bool laterItem = item->replacesId() == bubble->replacesId();
if (firstItem || laterItem) {
if (item->id() == bubble->id()) {
return i;
}
}
Expand Down
1 change: 0 additions & 1 deletion panels/notification/bubble/bubblemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class BubbleModel : public QAbstractListModel
QList<BubbleItem *> m_bubbles;
int BubbleMaxCount{3};
const int OverlayMaxCount{2};
const int NoReplaceId{0};
QList<qint64> m_delayBubbles;
qint64 m_delayRemovedBubble{-1};
const int DelayRemovBubbleTime{1000};
Expand Down
2 changes: 0 additions & 2 deletions panels/notification/bubble/bubblepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ void BubblePanel::addBubble(qint64 id)
if (m_bubbles->isReplaceBubble(bubble)) {
auto oldBubble = m_bubbles->replaceBubble(bubble);
if (oldBubble) {
QMetaObject::invokeMethod(m_notificationServer, "notificationReplaced", Qt::DirectConnection,
Q_ARG(qint64, oldBubble->id()));
oldBubble->deleteLater();
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion panels/notification/center/notifyitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void AppNotifyItem::updateStrongInteractive()
QMap<QString, QVariant>::const_iterator i = hints.constBegin();
while (i != hints.constEnd()) {
if (i.key() == QLatin1String("urgency")) {
ret = i.value().toString() == QLatin1String("SOH");
ret = i.value().toUInt() == NotifyEntity::Critical;
break;
}
++i;
Expand Down
19 changes: 18 additions & 1 deletion panels/notification/center/notifystagingmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ NotifyEntity NotifyStagingModel::notifyById(qint64 id) const
return {};
}

void NotifyStagingModel::replace(const NotifyEntity &entity)
{
for (int i = 0; i < m_appNotifies.size(); i++) {
auto item = m_appNotifies[i];
if (item->entity().id() == entity.id()) {
item->setEntity(entity);
const auto index = this->index(i, 0, {});
dataChanged(index, index);
break;
}
}
}

QHash<int, QByteArray> NotifyStagingModel::roleNames() const
{
static const QHash<int, QByteArray> roles{{NotifyItemType, "type"},
Expand Down Expand Up @@ -281,7 +294,11 @@ void NotifyStagingModel::doEntityReceived(qint64 id)
qWarning(notifyLog) << "Received invalid entity:" << id << ", appName:" << entity.appName();
return;
}
push(entity);
if (entity.isReplace() && notifyById(id).isValid()) {
replace(entity);
} else {
push(entity);
}
}

void NotifyStagingModel::onEntityClosed(qint64 id)
Expand Down
1 change: 1 addition & 0 deletions panels/notification/center/notifystagingmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class NotifyStagingModel : public QAbstractListModel

private slots:
void push(const NotifyEntity &entity);
void replace(const NotifyEntity &entity);
void doEntityReceived(qint64 id);
void onEntityClosed(qint64 id);

Expand Down
6 changes: 6 additions & 0 deletions panels/notification/common/dataaccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class DataAccessor
{
}
virtual qint64 addEntity(const NotifyEntity &entity) { Q_UNUSED(entity); return 0; }
virtual qint64 replaceEntity(qint64 id, const NotifyEntity &entity)
{
Q_UNUSED(id);
Q_UNUSED(entity);
return 0;
}

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

Expand Down
46 changes: 46 additions & 0 deletions panels/notification/common/dbaccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,52 @@
return storageId;
}

qint64 DBAccessor::replaceEntity(qint64 id, const NotifyEntity &entity)
{
BENCHMARK();

QMutexLocker locker(&m_mutex);
QSqlQuery query(m_connection);

QString columns = QStringList{QString("%1 = :icon").arg(ColumnIcon),
QString("%1 = :summary").arg(ColumnSummary),
QString("%1 = :body").arg(ColumnBody),
QString("%1 = :appName").arg(ColumnAppName),
QString("%1 = :appId").arg(ColumnAppId),
QString("%1 = :ctime").arg(ColumnCTime),
QString("%1 = :action").arg(ColumnAction),
QString("%1 = :hint").arg(ColumnHint),
QString("%1 = :replacesId").arg(ColumnReplacesId),
QString("%1 = :notifyId").arg(ColumnNotifyId),
QString("%1 = :processedType").arg(ColumnProcessedType)}
.join(", ");

QString sqlCmd = QString("UPDATE %1 SET %2 WHERE ID = :id").arg(TableName_v2).arg(columns);

query.prepare(sqlCmd);

Check warning on line 247 in panels/notification/common/dbaccessor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function query.prepare() is not used.
query.bindValue(":icon", entity.appIcon());
query.bindValue(":summary", entity.summary());
query.bindValue(":body", entity.body());
query.bindValue(":appName", entity.appName());
query.bindValue(":appId", entity.appId());
query.bindValue(":ctime", entity.cTime());
query.bindValue(":action", entity.actionsString());
query.bindValue(":hint", entity.hintsString());
query.bindValue(":replacesId", entity.replacesId());
query.bindValue(":notifyId", entity.bubbleId());
query.bindValue(":processedType", entity.processedType());
query.bindValue(":id", id);

if (!query.exec()) {
qWarning(notifyDBLog) << "Update value to database failed: " << query.lastError().text() << query.lastQuery() << entity.bubbleId() << entity.cTime();
return -1;
}

qDebug(notifyDBLog) << "Update entity bubbleId:" << entity.bubbleId() << ", id:" << id << ", affected rows:" << query.numRowsAffected();

return id;
}

void DBAccessor::updateEntityProcessedType(qint64 id, int processedType)
{
BENCHMARK();
Expand Down
1 change: 1 addition & 0 deletions panels/notification/common/dbaccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DBAccessor : public DataAccessor
bool open(const QString &dataPath);

qint64 addEntity(const NotifyEntity &entity) override;
qint64 replaceEntity(qint64 id, const NotifyEntity &entity) override;
void updateEntityProcessedType(qint64 id, int processedType) override;

NotifyEntity fetchEntity(qint64 id) override;
Expand Down
9 changes: 8 additions & 1 deletion panels/notification/common/notifyentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Q_LOGGING_CATEGORY(notifyLog, "dde.shell.notification")
#define HINT_SEGMENT ("|")
#define KEY_VALUE_SEGMENT ("!!!")

static const uint NoReplaceId = 0;

class NotifyData : public QSharedData
{
public:
Expand All @@ -31,7 +33,7 @@ class NotifyData : public QSharedData
QStringList actions;
QVariantMap hints;
uint bubbleId = 0;
uint replacesId = 0;
uint replacesId = NoReplaceId;
int expireTimeout = 0;

qint64 id = -1;
Expand Down Expand Up @@ -217,6 +219,11 @@ void NotifyEntity::setReplacesId(uint replacesId)
d->replacesId = replacesId;
}

bool NotifyEntity::isReplace() const
{
return d->replacesId != NoReplaceId;
}

qint64 NotifyEntity::cTime() const
{
return d->cTime;
Expand Down
1 change: 1 addition & 0 deletions panels/notification/common/notifyentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class NotifyEntity

uint replacesId() const;
void setReplacesId(uint replacesId);
bool isReplace() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

这个是不是hasReplaceId()更合适

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是直接替换了,不是跟之前的共存,跟之前的通知共用同一个id, 应该是is吧,


qint64 cTime() const;
void setCTime(qint64 cTime);
Expand Down
18 changes: 16 additions & 2 deletions panels/notification/server/notificationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
NotifyEntity entity(appName, replacesId, strIcon, summary, strBody, actions, hints, expireTimeout);
entity.setAppId(appId);
entity.setProcessedType(NotifyEntity::None);
entity.setReplacesId(replacesId);

bool lockScreenShow = true;
bool dndMode = isDoNotDisturb();
Expand Down Expand Up @@ -238,7 +239,20 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
}

if (entity.processedType() != NotifyEntity::None) {
qint64 id = m_persistence->addEntity(entity);
qint64 id = -1;
if (entity.isReplace()) {
auto lastEntity = m_persistence->fetchLastEntity(entity.bubbleId());
if (lastEntity.isValid()) {
removePendingEntity(entity);
id = m_persistence->replaceEntity(lastEntity.id(), entity);
} else {
qWarning() << "Not exist notification to replace for the replaceId" << replacesId;
}
}
if (id == -1) {
id = m_persistence->addEntity(entity);
}

if (id == -1) {
qWarning(notifyLog) << "Failed on saving DB, bubbleId:" << entity.bubbleId() << ", appName" << appName;
return 0;
Expand All @@ -260,7 +274,7 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
}
}

qInfo(notifyLog) << "Notify done, bubbleId:" << entity.bubbleId() << ", id:" << entity.id();
qInfo(notifyLog) << "Notify done, bubbleId:" << entity.bubbleId() << ", id:" << entity.id() << ", type:" << entity.processedType();

// If replaces_id is 0, the return value is a UINT32 that represent the notification.
// If replaces_id is not 0, the returned value is the same value as replaces_id.
Expand Down
9 changes: 2 additions & 7 deletions panels/notification/server/notifyserverapplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,12 @@ bool NotifyServerApplet::init()

void NotifyServerApplet::actionInvoked(qint64 id, uint bubbleId, const QString &actionKey)
{
QMetaObject::invokeMethod(m_manager, "actionInvoked", Qt::AutoConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(QString, actionKey));
QMetaObject::invokeMethod(m_manager, "actionInvoked", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(QString, actionKey));
}

void NotifyServerApplet::notificationClosed(qint64 id, uint bubbleId, uint reason)
{
QMetaObject::invokeMethod(m_manager, "notificationClosed", Qt::AutoConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(uint, reason));
}

void NotifyServerApplet::notificationReplaced(qint64 id)
{
QMetaObject::invokeMethod(m_manager, "notificationReplaced", Qt::AutoConnection, Q_ARG(qint64, id));
QMetaObject::invokeMethod(m_manager, "notificationClosed", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(uint, reason));
}

QVariant NotifyServerApplet::appValue(const QString &appId, int configItem)
Expand Down
1 change: 0 additions & 1 deletion panels/notification/server/notifyserverapplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class NotifyServerApplet : public DS_NAMESPACE::DApplet
public Q_SLOTS:
void actionInvoked(qint64 id, uint bubbleId, const QString &actionKey);
void notificationClosed(qint64 id, uint bubbleId, uint reason);
void notificationReplaced(qint64 id);
QVariant appValue(const QString &appId, int configItem);
void removeNotification(qint64 id);
void removeNotifications(const QString &appName);
Expand Down
Loading