Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2577428
matrix-room-list.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-list.cpp
View Options
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020 Tusooa Zhu <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
<lager/commit.hpp>
#include
<lager/constant.hpp>
#include
<lager/lenses/optional.hpp>
#include
"matrix-room-list.hpp"
#include
"matrix-room.hpp"
#include
"helper.hpp"
using
namespace
Kazv
;
MatrixRoomList
::
MatrixRoomList
(
Kazv
::
Client
client
,
QString
tagId
,
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
,
m_client
(
client
)
,
m_tagId
(
tagId
)
,
m_tagIdCursor
(
lager
::
make_sensor
([
this
]
{
return
m_tagId
.
toStdString
();
}))
,
m_internalCount
(
0
)
,
m_roomIds
(
lager
::
with
(
m_tagIdCursor
,
m_client
.
roomIds
(),
m_client
.
roomIdsByTagId
())
.
map
([](
const
auto
&
tagIdStdStr
,
const
auto
&
allRooms
,
const
auto
&
roomsByTagMap
)
{
if
(
tagIdStdStr
.
empty
())
{
return
allRooms
;
}
else
{
return
intoImmer
(
immer
::
flex_vector
<
std
::
string
>
{},
zug
::
map
([](
const
auto
&
pair
)
{
return
pair
.
first
;
}),
roomsByTagMap
[
tagIdStdStr
]
);
}
}))
,
LAGER_QT
(
count
)(
m_roomIds
.
xform
(
containerSize
))
,
LAGER_QT
(
roomIds
)(
m_roomIds
.
xform
(
zug
::
map
(
[](
auto
container
)
{
return
zug
::
into
(
QStringList
{},
strToQt
,
std
::
move
(
container
));
})))
{
m_internalCount
=
count
();
connect
(
this
,
&
MatrixRoomList
::
countChanged
,
this
,
&
MatrixRoomList
::
updateInternalCount
);
}
MatrixRoomList
::~
MatrixRoomList
()
=
default
;
void
MatrixRoomList::setTagId
(
QString
tagId
)
{
m_tagId
=
tagId
;
lager
::
commit
(
m_tagIdCursor
);
}
MatrixRoom
*
MatrixRoomList::at
(
int
index
)
const
{
qDebug
()
<<
"Room at index "
<<
index
<<
" requested"
;
return
new
MatrixRoom
(
m_client
.
roomByCursor
(
lager
::
with
(
m_roomIds
,
lager
::
make_constant
(
index
))
.
xform
(
zug
::
map
([](
auto
ids
,
auto
i
)
{
try
{
return
ids
.
at
(
i
);
}
catch
(
const
std
::
out_of_range
&
)
{
return
std
::
string
{};
}
}))),
m_client
.
userId
());
}
QString
MatrixRoomList::roomIdAt
(
int
index
)
const
{
using
namespace
Kazv
::
CursorOp
;
return
+
m_roomIds
[
index
][
lager
::
lenses
::
or_default
].
xform
(
strToQt
);
}
MatrixRoom
*
MatrixRoomList
::
room
(
QString
roomId
)
const
{
return
new
MatrixRoom
(
m_client
.
room
(
roomId
.
toStdString
()),
m_client
.
userId
());
}
QVariant
MatrixRoomList
::
data
(
const
QModelIndex
&
/* index */
,
int
/* role */
)
const
{
return
QVariant
();
}
int
MatrixRoomList
::
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
{
if
(
parent
.
isValid
())
{
return
0
;
}
else
{
return
count
();
}
}
void
MatrixRoomList
::
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
Tue, Jun 24, 7:09 AM (23 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
234746
Default Alt Text
matrix-room-list.cpp (3 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment