mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 15:17:48 +01:00
remove notifications
This commit is contained in:
@@ -195,6 +195,23 @@ public:
|
|||||||
++revisionCounter;
|
++revisionCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeById(std::uint64_t id) override {
|
||||||
|
if (id == 0)
|
||||||
|
return;
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
bool removed = false;
|
||||||
|
for (auto it = entries.begin(); it != entries.end();) {
|
||||||
|
if (it->id == id) {
|
||||||
|
it = entries.erase(it);
|
||||||
|
removed = true;
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removed)
|
||||||
|
++revisionCounter;
|
||||||
|
}
|
||||||
|
|
||||||
void removeByExternalId(std::uint64_t externalId) override {
|
void removeByExternalId(std::uint64_t externalId) override {
|
||||||
if (externalId == 0)
|
if (externalId == 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -130,6 +130,25 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool deletePressed = button.current.b && !button.previous.b;
|
||||||
|
if (deletePressed && notificationCenter && !notifications.empty()) {
|
||||||
|
const std::size_t index = std::min<std::size_t>(selectedNotification, notifications.size() - 1);
|
||||||
|
const auto& note = notifications[index];
|
||||||
|
std::size_t preferredIndex = index;
|
||||||
|
if (index + 1 < notifications.size())
|
||||||
|
preferredIndex = index + 1;
|
||||||
|
else if (index > 0)
|
||||||
|
preferredIndex = index - 1;
|
||||||
|
if (note.externalId != 0)
|
||||||
|
notificationCenter->removeByExternalId(note.externalId);
|
||||||
|
else
|
||||||
|
notificationCenter->removeById(note.id);
|
||||||
|
selectedNotification = preferredIndex;
|
||||||
|
lastNotificationInteractionMs = clock.millis();
|
||||||
|
dirty = true;
|
||||||
|
refreshNotifications();
|
||||||
|
}
|
||||||
|
|
||||||
const bool comboNow = comboPressed(button.current);
|
const bool comboNow = comboPressed(button.current);
|
||||||
updateHoldState(comboNow);
|
updateHoldState(comboNow);
|
||||||
if (navPressed)
|
if (navPressed)
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public:
|
|||||||
[[nodiscard]] virtual std::vector<Notification> recent(std::size_t limit) const = 0;
|
[[nodiscard]] virtual std::vector<Notification> recent(std::size_t limit) const = 0;
|
||||||
virtual void markAllRead() = 0;
|
virtual void markAllRead() = 0;
|
||||||
virtual void clear() = 0;
|
virtual void clear() = 0;
|
||||||
|
virtual void removeById(std::uint64_t id) = 0;
|
||||||
virtual void removeByExternalId(std::uint64_t externalId) = 0;
|
virtual void removeByExternalId(std::uint64_t externalId) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ public:
|
|||||||
[[nodiscard]] std::vector<Notification> recent(std::size_t limit) const override;
|
[[nodiscard]] std::vector<Notification> recent(std::size_t limit) const override;
|
||||||
void markAllRead() override;
|
void markAllRead() override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
void removeById(std::uint64_t id) override;
|
||||||
void removeByExternalId(std::uint64_t externalId) override;
|
void removeByExternalId(std::uint64_t externalId) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -212,6 +212,23 @@ void DesktopNotificationCenter::clear() {
|
|||||||
++revisionCounter;
|
++revisionCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DesktopNotificationCenter::removeById(std::uint64_t id) {
|
||||||
|
if (id == 0)
|
||||||
|
return;
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
bool removed = false;
|
||||||
|
for (auto it = entries.begin(); it != entries.end();) {
|
||||||
|
if (it->id == id) {
|
||||||
|
it = entries.erase(it);
|
||||||
|
removed = true;
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removed)
|
||||||
|
++revisionCounter;
|
||||||
|
}
|
||||||
|
|
||||||
void DesktopNotificationCenter::removeByExternalId(std::uint64_t externalId) {
|
void DesktopNotificationCenter::removeByExternalId(std::uint64_t externalId) {
|
||||||
if (externalId == 0)
|
if (externalId == 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user