Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CONTACT SYNC V2] Extract Fed server in well-know #2220

Open
nqhhdev opened this issue Jan 23, 2025 · 0 comments
Open

[CONTACT SYNC V2] Extract Fed server in well-know #2220

nqhhdev opened this issue Jan 23, 2025 · 0 comments

Comments

@nqhhdev
Copy link
Member

nqhhdev commented Jan 23, 2025

How to extract Fed server in well-know

  • ENDPOINT {{homeserver}}.well-known/matrix/client

  • Response

{
    ...
    "m.federated_identity_services": {
        "base_urls": [
            "https://fed...com/"
        ]
    },
    ...
}

Create Fed server info:

@JsonSerializable()
class FedServerInformation with EquatableMixin {
  static const String fedServerKey = 'm.federated_identity_services';

  @JsonKey(name: 'base_url')
  final Uri? baseUrl;

  @JsonKey(name: 'server_name')
  final String? serverName;

  FedServerInformation({
    this.baseUrl,
    this.serverName,
  });

  factory FedServerInformation.fromJson(Map<String, dynamic> json) =>
      _$FedServerInformationFromJson(json);

  Map<String, dynamic> toJson() => _$FedServerInformationToJson(this);

  @override
  List<Object?> get props => [baseUrl, serverName];
}

Create FedConfigurations

class FedConfigurations with EquatableMixin {
  final FedServerInformation fedServerInformation;
  final IdentityServerInformation? identityServerInformation;
  final String? authUrl;
  final LoginType? loginType;

  FedConfigurations({
    required this.tomServerInformation,
    this.identityServerInformation,
    this.authUrl,
    this.loginType,
  });

  @override
  List<Object?> get props =>
      [fedServerInformation, identityServerInformation, authUrl, loginType];
}

Convert response from .well-know to FedServerInformation

  • Write func convert it in HomeserverSummaryExtensions: lib/domain/model/extensions/homeserver_summary_extensions.dart
FedServerInformation? get fedServer {
    if (discoveryInformation?.additionalProperties == null) {
      return null;
    }
    final fedServerJson = discoveryInformation
        ?.additionalProperties[FedServerInformation.fedServerKey];
    if (fedServerJson == null) {
      return null;
    }
    try {
      return FedServerInformation.fromJson(fedServerJson);
    } catch (e) {
      Logs().e('Failed to parse m.federated_identity_services from homeserver summary', e);
      return null;
    }
  }

Create FedConfigurationsRepository

abstract class FedConfigurationsRepository {
  Future<FedConfigurations> getFedConfigurations(String userId);

  Future<void> saveFedConfigurations(
    String userId,
    FedConfigurations fedConfigurations,
  );

  Future<void> deleteFedConfigurations(String userId);
}

Create new Fed dio in NetworkDI

class NetworkDI extends BaseDI {
  static const fedServerUrlInterceptorName = 'fedServerDynamicUrlInterceptor';
  static const fedServerDioName = 'fedServerDioName';
  static const fedDioClientName = 'fedServerDioClientName';

  void _bindInterceptor(GetIt get) { 
    get.registerLazySingleton(
      () => DynamicUrlInterceptors(),
      instanceName: fedServerUrlInterceptorName,
    );
  }

  void _bindDio(GetIt get) {
    _bindDioForFedServer(get);
  }

  void _bindDioForFedServer(GetIt Get) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant