-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration federation lookup module
- Loading branch information
Showing
16 changed files
with
687 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...les/federation_identity_lookup/data/datasource/federation_identity_lookup_datasource.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_hash_details_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_request.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_register_response.dart'; | ||
import 'package:fluffychat/modules/federation_indetity_request_token/domain/models/federation_token_information.dart'; | ||
|
||
abstract class FederationIdentityLookupDatasource { | ||
Future<FederationRegisterResponse> register({ | ||
required FederationTokenInformation tokenInformation, | ||
}); | ||
|
||
Future<FederationHashDetailsResponse> getHashDetails({ | ||
required String token, | ||
}); | ||
|
||
Future<FederationLookupMxidResponse> lookupMxid({ | ||
required FederationLookupMxidRequest request, | ||
required String token, | ||
}); | ||
} |
45 changes: 45 additions & 0 deletions
45
...tion_identity_lookup/data/datasource_impl/federation_identity_lookup_datasource_impl.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:fluffychat/modules/federation_identity_lookup/data/datasource/federation_identity_lookup_datasource.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/data/network/federation_identity_lookup_api.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_hash_details_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_request.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_register_response.dart'; | ||
import 'package:fluffychat/modules/federation_indetity_request_token/domain/models/federation_token_information.dart'; | ||
|
||
class FederationIdentityLookupDatasourceImpl | ||
implements FederationIdentityLookupDatasource { | ||
final FederationIdentityLookupApi federationIdentityLookupApi; | ||
|
||
FederationIdentityLookupDatasourceImpl({ | ||
required this.federationIdentityLookupApi, | ||
}); | ||
|
||
@override | ||
Future<FederationHashDetailsResponse> getHashDetails({ | ||
required String token, | ||
}) { | ||
return federationIdentityLookupApi.getHashDetails( | ||
token, | ||
); | ||
} | ||
|
||
@override | ||
Future<FederationLookupMxidResponse> lookupMxid({ | ||
required FederationLookupMxidRequest request, | ||
required String token, | ||
}) { | ||
return federationIdentityLookupApi.lookupMxid( | ||
request: request, | ||
token: token, | ||
); | ||
} | ||
|
||
@override | ||
Future<FederationRegisterResponse> register({ | ||
required FederationTokenInformation tokenInformation, | ||
}) { | ||
return federationIdentityLookupApi.register( | ||
tokenInformation: tokenInformation, | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
lib/modules/federation_identity_lookup/data/network/federation_identity_endpoint.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:fluffychat/data/network/service_path.dart'; | ||
|
||
class FederationIdentityEndpoint { | ||
static const String federationIdentityRootPath = '/_matrix/identity'; | ||
static const String federationIdentityAPIVersion = 'v2'; | ||
|
||
static const federationIdentityDioClientName = | ||
'federationIdentityDioClientName'; | ||
|
||
static const acceptHeaderDefault = 'application/json'; | ||
|
||
static const contentTypeHeaderDefault = 'application/json'; | ||
|
||
static final ServicePath lookupServicePath = ServicePath( | ||
'/lookup', | ||
); | ||
|
||
static final ServicePath hashDetailsServicePath = ServicePath( | ||
'/hash_details', | ||
); | ||
|
||
static final ServicePath registerServicePath = ServicePath( | ||
'/register', | ||
); | ||
} | ||
|
||
extension FederationServicePathExtensions on ServicePath { | ||
String generateFederationIdentityEndpoint({ | ||
String rootPath = FederationIdentityEndpoint.federationIdentityRootPath, | ||
String apiVersion = FederationIdentityEndpoint.federationIdentityAPIVersion, | ||
}) { | ||
return '$rootPath/$apiVersion$path'; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
lib/modules/federation_identity_lookup/data/network/federation_identity_lookup_api.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/data/network/federation_identity_endpoint.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_hash_details_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_request.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_register_response.dart'; | ||
import 'package:fluffychat/modules/federation_indetity_request_token/domain/models/federation_token_information.dart'; | ||
import 'package:fluffychat/data/network/dio_client.dart'; | ||
|
||
class FederationIdentityLookupApi { | ||
final DioClient client; | ||
|
||
FederationIdentityLookupApi(this.client); | ||
|
||
Future<FederationRegisterResponse> register({ | ||
required FederationTokenInformation tokenInformation, | ||
}) async { | ||
final path = FederationIdentityEndpoint.registerServicePath | ||
.generateFederationIdentityEndpoint(); | ||
|
||
final response = await client.postToGetBody( | ||
path, | ||
data: tokenInformation.toJson(), | ||
); | ||
|
||
return FederationRegisterResponse.fromJson(response); | ||
} | ||
|
||
Future<FederationHashDetailsResponse> getHashDetails(String token) async { | ||
final path = FederationIdentityEndpoint.hashDetailsServicePath | ||
.generateFederationIdentityEndpoint(); | ||
|
||
final dioHeaders = client.getHeaders(); | ||
|
||
dioHeaders[HttpHeaders.authorizationHeader] = 'Bearer $token'; | ||
|
||
final response = await client.get( | ||
path, | ||
options: Options(headers: dioHeaders), | ||
); | ||
|
||
return FederationHashDetailsResponse.fromJson(response); | ||
} | ||
|
||
Future<FederationLookupMxidResponse> lookupMxid({ | ||
required FederationLookupMxidRequest request, | ||
required String token, | ||
}) async { | ||
final path = FederationIdentityEndpoint.lookupServicePath | ||
.generateFederationIdentityEndpoint(); | ||
|
||
final dioHeaders = client.getHeaders(); | ||
|
||
dioHeaders[HttpHeaders.authorizationHeader] = 'Bearer $token'; | ||
|
||
final response = await client.postToGetBody( | ||
path, | ||
data: request.toJson(), | ||
options: Options(headers: dioHeaders), | ||
); | ||
|
||
return FederationLookupMxidResponse.fromJson(response); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...tion_identity_lookup/data/repository_impl/federation_identity_lookup_repository_impl.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:fluffychat/modules/federation_identity_lookup/data/datasource/federation_identity_lookup_datasource.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_hash_details_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_request.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_register_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/repository/federation_identity_lookup_repository.dart'; | ||
import 'package:fluffychat/modules/federation_indetity_request_token/domain/models/federation_token_information.dart'; | ||
|
||
class FederationIdentityLookupRepositoryImpl | ||
implements FederationIdentityLookupRepository { | ||
final FederationIdentityLookupDatasource datasource; | ||
|
||
FederationIdentityLookupRepositoryImpl({required this.datasource}); | ||
|
||
@override | ||
Future<FederationHashDetailsResponse> getHashDetails({ | ||
required String token, | ||
}) { | ||
return datasource.getHashDetails( | ||
token: token, | ||
); | ||
} | ||
|
||
@override | ||
Future<FederationLookupMxidResponse> lookupMxid({ | ||
required FederationLookupMxidRequest request, | ||
required String token, | ||
}) { | ||
return datasource.lookupMxid( | ||
request: request, | ||
token: token, | ||
); | ||
} | ||
|
||
@override | ||
Future<FederationRegisterResponse> register({ | ||
required FederationTokenInformation tokenInformation, | ||
}) { | ||
return datasource.register( | ||
tokenInformation: tokenInformation, | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
lib/modules/federation_identity_lookup/domain/models/federation_arguments.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:fluffychat/modules/federation_indetity_request_token/domain/models/federation_token_information.dart'; | ||
|
||
class FederationArguments with EquatableMixin { | ||
final String federationUrl; | ||
|
||
final FederationTokenInformation tokenInformation; | ||
|
||
final Set<String>? phoneNumbers; | ||
|
||
final Set<String>? emailAddresses; | ||
|
||
FederationArguments({ | ||
required this.federationUrl, | ||
required this.tokenInformation, | ||
this.phoneNumbers, | ||
this.emailAddresses, | ||
}); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
federationUrl, | ||
tokenInformation, | ||
phoneNumbers, | ||
emailAddresses, | ||
]; | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/modules/federation_identity_lookup/domain/models/federation_hash_details_response.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'federation_hash_details_response.g.dart'; | ||
|
||
@JsonSerializable() | ||
class FederationHashDetailsResponse extends Equatable { | ||
@JsonKey(name: 'algorithms') | ||
final Set<String>? algorithms; | ||
|
||
@JsonKey(name: 'lookup_pepper') | ||
final String? lookupPepper; | ||
|
||
const FederationHashDetailsResponse({ | ||
this.algorithms, | ||
this.lookupPepper, | ||
}); | ||
|
||
@override | ||
List<Object?> get props => [algorithms, lookupPepper]; | ||
|
||
factory FederationHashDetailsResponse.fromJson(Map<String, dynamic> json) => | ||
_$FederationHashDetailsResponseFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$FederationHashDetailsResponseToJson(this); | ||
} |
28 changes: 28 additions & 0 deletions
28
lib/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_request.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'federation_lookup_mxid_request.g.dart'; | ||
|
||
@JsonSerializable() | ||
class FederationLookupMxidRequest extends Equatable { | ||
@JsonKey(name: 'addresses') | ||
final Set<String>? addresses; | ||
@JsonKey(name: 'algorithm') | ||
final String? algorithm; | ||
@JsonKey(name: 'pepper') | ||
final String? pepper; | ||
|
||
const FederationLookupMxidRequest({ | ||
this.addresses, | ||
this.algorithm, | ||
this.pepper, | ||
}); | ||
|
||
factory FederationLookupMxidRequest.fromJson(Map<String, dynamic> json) => | ||
_$FederationLookupMxidRequestFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$FederationLookupMxidRequestToJson(this); | ||
|
||
@override | ||
List<Object?> get props => [addresses, algorithm, pepper]; | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_response.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'federation_lookup_mxid_response.g.dart'; | ||
|
||
@JsonSerializable() | ||
class FederationLookupMxidResponse extends Equatable { | ||
@JsonKey(name: 'mappings') | ||
final Map<String, String>? mappings; | ||
|
||
@JsonKey(name: 'inactive_mappings') | ||
final Map<String, String>? inactiveMappings; | ||
|
||
const FederationLookupMxidResponse({ | ||
this.mappings, | ||
this.inactiveMappings, | ||
}); | ||
|
||
factory FederationLookupMxidResponse.fromJson(Map<String, dynamic> json) => | ||
_$FederationLookupMxidResponseFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$FederationLookupMxidResponseToJson(this); | ||
|
||
@override | ||
List<Object?> get props => [mappings, inactiveMappings]; | ||
} |
22 changes: 22 additions & 0 deletions
22
lib/modules/federation_identity_lookup/domain/models/federation_register_response.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'federation_register_response.g.dart'; | ||
|
||
@JsonSerializable() | ||
class FederationRegisterResponse extends Equatable { | ||
@JsonKey(name: "token") | ||
final String? token; | ||
|
||
const FederationRegisterResponse({ | ||
this.token, | ||
}); | ||
|
||
factory FederationRegisterResponse.fromJson(Map<String, dynamic> json) => | ||
_$FederationRegisterResponseFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$FederationRegisterResponseToJson(this); | ||
|
||
@override | ||
List<Object?> get props => [token]; | ||
} |
20 changes: 20 additions & 0 deletions
20
...s/federation_identity_lookup/domain/repository/federation_identity_lookup_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_hash_details_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_request.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_lookup_mxid_response.dart'; | ||
import 'package:fluffychat/modules/federation_identity_lookup/domain/models/federation_register_response.dart'; | ||
import 'package:fluffychat/modules/federation_indetity_request_token/domain/models/federation_token_information.dart'; | ||
|
||
abstract class FederationIdentityLookupRepository { | ||
Future<FederationRegisterResponse> register({ | ||
required FederationTokenInformation tokenInformation, | ||
}); | ||
|
||
Future<FederationHashDetailsResponse> getHashDetails({ | ||
required String token, | ||
}); | ||
|
||
Future<FederationLookupMxidResponse> lookupMxid({ | ||
required FederationLookupMxidRequest request, | ||
required String token, | ||
}); | ||
} |
Oops, something went wrong.