Changeset View
Changeset View
Standalone View
Standalone View
src/matrix-room-member-list-model.cpp
| /* | /* | ||||
| * This file is part of kazv. | * This file is part of kazv. | ||||
| * SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe> | * SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe> | ||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | * SPDX-License-Identifier: AGPL-3.0-or-later | ||||
| */ | */ | ||||
| #include <kazv-defs.hpp> | #include <kazv-defs.hpp> | ||||
| #include <cmath> | #include <cmath> | ||||
| #include <lager/lenses/optional.hpp> | #include <lager/lenses/optional.hpp> | ||||
| #include <cursorutil.hpp> | #include <cursorutil.hpp> | ||||
| #include "helper.hpp" | |||||
| #include "matrix-room-member-list-model.hpp" | #include "matrix-room-member-list-model.hpp" | ||||
| #include "matrix-room-member.hpp" | #include "matrix-room-member.hpp" | ||||
| using namespace Kazv; | using namespace Kazv; | ||||
| MatrixRoomMemberListModel::MatrixRoomMemberListModel(lager::reader<Kazv::EventList> members, QObject *parent) | MatrixRoomMemberListModel::MatrixRoomMemberListModel(lager::reader<Kazv::EventList> members, QString filter, QObject *parent) | ||||
| : QAbstractListModel(parent) | : QAbstractListModel(parent) | ||||
| , m_members(members) | , m_filter(lager::make_state(filter.toStdString(), lager::automatic_tag{})) | ||||
| , m_members(lager::with(members, m_filter).map([](const auto &members, const auto &filter) { | |||||
| if (filter.empty()) { | |||||
| return members; | |||||
| } | |||||
| return intoImmer(EventList{}, zug::filter([filter](const auto &e) { | |||||
| auto userId = e.stateKey(); | |||||
| if (userId.find(filter) != std::string::npos) { | |||||
| return true; | |||||
| } | |||||
| auto content = e.content().get(); | |||||
| if (content.contains("displayname") | |||||
| && content["displayname"].is_string()) { | |||||
| auto name = content["displayname"].template get<std::string>(); | |||||
| return name.find(filter) != std::string::npos; | |||||
| } | |||||
| return false; | |||||
| }), members); | |||||
| })) | |||||
| , m_internalCount(0) | , m_internalCount(0) | ||||
| , LAGER_QT(filter)(m_filter.xform(strToQt, qStringToStd)) | |||||
| , LAGER_QT(count)(m_members.map([](const auto &m) -> int { return m.size(); })) | , LAGER_QT(count)(m_members.map([](const auto &m) -> int { return m.size(); })) | ||||
| { | { | ||||
| m_internalCount = count(); | m_internalCount = count(); | ||||
| connect(this, &MatrixRoomMemberListModel::countChanged, | connect(this, &MatrixRoomMemberListModel::countChanged, | ||||
| this, &MatrixRoomMemberListModel::updateInternalCount); | this, &MatrixRoomMemberListModel::updateInternalCount); | ||||
| } | } | ||||
| Show All 37 Lines | |||||