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

fix: post sharing logic #58

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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