Skip to content

Commit

Permalink
Merge pull request #58 from les-transformations/fix/sharing-logic
Browse files Browse the repository at this point in the history
fix: post sharing logic
  • Loading branch information
divyanshgandhilm authored Nov 9, 2023
2 parents 4af2753 + 938b877 commit 266b183
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions lib/src/utils/share/share_post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class SharePost {
static String userId = prodFlag ? CredsProd.botId : CredsDev.botId;
static String apiKey = prodFlag ? CredsProd.apiKey : CredsDev.apiKey;
// TODO: Add domain to your application
String domain = 'suraasalearn://www.suraasa.com';
String domain = 'https://www.suraasa.com';
// fetches the domain given by client at time of initialization of Feed

// below function creates a link from domain and post id
String createLink(String postId) {
int length = domain.length;
if (domain[length - 1] == '/') {
return "${domain}post?post_id=$postId";
return "${domain}community/post?post_id=$postId";
} else {
return "$domain/post?post_id=$postId";
return "$domain/community/post?post_id=$postId";
}
}

Expand All @@ -45,17 +45,21 @@ class SharePost {
}
}

Future<DeepLinkResponse> handlePostDeepLink(DeepLinkRequest request, BuildContext context) async {
Future<DeepLinkResponse> handlePostDeepLink(
DeepLinkRequest request,
GlobalKey<NavigatorState> navigatorKey,
) async {
List secondPathSegment = request.link.split('post_id=');
if (secondPathSegment.length > 1 && secondPathSegment[1] != null) {
String postId = secondPathSegment[1];
await locator<LikeMindsService>().initiateUser((InitiateUserRequestBuilder()
..apiKey(request.apiKey)
..userId(request.userUniqueId)
..userName(request.userName))
.build());
await locator<LikeMindsService>()
.initiateUser((InitiateUserRequestBuilder()
..apiKey(request.apiKey)
..userId(request.userUniqueId)
..userName(request.userName))
.build());

Navigator.of(context).push(
navigatorKey.currentState!.push(
MaterialPageRoute(
builder: (context) => PostDetailScreen(postId: postId),
),
Expand All @@ -73,13 +77,15 @@ class SharePost {
}
}

Future<DeepLinkResponse> parseDeepLink(DeepLinkRequest request, BuildContext context) async {
if (Uri.parse(request.link).isAbsolute) {
final firstPathSegment = getFirstPathSegment(request.link);
if (firstPathSegment == "post") {
return handlePostDeepLink(request, context);
Future<DeepLinkResponse> parseDeepLink(
DeepLinkRequest request, GlobalKey<NavigatorState> navigatorKey) async {
final link = Uri.parse(request.link);
if (link.isAbsolute) {
if (link.path == '/community/post') {
return handlePostDeepLink(request, navigatorKey);
}
return DeepLinkResponse(success: false, errorMessage: 'URI not supported');
return DeepLinkResponse(
success: false, errorMessage: 'URI not supported');
} else {
return DeepLinkResponse(
success: false,
Expand Down

0 comments on commit 266b183

Please sign in to comment.