Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F116376
matrix-event.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
matrix-event.cpp
View Options
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include
<libkazv-config.hpp>
#include
<immer/config.hpp>
// https://github.com/arximboldi/immer/issues/168
#include
"matrix-event.hpp"
#include
"helper.hpp"
using
namespace
Kazv
;
static
std
::
optional
<
LocalEchoDesc
>
getLocalEcho
(
std
::
variant
<
Event
,
LocalEchoDesc
>
event
)
{
if
(
std
::
holds_alternative
<
LocalEchoDesc
>
(
event
))
{
return
std
::
get
<
LocalEchoDesc
>
(
event
);
}
else
{
return
std
::
nullopt
;
}
}
static
Event
getEvent
(
std
::
variant
<
Event
,
LocalEchoDesc
>
event
)
{
if
(
std
::
holds_alternative
<
LocalEchoDesc
>
(
event
))
{
return
std
::
get
<
LocalEchoDesc
>
(
event
).
event
;
}
else
{
return
std
::
get
<
Event
>
(
event
);
}
}
MatrixEvent
::
MatrixEvent
(
lager
::
reader
<
std
::
variant
<
Event
,
LocalEchoDesc
>>
event
,
QObject
*
parent
)
:
QObject
(
parent
)
,
m_localEcho
(
event
.
map
(
getLocalEcho
))
,
m_event
(
event
.
map
(
getEvent
))
,
LAGER_QT
(
eventId
)(
m_event
.
xform
(
zug
::
map
([](
Event
e
)
{
return
e
.
id
();
})
|
strToQt
))
,
LAGER_QT
(
sender
)(
m_event
.
xform
(
zug
::
map
([](
Event
e
)
{
return
e
.
sender
();
})
|
strToQt
))
,
LAGER_QT
(
type
)(
m_event
.
xform
(
zug
::
map
([](
Event
e
)
{
return
e
.
type
();
})
|
strToQt
))
,
LAGER_QT
(
stateKey
)(
m_event
.
xform
(
zug
::
map
([](
Event
e
)
{
return
e
.
stateKey
();
})
|
strToQt
))
,
LAGER_QT
(
content
)(
m_event
.
xform
(
zug
::
map
([](
Event
e
)
{
return
e
.
content
().
get
().
get
<
QJsonObject
>
();
})))
,
LAGER_QT
(
encrypted
)(
m_event
.
xform
(
zug
::
map
([](
Event
e
)
{
return
e
.
encrypted
();
})))
,
LAGER_QT
(
decrypted
)(
m_event
.
map
([](
Event
e
)
{
return
e
.
decrypted
();
}))
,
LAGER_QT
(
isState
)(
m_event
.
map
([](
Event
e
)
{
return
e
.
isState
();
}))
,
LAGER_QT
(
unsignedData
)(
m_event
.
map
([](
Event
e
)
{
auto
j
=
e
.
raw
();
if
(
j
.
get
().
contains
(
"unsigned"
))
{
return
j
.
get
()[
"unsigned"
].
template
get
<
QJsonObject
>
();
}
else
{
return
QJsonObject
();
}
}))
,
LAGER_QT
(
isLocalEcho
)(
m_localEcho
.
map
([](
const
auto
&
maybe
)
{
return
maybe
.
has_value
();
}))
,
LAGER_QT
(
isSending
)(
m_localEcho
.
map
([](
const
auto
&
maybe
)
{
return
maybe
.
has_value
()
&&
maybe
.
value
().
status
==
LocalEchoDesc
::
Sending
;
}))
,
LAGER_QT
(
isFailed
)(
m_localEcho
.
map
([](
const
auto
&
maybe
)
{
return
maybe
.
has_value
()
&&
maybe
.
value
().
status
==
LocalEchoDesc
::
Failed
;
}))
,
LAGER_QT
(
txnId
)(
m_localEcho
.
map
([](
const
auto
&
maybe
)
{
return
maybe
.
has_value
()
?
QString
::
fromStdString
(
maybe
.
value
().
txnId
)
:
QStringLiteral
(
""
);
}))
,
LAGER_QT
(
redacted
)(
m_event
.
map
([](
const
auto
&
e
)
{
return
e
.
redacted
();
}))
,
LAGER_QT
(
originalSource
)(
m_event
.
map
([](
Event
e
)
{
return
e
.
originalJson
().
get
().
template
get
<
QJsonObject
>
();
}))
,
LAGER_QT
(
decryptedSource
)(
m_event
.
map
([](
Event
e
)
{
return
e
.
decrypted
()
?
e
.
raw
().
get
().
template
get
<
QJsonObject
>
()
:
QJsonObject
();
}))
,
LAGER_QT
(
replyingToEventId
)(
m_event
.
map
([](
Event
e
)
{
return
e
.
replyingTo
();
}).
xform
(
strToQt
))
,
LAGER_QT
(
relationType
)(
m_event
.
map
([](
Event
e
)
{
return
e
.
relationship
().
first
;
}).
xform
(
strToQt
))
,
LAGER_QT
(
relatedEventId
)(
m_event
.
map
([](
Event
e
)
{
return
e
.
relationship
().
second
;
}).
xform
(
strToQt
))
,
LAGER_QT
(
formattedTime
)(
m_event
.
map
(
&
Event
::
originServerTs
)
.
map
([](
Timestamp
ts
)
{
auto
locale
=
QLocale
::
system
();
return
locale
.
toString
(
QDateTime
::
fromMSecsSinceEpoch
(
ts
).
time
(),
QLocale
::
ShortFormat
);
}))
{
}
MatrixEvent
::
MatrixEvent
(
lager
::
reader
<
Event
>
event
,
QObject
*
parent
)
:
MatrixEvent
(
event
.
map
([](
const
auto
&
e
)
->
std
::
variant
<
Kazv
::
Event
,
Kazv
::
LocalEchoDesc
>
{
return
e
;
}),
parent
)
{
}
MatrixEvent
::~
MatrixEvent
()
=
default
;
Kazv
::
Event
MatrixEvent::underlyingEvent
()
const
{
return
m_event
.
get
();
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Dec 1, 10:58 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41661
Default Alt Text
matrix-event.cpp (4 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment