### Install kazvstore target Source: https://github.com/kazv/libkazv/blob/servant/src/store/CMakeLists.txt Installs the kazvstore target and its export set. ```cmake install(TARGETS kazvstore EXPORT libkazvTargets) ``` -------------------------------- ### Install libkazv Job Library and Configuration Source: https://github.com/kazv/libkazv/blob/servant/src/job/CMakeLists.txt Installs the kazvjob library and its CMake configuration files. ```cmake install( TARGETS kazvjob EXPORT libkazv-jobTargets LIBRARY) install(EXPORT libkazv-jobTargets NAMESPACE libkazv:: DESTINATION ${ConfigPackageLocation} ) install( FILES ${libkazvSourceRoot}/cmake/libkazv-jobConfig.cmake DESTINATION ${ConfigPackageLocation}) ``` -------------------------------- ### Install kazvbase Library and Headers Source: https://github.com/kazv/libkazv/blob/servant/src/base/CMakeLists.txt Installs the kazvbase library and its associated headers. This ensures that the built library and its public header files are placed in the correct locations for use by other projects. ```cmake install(TARGETS kazvbase EXPORT libkazvTargets LIBRARY) if(libkazv_INSTALL_HEADERS) # Install headers not under src/ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libkazv-defs.hpp DESTINATION ${libkazv_HEADER_INSTALL_DIR}/base) endif() ``` -------------------------------- ### Start and Stop Syncing with Matrix SDK Source: https://context7.com/kazv/libkazv/llms.txt Controls the continuous synchronization with the Matrix homeserver to fetch new events and updates. Ensure you start syncing after a successful login. ```cpp auto client = sdk.client(); // Start syncing after login client.startSyncing() .then([](auto status) { if (status.success()) { std::cout << "Initial sync completed, now syncing continuously" << std::endl; } else { std::cerr << "Sync preparation failed" << std::endl; } }); // Check if currently syncing auto isSyncing = client.syncing().make().get(); std::cout << "Is syncing: " << (isSyncing ? "yes" : "no") << std::endl; // Stop syncing when done client.stopSyncing() .then([](auto status) { std::cout << "Syncing stopped" << std::endl; }); ``` -------------------------------- ### Install kazvcrypto target Source: https://github.com/kazv/libkazv/blob/servant/src/crypto/CMakeLists.txt Installs the kazvcrypto target as a library for export, making it available for other targets to link against. ```cmake install(TARGETS kazvcrypto EXPORT libkazvTargets LIBRARY) ``` -------------------------------- ### Install kazvtestfixtures Library and Export Targets Source: https://github.com/kazv/libkazv/blob/servant/src/testfixtures/CMakeLists.txt Installs the 'kazvtestfixtures' library and exports its targets under the 'libkazvTargets' configuration for use by other projects. ```cmake install(TARGETS kazvtestfixtures EXPORT libkazvTargets LIBRARY) ``` -------------------------------- ### Set include directories for kazvstore Source: https://github.com/kazv/libkazv/blob/servant/src/store/CMakeLists.txt Configures the include directories for the kazvstore library for build and installation. ```cmake target_include_directories(kazvstore INTERFACE $ $ $ ) ``` -------------------------------- ### Configure Interface Include Directories for kazvclient Source: https://github.com/kazv/libkazv/blob/servant/src/testfixtures/CMakeLists.txt Sets the interface include directories for the 'kazvclient' target, making headers available during build and installation. ```cmake target_include_directories(kazvclient INTERFACE $ $ ) ``` -------------------------------- ### Install Kazv EventEmitter Target Source: https://github.com/kazv/libkazv/blob/servant/src/eventemitter/CMakeLists.txt Installs the kazveventemitter target and its export set (libkazvTargets). This makes the library available for other projects to find and use. ```cmake install(TARGETS kazveventemitter EXPORT libkazvTargets) ``` -------------------------------- ### Perform Password Login and Start Syncing Source: https://github.com/kazv/libkazv/blob/servant/tutorials/tutorial0.md Dispatches a login action using provided credentials and initiates synchronization upon successful login. Handles login failures by printing an error and exiting. The `then` method chains asynchronous operations, resolving when the login is successful or an error occurs. ```cpp client.passwordLogin(homeserver, username, password, deviceName) .then([=](auto status) { if (! status.success()) { std::cerr << "Login failed" << std::endl; std::exit(1); } client.startSyncing(); }); ``` -------------------------------- ### Configure Include Directories for kazvbase Source: https://github.com/kazv/libkazv/blob/servant/src/base/CMakeLists.txt Sets the include directories for the kazvbase library. It specifies build-time and install-time include paths, making headers accessible during development and after installation. ```cmake target_include_directories(kazvbase INTERFACE $ $ $ ) target_include_directories(kazvbase PRIVATE $) ``` -------------------------------- ### Set include directories for kazvcrypto Source: https://github.com/kazv/libkazv/blob/servant/src/crypto/CMakeLists.txt Configures the include directories for the kazvcrypto target. It includes the current directory for build interfaces and a specific path for installation. ```cmake target_include_directories(kazvcrypto PRIVATE .) target_include_directories(kazvcrypto INTERFACE $ $ ) ``` -------------------------------- ### Start Event Loop Source: https://github.com/kazv/libkazv/blob/servant/tutorials/tutorial0.md Initiates the event loop. Dispatched actions will not run until this call is made. This is a simple and essential step to begin processing asynchronous operations. ```python io.run(); ``` -------------------------------- ### Defining Reducer Function Signatures in C++ Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Example signatures for reducer functions within the libkazv project. `updateClient` handles actions, and `processResponse` handles responses from API jobs. ```cpp namespace Kazv { ClientResult updateClient(ClientModel m, XXXAction a); ClientResult processResponse(ClientModel m, YYYResponse r); } ``` -------------------------------- ### Get User Devices Source: https://context7.com/kazv/libkazv/llms.txt Retrieve a list of devices associated with a specific Matrix user ID using `client.devicesOfUser`. This is often a prerequisite for device verification. ```cpp auto client = sdk.client(); // Get devices of a user auto devices = client.devicesOfUser("@alice:example.org").make().get(); for (const auto& device : devices) { std::cout << "Device: " << device.deviceId << " Trust: " << static_cast(device.trustLevel) << std::endl; } ``` -------------------------------- ### Build and run tutorial0.cpp Source: https://github.com/kazv/libkazv/blob/servant/tutorials/tutorial0.md Use these commands to build and execute the libkazv tutorial program. The program will prompt for Matrix homeserver, username, and password. ```bash mkdir -pv build && cd build cmake .. -DCMAKE_PREFIX_PATH= make tutorial0 ./tutorial0 ``` -------------------------------- ### Initialize Kazv SDK Source: https://github.com/kazv/libkazv/blob/servant/tutorials/tutorial0.md Creates an SDK instance by combining an io_context, job handler, event emitter, promise handler, and identity. Ensure boost::asio::io_context is set up for the event loop. ```cpp auto io = ...; auto jh = Kazv::CprJobHandler{...}; auto ee = Kazv::LagerStoreEventEmitter{...}; auto sdk = Kazv::makeSdk( Kazv::SdkModel{}, jh, ee, Kazv::AsioPromiseHandler{io.get_executor()}, zug::identity ); ``` -------------------------------- ### Initialize libkazv SDK Source: https://context7.com/kazv/libkazv/llms.txt Creates an SDK instance with necessary dependencies like job handler, event emitter, and promise handler. This is the entry point for using libkazv. ```cpp #include #include #include #include #include #include #include int main() { // Create the event loop auto io = boost::asio::io_context{}; // Create the job handler for network requests auto jh = Kazv::CprJobHandler{io.get_executor()}; // Create the event emitter for triggers auto ee = Kazv::LagerStoreEventEmitter(lager::with_boost_asio_event_loop{io.get_executor()}); // Create the SDK with all dependencies auto sdk = Kazv::makeSdk( Kazv::SdkModel{}, // Initial model state jh, // Job handler ee, // Event emitter Kazv::AsioPromiseHandler{io.get_executor()}, // Promise handler zug::identity // Transform function ); // Get the client to perform operations auto client = sdk.client(); // Start the event loop (blocking) io.run(); return 0; } ``` -------------------------------- ### SDK Initialization Source: https://context7.com/kazv/libkazv/llms.txt Demonstrates how to initialize the libkazv SDK with necessary dependencies like a job handler, event emitter, and promise handler. ```APIDOC ## SDK Initialization The `makeSdk` function creates an SDK instance with the necessary dependencies including a job handler for network requests, an event emitter for triggers, and a promise handler for async operations. This is the entry point for using libkazv. ```cpp #include #include #include #include #include #include #include int main() { // Create the event loop auto io = boost::asio::io_context{}; // Create the job handler for network requests auto jh = Kazv::CprJobHandler{io.get_executor()}; // Create the event emitter for triggers auto ee = Kazv::LagerStoreEventEmitter(lager::with_boost_asio_event_loop{io.get_executor()}); // Create the SDK with all dependencies auto sdk = Kazv::makeSdk( Kazv::SdkModel{}, jh, ee, Kazv::AsioPromiseHandler{io.get_executor()}, zug::identity ); // Get the client to perform operations auto client = sdk.client(); // Start the event loop (blocking) io.run(); return 0; } ``` ``` -------------------------------- ### Include Header and Namespace Source: https://github.com/kazv/libkazv/blob/servant/design-docs/libkazvfixtures.md Include the necessary header file and open the Kazv::Factory namespace for using the fixtures library. ```cpp #include using namespace Kazv::Factory; ``` -------------------------------- ### Create a Store with an Event Loop Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Initialize a store with an initial model and an event loop. The event loop processes posts (functions) in a queue, defining ticks for execution. ```cpp auto initialModel = ...; auto eventLoop = ...; auto store = makeStore( initialModel, withEventLoop(eventLoop), ... ); ``` -------------------------------- ### Initialize libkazv SDK with Encryption Source: https://context7.com/kazv/libkazv/llms.txt Creates an SDK instance with E2EE capabilities, initialized using user-provided random data. This is recommended for production use. ```cpp #include #include #include #include #include // Get random data from a secure source auto randomSize = Kazv::makeDefaultSdkWithCryptoRandomSize(); auto randomData = Kazv::genRandomData(randomSize); // Or use your own CSPRNG auto sdk = Kazv::makeDefaultSdkWithCryptoRandom( randomData, // Random data for crypto initialization jh, // Job handler ee, // Event emitter Kazv::AsioPromiseHandler{io.get_executor()}, // Promise handler zug::identity // Transform function ); auto client = sdk.client(); ``` -------------------------------- ### Get Model Value from Cursor Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Obtain the current value stored in a read-only cursor. Ensure the cursor is initialized with the correct model type. ```cpp lager::reader cursor = store; Model model = cursor.get(); ``` -------------------------------- ### Read and Set Room State Events in C++ Source: https://context7.com/kazv/libkazv/llms.txt Demonstrates reading room name and power levels, and setting room name and topic. Requires initialization of the SDK client and a room object. ```cpp auto client = sdk.client(); auto room = client.room("!roomid:example.org"); // Read a state event auto nameEvent = room.state(Kazv::KeyOfState{"m.room.name", ""}).make().get(); auto roomName = nameEvent.content().get()["name"].get(); // Read power levels auto powerLevels = room.powerLevels().make().get(); std::cout << "Users default power: " << powerLevels.usersDefault() << std::endl; // Set room name room.setName("New Room Name") .then([](auto status) { if (status.success()) { std::cout << "Room name updated" << std::endl; } }); // Set room topic room.setTopic("Discussion about important topics") .then([](auto status) { if (status.success()) { std::cout << "Room topic updated" << std::endl; } }); // Send a custom state event Kazv::Event stateEvent(Kazv::JsonWrap(nlohmann::json{ {"type", "m.room.avatar"}, {"state_key", ""}, {"content", { {"url", "mxc://example.org/avatar123"} }} })); room.sendStateEvent(stateEvent); ``` -------------------------------- ### Build libkazv with CMake Source: https://github.com/kazv/libkazv/blob/servant/README.md Standard CMake process for building libkazv. Ensure you create a build directory and navigate into it before running the cmake command. ```bash mkdir -pv build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/prefix make install ``` -------------------------------- ### Configure Include Directories Source: https://github.com/kazv/libkazv/blob/servant/src/eventemitter/CMakeLists.txt Sets up the include directories for the kazveventemitter library. It specifies build-time and install-time include paths for the eventemitter headers. ```cmake target_include_directories(kazveventemitter INTERFACE $ $ ) ``` -------------------------------- ### Get User Profile Source: https://context7.com/kazv/libkazv/llms.txt Retrieve the profile information of another user using `client.getProfile`. This method returns the display name and avatar URL if the user's profile is accessible. ```cpp auto client = sdk.client(); // Get another user's profile client.getProfile("@bob:example.org") .then([](auto status) { if (status.success()) { std::cout << "Display name: " << status.dataStr("displayName") << std::endl; std::cout << "Avatar URL: " << status.dataStr("avatarUrl") << std::endl; } }); ``` -------------------------------- ### Derive Cursor with Attribute Lens Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Use an attribute lens to create a cursor that accesses a specific member of a struct or class. This provides a concise way to get nested data. ```cpp struct Model { int a; int b; }; lager::reader cursor = ...; lager::reader cursorA = cursor[&Model::a]; ``` -------------------------------- ### SDK with Encryption Support Source: https://context7.com/kazv/libkazv/llms.txt Shows how to initialize the SDK with End-to-End Encryption (E2EE) capabilities using user-provided random data for cryptographic operations. ```APIDOC ## SDK with Encryption Support The `makeDefaultSdkWithCryptoRandom` function creates an SDK with E2EE capabilities initialized using user-provided random data. This is the recommended way to create an encrypted SDK for production use. ```cpp #include #include #include #include #include // Get random data from a secure source auto randomSize = Kazv::makeDefaultSdkWithCryptoRandomSize(); auto randomData = Kazv::genRandomData(randomSize); // Or use your own CSPRNG auto sdk = Kazv::makeDefaultSdkWithCryptoRandom( randomData, jh, ee, Kazv::AsioPromiseHandler{io.get_executor()}, zug::identity ); auto client = sdk.client(); ``` ``` -------------------------------- ### Set Device Trust Level Source: https://context7.com/kazv/libkazv/llms.txt Manually set the trust level for a specific device using `client.setDeviceTrustLevel`. This allows overriding automatic trust assessments, for example, marking a device as `Verified`. ```cpp // Set device trust level manually client.setDeviceTrustLevel("@alice:example.org", "DEVICEID", Kazv::DeviceTrustLevel::Verified); ``` -------------------------------- ### Returning a Promise from a Reducer Effect in C++ Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md A reducer's effect can return a Promise. The Promise returned by `ctx.dispatch` will then wait for this effect-returned Promise to resolve. This example shows an effect creating a Promise that resolves upon an asynchronous IO request. ```cpp std::pair update(Model m, Action a) { return {nextModel, [](const auto &ctx) { auto ioHandler = getIOHandler(ctx); auto p = ctx.createPromise([](auto resolve) { ioHandler.request(..., [](auto value) { auto data = doSomethingWith(value); return resolve(data); }); }); return p; }}; } auto promise = ctx.dispatch(Action{}); // will be resolved after p has resolved ``` -------------------------------- ### Manage Global and Room Account Data with C++ Source: https://context7.com/kazv/libkazv/llms.txt Use this C++ code to interact with global and room-specific account data. It shows how to retrieve, set, and manage user preferences and settings that sync across devices or are specific to a room. Ensure the libkazv SDK is initialized. ```cpp auto client = sdk.client(); // Get global account data auto accountData = client.accountData().make().get(); if (accountData.count("m.direct")) { auto directEvent = accountData.at("m.direct"); std::cout << "Direct rooms configured" << std::endl; } // Set global account data Kazv::Event customData(Kazv::JsonWrap(nlohmann::json{ {"type", "com.example.settings"}, {"content", { {"theme", "dark"}, {"notifications", true} }} })); client.setAccountData(customData); // Room-specific account data auto room = client.room("!roomid:example.org"); // Get room account data auto roomData = room.accountDataOpt("m.fully_read").make().get(); // Set room account data Kazv::Event roomSettings(Kazv::JsonWrap(nlohmann::json{ {"type", "com.example.room_settings"}, {"content", { {"muted", true} }} })); room.setAccountData(roomSettings); ``` -------------------------------- ### Provide Dependencies to the Store Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Create a store with dependencies that can be accessed within the context of effects. This is useful for providing services like IO handlers. ```cpp auto store = makeStore(..., lager::with_deps(depA, depB)); ``` -------------------------------- ### Configure libkazv Job Library Source: https://github.com/kazv/libkazv/blob/servant/src/job/CMakeLists.txt Defines the sources, creates the library, sets versioning, links dependencies, and configures include directories for the kazvjob library. ```cmake include(linklibsys) set(libkazvjob_SRCS cprjobhandler.cpp ) add_library(kazvjob ${libkazvjob_SRCS}) add_library(libkazv::kazvjob ALIAS kazvjob) set_target_properties(kazvjob PROPERTIES VERSION ${libkazv_VERSION_STRING} SOVERSION ${libkazv_SOVERSION}) target_link_libraries(kazvjob PUBLIC Threads::Threads kazvbase) target_link_libraries_system(kazvjob PUBLIC cpr::cpr ) target_include_directories(kazvjob INTERFACE $ $ ) ``` -------------------------------- ### Obtain Kazv Client Instance Source: https://github.com/kazv/libkazv/blob/servant/tutorials/tutorial0.md Retrieves a client instance from the initialized SDK. This client is used for performing most of the SDK's operations. ```cpp auto client = sdk.client(); ``` -------------------------------- ### Authenticate with Password Login Source: https://context7.com/kazv/libkazv/llms.txt Authenticates with a Matrix homeserver using username and password. Returns a Promise that resolves upon completion or failure. Ensure the event loop is running to process the login. ```cpp auto client = sdk.client(); std::string homeserver = "https://matrix.example.org"; std::string username = "alice"; std::string password = "secretpassword"; std::string deviceName = "My App"; client.passwordLogin(homeserver, username, password, deviceName) .then([=](auto status) { if (!status.success()) { std::cerr << "Login failed: " << status.dataStr("error") << std::endl; std::cerr << "Error code: " << status.dataStr("errorCode") << std::endl; return; } std::cout << "Login successful!" << std::endl; std::cout << "User ID: " << client.userId().make().get() << std::endl; std::cout << "Device ID: " << client.deviceId().make().get() << std::endl; // Start syncing after successful login client.startSyncing(); }); io.run(); ``` -------------------------------- ### Download Content to File in C++ Source: https://context7.com/kazv/libkazv/llms.txt Downloads content from the Matrix content repository and saves it to a specified file path. Requires the MXC URI and a Kazv::FileDesc object for the output file. ```cpp // Download to file Kazv::FileDesc outputFile("downloads/file.png"); client.downloadContent(mxcUri, outputFile) .then([](auto status) { if (status.success()) { std::cout << "File saved to downloads/file.png" << std::endl; } }); ``` -------------------------------- ### Define and Configure kazvtestfixtures Library Source: https://github.com/kazv/libkazv/blob/servant/src/testfixtures/CMakeLists.txt Defines the 'kazvtestfixtures' library using source files and sets its version and SOVERSION. It also specifies private include directories. ```cmake add_library(kazvtestfixtures factory.cpp ) add_library(libkazv::kazvtestfixtures ALIAS kazvtestfixtures) set_target_properties(kazvtestfixtures PROPERTIES VERSION ${libkazv_VERSION_STRING} SOVERSION ${libkazv_SOVERSION}) ``` ```cmake target_include_directories( kazvtestfixtures PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### Add Executable and Link Libraries Source: https://github.com/kazv/libkazv/blob/servant/src/examples/CMakeLists.txt Defines an executable target and links it with necessary libraries. Ensure all listed libraries are available in your build environment. ```cmake add_executable(basicexample basic/main.cpp basic/commands.cpp) target_link_libraries(basicexample PRIVATE kazvjob PRIVATE kazv PRIVATE immer PRIVATE zug PRIVATE lager PRIVATE ${LIBHTTPSERVER_LINK_LIBRARIES}) target_include_directories(basicexample PRIVATE ${LIBHTTPSERVER_INCLUDE_DIRS}) ``` -------------------------------- ### Room Creation API Source: https://context7.com/kazv/libkazv/llms.txt Creates new Matrix rooms with various configurations like visibility, presets, and invited users. ```APIDOC ## Creating Rooms ### Description The `createRoom` method creates a new Matrix room with specified visibility, name, and other options. It supports various room presets and power level configurations. ### Method POST ### Endpoint `/rooms/create` (assumed) ### Parameters #### Request Body - **visibility** (string) - Required - Room visibility (e.g., `Private`). - **name** (string) - Optional - The name of the room. - **alias** (string) - Optional - The room alias. - **invitees** (array of strings) - Optional - User IDs to invite. - **isDirect** (boolean) - Optional - Whether this is a direct message room. - **allowFederation** (boolean) - Optional - Whether to allow federation. - **topic** (string) - Optional - The room topic. - **powerLevelOverrides** (object) - Optional - Power level configurations. - **preset** (string) - Optional - Room creation preset (e.g., `PrivateChat`). ### Request Example (Private Room) ```json { "visibility": "Private", "name": "My Private Room", "invitees": [ "@bob:example.org", "@charlie:example.org" ], "allowFederation": true, "topic": "A room for discussing projects", "preset": "PrivateChat" } ``` ### Request Example (Direct Message Room) ```json { "visibility": "Private", "invitees": [ "@bob:example.org" ], "isDirect": true, "allowFederation": true } ``` ### Response #### Success Response (200) - **roomId** (string) - The ID of the newly created room. - **error** (string) - Error message if creation failed. #### Response Example ```json { "roomId": "!newroomid:example.org" } ``` ``` -------------------------------- ### Create Private Room with Matrix SDK Source: https://context7.com/kazv/libkazv/llms.txt Creates a new private Matrix room with specified options including invited users, topic, and preset. Use this for direct communication or project-specific discussions. ```cpp auto client = sdk.client(); // Create a private room with encryption client.createRoom( Kazv::RoomVisibility::Private, // Visibility "My Private Room", // Name std::nullopt, // Alias (optional) immer::array{ // Users to invite "@bob:example.org", "@charlie:example.org" }, false, // Is direct message true, // Allow federation "A room for discussing projects", // Topic json::object(), // Power level overrides Kazv::CreateRoomPreset::PrivateChat // Preset ) .then([](auto status) { if (status.success()) { std::cout << "Room created successfully" << std::endl; } else { std::cerr << "Failed to create room: " << status.dataStr("error") << std::endl; } }); ``` -------------------------------- ### Add Client Module Tests Source: https://github.com/kazv/libkazv/blob/servant/src/tests/CMakeLists.txt Configures a shared library for client-side testing utilities and then adds numerous client-specific test executables using `libkazv_add_tests`. This includes linking against `kazvclient`, `kazveventemitter`, `kazvjob`, and the custom `client-test-lib`, along with specific include directories. ```cmake add_library(client-test-lib SHARED client/client-test-util.cpp) target_link_libraries(client-test-lib PUBLIC kazvjob kazvclient) libkazv_add_tests( client/discovery-test.cpp client/sync-test.cpp client/content-test.cpp client/paginate-test.cpp client/storage-actions-test.cpp client/util-test.cpp client/serialization-test.cpp client/encrypted-file-test.cpp client/sdk-test.cpp client/thread-safety-test.cpp client/room-test.cpp client/random-generator-test.cpp client/profile-test.cpp client/kick-test.cpp client/ban-test.cpp client/join-test.cpp client/keys-test.cpp client/device-ops-test.cpp client/send-test.cpp client/encryption-test.cpp client/redact-test.cpp client/tagging-test.cpp client/account-data-test.cpp client/room/room-actions-test.cpp client/room/local-echo-test.cpp client/room/event-relationships-test.cpp client/room/member-membership-test.cpp client/room/purge-test.cpp client/push-rules-desc-test.cpp client/notification-handler-test.cpp client/validator-test.cpp client/power-levels-desc-test.cpp client/client-test.cpp client/create-room-test.cpp client/device-list-tracker-test.cpp client/device-list-tracker-benchmark-test.cpp client/room/read-receipt-test.cpp client/room/undecrypted-events-test.cpp client/encryption-benchmark-test.cpp client/login-test.cpp client/logout-test.cpp client/room/pinned-events-test.cpp client/get-versions-test.cpp client/alias-test.cpp client/encode-test.cpp client/maybe-add-save-events-trigger-benchmark-test.cpp client/verification-processing-test.cpp EXTRA_LINK_LIBRARIES kazvclient kazveventemitter kazvjob client-test-lib kazvtestfixtures EXTRA_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/client ) ``` -------------------------------- ### Accessing Data from Response in Kazv Client Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Demonstrates how to access data that was added to the job and is now available in the response. It shows retrieving string and JSON data using helper methods. ```cpp ClientResult processResponse(ClientModel m, YYYResponse r) { // ... auto param1 = r.dataStr("param1"); // this gives data["param1"] converted to std::string auto param2 = r.dataJson("param2"); // this gives data["param2"] as json // ... } ``` -------------------------------- ### Accept Incoming Device Verification Source: https://context7.com/kazv/libkazv/llms.txt Signal readiness to accept an incoming device verification request using `client.readyForVerification`. This should be called after receiving a verification request from another user. ```cpp // Accept incoming verification client.readyForVerification("@bob:example.org", "BOBDEVICE") .then([](auto status) { if (status.success()) { std::cout << "Ready for verification" << std::endl; } }); ``` -------------------------------- ### Password Login Source: https://context7.com/kazv/libkazv/llms.txt Details the process of authenticating with a Matrix homeserver using username and password credentials, and initiating synchronization upon successful login. ```APIDOC ## Password Login The `passwordLogin` method authenticates with a Matrix homeserver using username and password credentials. It returns a Promise that resolves when login completes or fails. ```cpp auto client = sdk.client(); std::string homeserver = "https://matrix.example.org"; std::string username = "alice"; std::string password = "secretpassword"; std::string deviceName = "My App"; client.passwordLogin(homeserver, username, password, deviceName) .then([=](auto status) { if (!status.success()) { std::cerr << "Login failed: " << status.dataStr("error") << std::endl; std::cerr << "Error code: " << status.dataStr("errorCode") << std::endl; return; } std::cout << "Login successful!" << std::endl; std::cout << "User ID: " << client.userId().make().get() << std::endl; std::cout << "Device ID: " << client.deviceId().make().get() << std::endl; // Start syncing after successful login client.startSyncing(); }); io.run(); ``` ``` -------------------------------- ### Create Client Model with Default Modifier Source: https://github.com/kazv/libkazv/blob/servant/design-docs/libkazvfixtures.md Instantiate a ClientModel using an empty ComposedModifier to apply default settings without specific modifications. ```cpp auto client = makeClient({}); ``` -------------------------------- ### Write Unit Test for XXXAction in C++ Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Create a unit test using Catch2 to ensure the `updateClient` function correctly generates the job request. This test verifies job creation and checks request parameters. ```cpp // src/tests/client/xxx-test.cpp #include "client/actions/xxx.hpp" using namespace Kazv; using namespace Kazv::Factory; TEST_CASE("XXXAction", "[client][xxx]") // add test tags as needed { auto client = makeClient(); // see design-docs/libkazvfixtures.md auto [next, _] = updateClient(client, XXXAction{...}); assert1Job(next); for1stJob(next, [](const BaseJob &job) { REQUIRE(job.url().find(...) != std::string::npos); auto body = json::parse(std::get(job.requestBody())); REQUIRE(body.at("param1") == ...); REQUIRE(body.at("param2") == ...); }); } ``` -------------------------------- ### Define kazvstore library and alias Source: https://github.com/kazv/libkazv/blob/servant/src/store/CMakeLists.txt Defines kazvstore as an INTERFACE library and creates an alias for it. ```cmake add_library(kazvstore INTERFACE) add_library(libkazv::kazvstore ALIAS kazvstore) ``` -------------------------------- ### Configure kazvcrypto library Source: https://github.com/kazv/libkazv/blob/servant/src/crypto/CMakeLists.txt Defines the source files for the kazvcrypto library and creates a CMake library target. It also sets version information and links to other libraries. ```cmake set(kazvcrypto_SRCS crypto.cpp session.cpp inbound-group-session.cpp outbound-group-session.cpp aes-256-ctr.cpp base64.cpp sha256.cpp key-export.cpp verification-process.cpp verification-utils.cpp verification-tracker.cpp sas-desc.cpp ) add_library(kazvcrypto ${kazvcrypto_SRCS}) add_library(libkazv::kazvcrypto ALIAS kazvcrypto) set_target_properties(kazvcrypto PROPERTIES VERSION ${libkazv_VERSION_STRING} SOVERSION ${libkazv_SOVERSION}) ``` -------------------------------- ### Accessing Room Information with Kazv SDK Source: https://context7.com/kazv/libkazv/llms.txt Retrieve room IDs, access specific room details like name, topic, encryption status, and membership. Also demonstrates fetching room members and their display names. ```cpp auto client = sdk.client(); // Get all room IDs auto roomIds = client.roomIds().make().get(); for (const auto& roomId : roomIds) { std::cout << "Room: " << roomId << std::endl; } // Access a specific room auto room = client.room("!roomid:example.org"); // Get room properties auto roomName = room.name().make().get(); auto topic = room.topic().make().get(); auto isEncrypted = room.encrypted().make().get(); auto membership = room.membership().make().get(); std::cout << "Room: " << roomName << std::endl; std::cout << "Topic: " << topic << std::endl; std::cout << "Encrypted: " << (isEncrypted ? "yes" : "no") << std::endl; // Get room members auto members = room.members().make().get(); for (const auto& memberId : members) { auto memberEvent = room.memberEventFor(memberId).make().get(); auto displayName = memberEvent.content().get()["displayname"].get(); std::cout << "Member: " << displayName << " (" << memberId << ")" << std::endl; } ``` -------------------------------- ### Download Thumbnail in C++ Source: https://context7.com/kazv/libkazv/llms.txt Downloads a thumbnail for a given MXC URI with specified dimensions and resizing method. The result is provided in the callback. ```cpp // Download thumbnail client.downloadThumbnail( mxcUri, 320, // Width 240, // Height Kazv::ThumbnailResizingMethod::Scale // Resize method: Scale or Crop ) .then([](auto status) { if (status.success()) { std::string thumbnail = status.dataStr("content"); std::cout << "Thumbnail size: " << thumbnail.size() << " bytes" << std::endl; } }); ``` -------------------------------- ### Define kazvbase Library Source: https://github.com/kazv/libkazv/blob/servant/src/base/CMakeLists.txt Defines the kazvbase static library with its source files and sets up an alias for external use. It also configures version information and links system libraries. ```cmake include(linklibsys) configure_file(libkazv-defs.hpp.in libkazv-defs.hpp) set(kazvbase_SRCS debug.cpp event.cpp basejob.cpp file-desc.cpp ) add_library(kazvbase ${kazvbase_SRCS}) add_library(libkazv::kazvbase ALIAS kazvbase) set_target_properties(kazvbase PROPERTIES VERSION ${libkazv_VERSION_STRING} SOVERSION ${libkazv_SOVERSION}) ``` -------------------------------- ### Download Content to Memory in C++ Source: https://context7.com/kazv/libkazv/llms.txt Downloads content from the Matrix content repository to memory using an MXC URI. The callback provides the downloaded content as a string. ```cpp auto client = sdk.client(); std::string mxcUri = "mxc://example.org/abc123"; // Download to memory client.downloadContent(mxcUri) .then([](auto status) { if (status.success()) { std::string content = status.dataStr("content"); std::cout << "Downloaded " << content.size() << " bytes" << std::endl; } }); ``` -------------------------------- ### Configure CMake for libkazv Project Source: https://github.com/kazv/libkazv/blob/servant/tutorials/CMakeLists.txt This CMakeLists.txt file sets up the build environment for a C++ project using libkazv. It specifies the C++ standard, compiler flags, finds the libkazv package, and links the executable against the necessary libkazv targets. ```cmake cmake_minimum_required(VERSION 3.16) project(libkazv-tutorials) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") find_package(libkazv REQUIRED COMPONENTS job) add_executable(tutorial0 tutorial0.cpp) target_link_libraries(tutorial0 libkazv::kazvall libkazv::kazvjob) ``` -------------------------------- ### Token Login with Matrix SDK Source: https://context7.com/kazv/libkazv/llms.txt Restores a user session using an access token and device ID. Useful for session persistence. ```cpp auto client = sdk.client(); std::string homeserver = "https://matrix.example.org"; std::string userId = "@alice:example.org"; std::string accessToken = "syt_abc123..."; std::string deviceId = "ABCDEFGH"; client.tokenLogin(homeserver, userId, accessToken, deviceId) .then([=](auto status) { if (!status.success()) { std::cerr << "Token login failed" << std::endl; return; } std::cout << "Session restored successfully" << std::endl; client.startSyncing(); }); ``` -------------------------------- ### Join Room by Alias with Matrix SDK Source: https://context7.com/kazv/libkazv/llms.txt Joins a Matrix room using its alias, optionally providing server hints for federated rooms. This is useful when the room alias is known but the room ID is not. ```cpp auto client = sdk.client(); // Join by room alias with server hints client.joinRoom( "#public-room:example.org", // Room ID or alias immer::array{ // Server names (via parameter) "example.org", "matrix.org" } ) .then([](auto status) { if (status.success()) { std::cout << "Joined room via alias" << std::endl; } }); ``` -------------------------------- ### Manage Room Tags Source: https://context7.com/kazv/libkazv/llms.txt Organize rooms using tags like favorites. Use `addOrSetTag` to apply or update tags and `removeTag` to delete them. The SDK also provides methods to retrieve tags for a room and list rooms by tag. ```cpp auto client = sdk.client(); auto room = client.room("!roomid:example.org"); // Add room to favorites room.addOrSetTag("m.favourite", 0.5) // Order is optional .then([](auto status) { if (status.success()) { std::cout << "Room added to favorites" << std::endl; } }); // Get room tags auto tags = room.tags().make().get(); for (const auto& [tagId, order] : tags) { std::cout << "Tag: " << tagId << " (order: " << order << ")" << std::endl; } // Get rooms by tag auto favoriteRooms = client.roomIdsUnderTag("m.favourite").make().get(); for (const auto& [roomId, order] : favoriteRooms) { std::cout << "Favorite room: " << roomId << std::endl; } // Remove tag room.removeTag("m.favourite") .then([](auto status) { if (status.success()) { std::cout << "Tag removed" << std::endl; } }); ``` -------------------------------- ### Link kazvtestfixtures with kazvclient Source: https://github.com/kazv/libkazv/blob/servant/src/testfixtures/CMakeLists.txt Links the 'kazvtestfixtures' library with the 'kazvclient' library, making 'kazvclient' public to dependents of 'kazvtestfixtures'. ```cmake target_link_libraries( kazvtestfixtures PUBLIC kazvclient ) ``` -------------------------------- ### Restore SDK State using Boost.Serialization Source: https://context7.com/kazv/libkazv/llms.txt Load the saved state of the Kazv SDK client from a file using Boost.Serialization. This enables restoring the client's session and continuing from where it left off. ```cpp // Later, restore the state { std::ifstream ifs("session.dat"); boost::archive::text_iarchive ia(ifs); Kazv::SdkModel savedModel; ia >> savedModel; // Create new SDK with restored model auto restoredSdk = Kazv::makeSdk( savedModel, jh, ee, Kazv::AsioPromiseHandler{io.get_executor()}, zug::identity ); auto restoredClient = restoredSdk.client(); restoredClient.startSyncing(); } ``` -------------------------------- ### Link kazvstore with kazvbase Source: https://github.com/kazv/libkazv/blob/servant/src/store/CMakeLists.txt Specifies that the kazvstore library depends on kazvbase. ```cmake target_link_libraries(kazvstore INTERFACE kazvbase) ``` -------------------------------- ### Join Room by ID with Matrix SDK Source: https://context7.com/kazv/libkazv/llms.txt Joins an existing Matrix room using its unique room ID. This is a direct way to access a known room. ```cpp auto client = sdk.client(); // Join by room ID client.joinRoomById("!roomid:example.org") .then([](auto status) { if (status.success()) { std::cout << "Joined room successfully" << std::endl; } }); ``` -------------------------------- ### Set Compile Options and Definitions for kazvbase Source: https://github.com/kazv/libkazv/blob/servant/src/base/CMakeLists.txt Configures compiler options and definitions for the kazvbase library. It enables exceptions and defines specific preprocessor macros for exception handling in dependent libraries. ```cmake target_compile_options(kazvbase PUBLIC "-fexceptions") target_compile_definitions(kazvbase PUBLIC -DLAGER_USE_EXCEPTIONS -DIMMER_USE_EXCEPTIONS) ``` -------------------------------- ### Add Store Tests Source: https://github.com/kazv/libkazv/blob/servant/src/tests/CMakeLists.txt Uses `libkazv_add_tests` to add tests for the store module, linking against `kazvstore` and `kazvjob`. ```cmake libkazv_add_tests( store-test.cpp EXTRA_LINK_LIBRARIES kazvstore kazvjob ) ``` -------------------------------- ### Create Secondary Root for Thread-Safety Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Establish a secondary store and event loop in a different thread to safely operate on cursors from that thread. This involves watching the primary store and dispatching its model to the secondary store. ```cpp auto secondaryStore = makeStore( initialModel, lager::with_reducer([](Model, Model next) { return next; }), ... // pass an event loop running in the desired thread ); lager::watch(mainStore, [ctx=secondaryStore.context()](Model m) { ctx.dispatch(std::move(m)); }); // in the thread of the secondary store's event loop auto cursor = secondaryStore.map(...); ``` -------------------------------- ### Define Application State Model Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Define the structure for your application's state. This struct will hold the current state of your application. ```cpp struct Model { /* ... */ }; Model current; ``` -------------------------------- ### Add Room to Client Model with withRoom() Source: https://github.com/kazv/libkazv/blob/servant/design-docs/libkazvfixtures.md Employ the withRoom() modifier to add a pre-created RoomModel to a client's room list, simplifying the process compared to manual map manipulation. ```cpp auto client = makeClient( withRoom(makeRoom({})) ); ``` -------------------------------- ### Post Read Receipts and Manage Read Markers Source: https://context7.com/kazv/libkazv/llms.txt Send read receipts for events using `postReceipt` and retrieve the latest read marker with `readMarker`. This section also covers fetching readers for specific events and listing unread notification event IDs. ```cpp auto client = sdk.client(); auto room = client.room("!roomid:example.org"); // Send read receipt for an event room.postReceipt("$lasteventid") .then([](auto status) { if (status.success()) { std::cout << "Read receipt sent" << std::endl; } }); // Get the current read marker auto readMarker = room.readMarker().make().get(); std::cout << "Read up to: " << readMarker << std::endl; // Get readers of a specific event auto eventId = lager::make_constant(std::string("$someeventid")); auto readers = room.eventReaders(eventId).make().get(); for (const auto& reader : readers) { std::cout << reader.userId << " read at " << reader.ts << std::endl; } // Get unread notification event IDs auto unreadIds = room.unreadNotificationEventIds().make().get(); std::cout << "Unread notifications: " << unreadIds.size() << std::endl; ``` -------------------------------- ### Combine Cursors with lager::with() Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Combine multiple cursors into a single cursor whose value is derived from the values of the combined cursors. Requires a map function that accepts arguments for each cursor. ```cpp lager::reader a = ...; lager::reader b = ...; lager::reader c = lager::with(a, b).map( [](int aValue, int bValue) { return aValue + bValue; }); ``` -------------------------------- ### Dispatching an Action and Handling Promise Resolution in C++ Source: https://github.com/kazv/libkazv/blob/servant/design-docs/architecture.md Dispatch an action using the context and attach a continuation callback to the returned Promise. The callback executes after the action's reducer and effect have completed, receiving the effect's return value. ```cpp auto promise = ctx.dispatch(action); promise.then([](auto status) { // this will be run after the reducer for action is run, // and after the effect returned by the reducer is run. // `status` will contain the value returned from the effect. }); ```