~aleteoryx/muditaos

muditaos/module-services/service-desktop/OutboxNotifications.cpp -rw-r--r-- 2.2 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include <service-desktop/OutboxNotifications.hpp>

auto OutboxNotifications::getNotificationEntries() const -> std::vector<Outbox::NotificationEntry>
{
    return notificationEntries;
}

void OutboxNotifications::removeNotificationEntries(const std::vector<uint32_t> &uidsOfNotificationsToBeRemoved)
{
    for (auto const &entryUid : uidsOfNotificationsToBeRemoved) {
        notificationEntries.erase(
            std::remove_if(notificationEntries.begin(),
                           notificationEntries.end(),
                           [&](const Outbox::NotificationEntry &entry) { return entry.uid == entryUid; }),
            notificationEntries.end());
    }
}

void OutboxNotifications::clearNotifications()
{
    notificationEntries.clear();
    notificationCurrentUid = 0;
}

void OutboxNotifications::newNotificationHandler(db::NotificationMessage *notificationMessage)
{
    auto entryType = Outbox::EntryType::INVALID;
    switch (notificationMessage->interface) {
    case db::Interface::Name::Contact:
        entryType = Outbox::EntryType::CONTACT;
        break;
    case db::Interface::Name::SMS:
        entryType = Outbox::EntryType::MESSAGE;
        break;
    case db::Interface::Name::SMSThread:
        entryType = Outbox::EntryType::THREAD;
        break;
    default:
        break;
    }

    auto entryChange = Outbox::EntryChange::INVALID;
    switch (notificationMessage->type) {
    case db::Query::Type::Create:
        entryChange = Outbox::EntryChange::CREATED;
        break;
    case db::Query::Type::Update:
        entryChange = Outbox::EntryChange::UPDATED;
        break;
    case db::Query::Type::Delete:
        entryChange = Outbox::EntryChange::DELETED;
        break;
    default:
        break;
    }

    if (entryType != Outbox::EntryType::INVALID && entryChange != Outbox::EntryChange::INVALID &&
        notificationMessage->recordId) {
        Outbox::NotificationEntry newNotificationEntry = {
            notificationCurrentUid++, entryType, entryChange, *notificationMessage->recordId};
        notificationEntries.emplace_back(newNotificationEntry);
    }
}