-
Notifications
You must be signed in to change notification settings - Fork 21
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
Integration federation lookup module #2226
Open
nqhhdev
wants to merge
2
commits into
main
Choose a base branch
from
integration-federation-lookup-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_identity_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_identity_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_identity_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_identity_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_identity_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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
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_identity_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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.