Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114618
event.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
event.hpp
View Options
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include
"libkazv-config.hpp"
#include
<string>
#include
<cstdint>
#include
"jsonwrap.hpp"
namespace
Kazv
{
using
Timestamp
=
std
::
int_fast64_t
;
class
Event
{
public
:
static
const
JsonWrap
notYetDecryptedEvent
;
enum
DecryptionStatus
{
NotDecrypted
,
Decrypted
};
Event
();
Event
(
JsonWrap
j
);
static
Event
fromSync
(
Event
e
,
std
::
string
roomId
);
/// returns the id of this event
std
::
string
id
()
const
;
std
::
string
sender
()
const
;
Timestamp
originServerTs
()
const
;
std
::
string
type
()
const
;
std
::
string
stateKey
()
const
;
/**
* @return whether this event is a state event.
* An event is considered a state event if and only if
* it has a maybe empty stateKey.
*/
bool
isState
()
const
;
JsonWrap
content
()
const
;
/// returns the decrypted json
JsonWrap
raw
()
const
;
/// returns the original json we fetched, probably encrypted.
JsonWrap
originalJson
()
const
;
JsonWrap
decryptedJson
()
const
;
bool
encrypted
()
const
;
bool
decrypted
()
const
;
/// internal. only to be called from inside the client.
Event
setDecryptedJson
(
JsonWrap
decryptedJson
,
DecryptionStatus
decrypted
)
const
;
/// returns whether this event has been redacted.
bool
redacted
()
const
;
/**
* Get the event id this event is replying to.
*
* @return The event id this event is replying to, or empty string if this
* event is not a reply.
*/
std
::
string
replyingTo
()
const
;
/**
* Get the relationship that this event contains.
*
* @return A Pair containing the rel_type and event_id in the m.relates_to section
* of this event, or a Pair of empty strings if there are not any.
*/
std
::
pair
<
std
::
string
/* relType */
,
std
::
string
/* eventId */
>
relationship
()
const
;
/**
* Get the m.relates_to object in the event.
*
* @return The m.relates_to object of this event.
*/
JsonWrap
mRelatesTo
()
const
;
template
<
class
Archive
>
void
serialize
(
Archive
&
ar
,
std
::
uint32_t
const
/*version*/
)
{
ar
&
m_json
&
m_decryptedJson
&
m_decrypted
&
m_encrypted
;
}
private
:
JsonWrap
m_json
;
JsonWrap
m_decryptedJson
;
DecryptionStatus
m_decrypted
{
NotDecrypted
};
bool
m_encrypted
{
false
};
};
bool
operator
==
(
const
Event
&
a
,
const
Event
&
b
);
inline
bool
operator
!=
(
const
Event
&
a
,
const
Event
&
b
)
{
return
!
(
a
==
b
);
};
}
BOOST_CLASS_VERSION
(
Kazv
::
Event
,
0
)
namespace
nlohmann
{
template
<>
struct
adl_serializer
<
Kazv
::
Event
>
{
static
void
to_json
(
json
&
j
,
Kazv
::
Event
w
)
{
j
=
w
.
originalJson
();
}
static
void
from_json
(
const
json
&
j
,
Kazv
::
Event
&
w
)
{
w
=
Kazv
::
Event
(
Kazv
::
JsonWrap
(
j
));
}
};
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Tue, Nov 26, 1:12 PM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40314
Default Alt Text
event.hpp (3 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment