Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F325626
matrix-room-timeline.cpp
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
matrix-room-timeline.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
<cmath>
#include
<lager/lenses/optional.hpp>
#include
<QTimer>
#include
<cursorutil.hpp>
#include
"matrix-room-timeline.hpp"
#include
"matrix-event.hpp"
#include
"helper.hpp"
#include
"kazv-log.hpp"
using
namespace
Kazv
;
MatrixRoomTimeline
::
MatrixRoomTimeline
(
Kazv
::
Room
room
,
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
,
m_room
(
room
)
,
m_timeline
(
m_room
.
timelineEvents
())
,
m_internalCount
(
0
)
,
m_localEchoes
(
m_room
.
localEchoes
())
,
m_timelineGaps
(
m_room
.
timelineGaps
())
,
LAGER_QT
(
count
)(
lager
::
with
(
m_timeline
.
xform
(
containerSize
),
m_localEchoes
.
xform
(
containerSize
)
).
map
([](
const
auto
&
tlSize
,
const
auto
&
localSize
)
{
return
tlSize
+
localSize
;
}))
,
LAGER_QT
(
eventIds
)(
m_timeline
.
xform
(
zug
::
map
(
[](
auto
container
)
{
return
zug
::
into
(
QStringList
{},
zug
::
map
([](
Kazv
::
Event
event
)
{
return
QString
::
fromStdString
(
event
.
id
());
}),
std
::
move
(
container
));
})))
,
LAGER_QT
(
gaps
)(
m_timelineGaps
.
map
([](
auto
g
)
{
QSet
<
QString
>
res
{};
for
(
const
auto
&
[
k
,
_v
]
:
g
)
{
res
.
insert
(
QString
::
fromStdString
(
k
));
}
return
res
;
}))
{
connect
(
this
,
&
MatrixRoomTimeline
::
countChanged
,
this
,
&
MatrixRoomTimeline
::
updateInternalCount
);
// HACK: If internally the count is set to its full count at the beginning,
// ListView will instantiate everything in the timeline.
// I don't know why it is the case, so I keep the internal count as 0
// when it is constructed, and update it in the next tick.
QTimer
::
singleShot
(
0
,
this
,
[
this
]
{
Q_EMIT
countChanged
(
count
());
});
}
MatrixRoomTimeline
::~
MatrixRoomTimeline
()
=
default
;
MatrixEvent
*
MatrixRoomTimeline::at
(
int
index
)
const
{
return
new
MatrixEvent
(
lager
::
with
(
m_timeline
,
m_localEchoes
,
LAGER_QT
(
count
))
.
map
([
index
](
const
auto
&
tl
,
const
auto
&
localEchoes
,
const
auto
&
count
)
->
std
::
variant
<
Kazv
::
Event
,
Kazv
::
LocalEchoDesc
>
{
auto
rIndex
=
count
-
index
-
1
;
if
(
static_cast
<
unsigned
int
>
(
rIndex
)
<
tl
.
size
())
{
return
tl
[
rIndex
];
}
else
{
auto
remainingIndex
=
rIndex
-
tl
.
size
();
if
(
remainingIndex
<
localEchoes
.
size
())
{
return
localEchoes
[
remainingIndex
];
}
else
{
return
Event
();
}
}
}));
}
int
MatrixRoomTimeline::rowCount
(
const
QModelIndex
&
index
)
const
{
if
(
index
.
isValid
())
{
return
0
;
}
else
{
return
m_internalCount
;
}
}
QVariant
MatrixRoomTimeline::data
(
const
QModelIndex
&
,
int
)
const
{
return
QVariant
();
}
void
MatrixRoomTimeline::updateInternalCount
()
{
auto
curCount
=
count
();
auto
oldCount
=
m_internalCount
;
auto
diff
=
std
::
abs
(
curCount
-
oldCount
);
if
(
curCount
>
oldCount
)
{
beginInsertRows
(
QModelIndex
(),
0
,
diff
-
1
);
m_internalCount
=
curCount
;
endInsertRows
();
}
else
if
(
curCount
<
oldCount
)
{
beginRemoveRows
(
QModelIndex
(),
0
,
diff
-
1
);
m_internalCount
=
curCount
;
endRemoveRows
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 24, 4:18 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
88427
Default Alt Text
matrix-room-timeline.cpp (3 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment