aboutsummaryrefslogtreecommitdiff
path: root/events/tagevent.cpp
blob: 9f381c7618bacf6e1ed986abdc53e54036043037 (plain)
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
#include "tagevent.h"

using namespace QMatrixClient;

TagRecord::TagRecord(const QJsonObject& json)
    : order(json.value("order").toString())
{ }

TagEvent::TagEvent(const QJsonObject& obj)
    : Event(Type::Tag, obj)
{
    Q_ASSERT(obj["type"].toString() == TypeId);
}

QStringList TagEvent::tagNames() const
{
    return tagsObject().keys();
}

QHash<QString, TagRecord> TagEvent::tags() const
{
    QHash<QString, TagRecord> result;
    auto allTags { tagsObject() };
    for (auto it = allTags.begin(); it != allTags.end(); ++ it)
        result.insert(it.key(), TagRecord(it.value().toObject()));
    return result;
}

bool TagEvent::isFavourite() const
{
    return tagsObject().contains("m.favourite");
}

bool TagEvent::isLowPriority() const
{
    return tagsObject().contains("m.lowpriority");
}

QJsonObject TagEvent::tagsObject() const
{
    return contentJson().value("tags").toObject();
}