libkazv
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1/*
2 * This file is part of libkazv.
3 * SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
4 * SPDX-License-Identifier: AGPL-3.0-or-later
5 */
6
7
8#pragma once
9#include "libkazv-config.hpp"
10
11#include <string>
12#include <cstdint>
13
14#include "jsonwrap.hpp"
15
16namespace Kazv
17{
18 using Timestamp = std::int_fast64_t;
19
20 class Event
21 {
22 public:
24
29
30 Event();
31
32 Event(JsonWrap j);
33
34 static Event fromSync(Event e, std::string roomId);
35
37 std::string id() const;
38
39 std::string sender() const;
40
42
43 std::string type() const;
44
45 std::string stateKey() const;
46
52 bool isState() const;
53
54 JsonWrap content() const;
55
57 JsonWrap raw() const;
58
60 JsonWrap originalJson() const;
61
62 JsonWrap decryptedJson() const;
63
64 bool encrypted() const;
65
66 bool decrypted() const;
67
70
72 bool redacted() const;
73
80 std::string replyingTo() const;
81
88 std::pair<std::string/* relType */, std::string/* eventId */> relationship() const;
89
95 JsonWrap mRelatesTo() const;
96
97 template<class Archive>
98 void serialize(Archive &ar, std::uint32_t const /*version*/ ) {
99 ar & m_json & m_decryptedJson & m_decrypted & m_encrypted;
100 }
101
102 friend bool operator==(const Event &a, const Event &b);
103 inline friend bool operator!=(const Event &a, const Event &b) { return !(a == b); };
104
105 private:
106 JsonWrap m_json;
107 JsonWrap m_decryptedJson;
108 DecryptionStatus m_decrypted{NotDecrypted};
109 bool m_encrypted{false};
110 };
111}
112
113BOOST_CLASS_VERSION(Kazv::Event, 0)
114
115namespace nlohmann
116{
117 template <>
118 struct adl_serializer<Kazv::Event> {
119 static void to_json(json& j, Kazv::Event w) {
120 j = w.originalJson();
121 }
122
123 static void from_json(const json& j, Kazv::Event &w) {
125 }
126 };
127}
Definition event.hpp:21
static const JsonWrap notYetDecryptedEvent
Definition event.hpp:23
std::string stateKey() const
Definition event.cpp:74
std::string replyingTo() const
Get the event id this event is replying to.
Definition event.cpp:121
std::string type() const
Definition event.cpp:62
void serialize(Archive &ar, std::uint32_t const)
Definition event.hpp:98
std::pair< std::string, std::string > relationship() const
Get the relationship that this event contains.
Definition event.cpp:155
std::string id() const
returns the id of this event
Definition event.cpp:42
JsonWrap originalJson() const
returns the original json we fetched, probably encrypted.
Definition event.cpp:91
bool isState() const
Definition event.cpp:80
bool decrypted() const
Definition event.cpp:103
Event()
Definition event.cpp:22
JsonWrap mRelatesTo() const
Get the m.relates_to object in the event.
Definition event.cpp:166
JsonWrap decryptedJson() const
Definition event.cpp:95
Timestamp originServerTs() const
Definition event.cpp:55
bool redacted() const
returns whether this event has been redacted.
Definition event.cpp:114
JsonWrap content() const
Definition event.cpp:68
DecryptionStatus
Definition event.hpp:25
@ Decrypted
Definition event.hpp:27
@ NotDecrypted
Definition event.hpp:26
bool encrypted() const
Definition event.cpp:99
static Event fromSync(Event e, std::string roomId)
Definition event.cpp:36
JsonWrap raw() const
returns the decrypted json
Definition event.cpp:86
friend bool operator==(const Event &a, const Event &b)
Definition event.cpp:180
friend bool operator!=(const Event &a, const Event &b)
Definition event.hpp:103
std::string sender() const
Definition event.cpp:49
Event setDecryptedJson(JsonWrap decryptedJson, DecryptionStatus decrypted) const
internal. only to be called from inside the client.
Definition event.cpp:107
Definition jsonwrap.hpp:23
Definition location.hpp:10
nlohmann::json json
Definition jsonwrap.hpp:20
std::int_fast64_t Timestamp
Definition event.hpp:18
Definition location.hpp:27
static void to_json(json &j, Kazv::Event w)
Definition event.hpp:119
static void from_json(const json &j, Kazv::Event &w)
Definition event.hpp:123