mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
more fixes
This commit is contained in:
@@ -141,6 +141,14 @@ public:
|
||||
capLengths(notification);
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (notification.externalId != 0) {
|
||||
for (auto it = entries.begin(); it != entries.end();) {
|
||||
if (it->externalId == notification.externalId)
|
||||
it = entries.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
notification.id = nextId++;
|
||||
notification.unread = true;
|
||||
|
||||
@@ -187,6 +195,23 @@ public:
|
||||
++revisionCounter;
|
||||
}
|
||||
|
||||
void removeByExternalId(std::uint64_t externalId) override {
|
||||
if (externalId == 0)
|
||||
return;
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
bool removed = false;
|
||||
for (auto it = entries.begin(); it != entries.end();) {
|
||||
if (it->externalId == externalId) {
|
||||
it = entries.erase(it);
|
||||
removed = true;
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
if (removed)
|
||||
++revisionCounter;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr std::size_t kMaxEntries = 8;
|
||||
static constexpr std::size_t kMaxTitleBytes = 96;
|
||||
|
||||
@@ -175,6 +175,15 @@ PendingNotification& ensurePending(uint32_t uid) {
|
||||
return pending;
|
||||
}
|
||||
|
||||
void discardPending(uint32_t uid) {
|
||||
for (auto it = g_pendingNotifications.begin(); it != g_pendingNotifications.end(); ++it) {
|
||||
if (it->uid == uid) {
|
||||
g_pendingNotifications.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void finalizePending(uint32_t uid) {
|
||||
if (!g_notificationCenter)
|
||||
return;
|
||||
@@ -184,6 +193,7 @@ void finalizePending(uint32_t uid) {
|
||||
|
||||
cardboy::sdk::INotificationCenter::Notification note{};
|
||||
note.timestamp = static_cast<std::uint64_t>(time(nullptr));
|
||||
note.externalId = uid;
|
||||
if (!it->title.empty()) {
|
||||
note.title = it->title;
|
||||
} else if (!it->appIdentifier.empty()) {
|
||||
@@ -975,7 +985,9 @@ void handleAncsNotificationSource(uint16_t connHandle, const uint8_t* data, uint
|
||||
uid);
|
||||
|
||||
if (eventId == 2) { // Removed
|
||||
finalizePending(uid);
|
||||
discardPending(uid);
|
||||
g_notificationCenter->removeByExternalId(uid);
|
||||
ESP_LOGI(kLogTag, "Cleared notification uid=%" PRIu32, uid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user