LCOV - code coverage report
Current view: top level - lib/msc_extensions/msc_2835_uia_login - msc_2835_uia_login.dart (source / functions) Hit Total Coverage
Test: merged.info Lines: 0 22 0.0 %
Date: 2024-09-30 15:57:20 Functions: 0 0 -

          Line data    Source code
       1             : library msc_2835_uia_login;
       2             : 
       3             : import 'dart:convert';
       4             : 
       5             : import 'package:http/http.dart' hide Client;
       6             : 
       7             : import 'package:matrix/matrix.dart';
       8             : 
       9             : extension UiaLogin on Client {
      10             :   /// Implementation of MSC2835:
      11             :   /// https://github.com/Sorunome/matrix-doc/blob/soru/uia-on-login/proposals/2835-uia-on-login.md
      12             :   /// Set `pathVersion` to `r0` if you need to use the previous
      13             :   /// version of the login endpoint.
      14           0 :   Future<LoginResponse> uiaLogin(
      15             :     String type, {
      16             :     String? address,
      17             :     String? deviceId,
      18             :     AuthenticationIdentifier? identifier,
      19             :     String? initialDeviceDisplayName,
      20             :     String? medium,
      21             :     String? password,
      22             :     String? token,
      23             :     String? user,
      24             :     AuthenticationData? auth,
      25             :     String pathVersion = 'v3',
      26             :     bool? refreshToken,
      27             :   }) async {
      28           0 :     final requestUri = Uri(path: '_matrix/client/$pathVersion/login');
      29           0 :     final request = Request('POST', baseUri!.resolveUri(requestUri));
      30           0 :     request.headers['content-type'] = 'application/json';
      31           0 :     request.bodyBytes = utf8.encode(jsonEncode({
      32           0 :       if (address != null) 'address': address,
      33           0 :       if (deviceId != null) 'device_id': deviceId,
      34           0 :       if (identifier != null) 'identifier': identifier.toJson(),
      35             :       if (initialDeviceDisplayName != null)
      36           0 :         'initial_device_display_name': initialDeviceDisplayName,
      37           0 :       if (medium != null) 'medium': medium,
      38           0 :       if (password != null) 'password': password,
      39           0 :       if (token != null) 'token': token,
      40           0 :       'type': type,
      41           0 :       if (user != null) 'user': user,
      42           0 :       if (auth != null) 'auth': auth.toJson(),
      43           0 :       if (refreshToken != null) 'refresh_token': refreshToken,
      44             :     }));
      45           0 :     final response = await httpClient.send(request);
      46           0 :     final responseBody = await response.stream.toBytes();
      47           0 :     if (response.statusCode != 200) unexpectedResponse(response, responseBody);
      48           0 :     final responseString = utf8.decode(responseBody);
      49           0 :     final json = jsonDecode(responseString);
      50           0 :     return LoginResponse.fromJson(json);
      51             :   }
      52             : }

Generated by: LCOV version 1.14