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: in web implementation session token is never used during the place autocomplete #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mrcsilverfox
Copy link
Contributor

@mrcsilverfox mrcsilverfox commented May 21, 2023

In web implementation session token is never used during the place autocomplete

@mrcsilverfox mrcsilverfox force-pushed the web-session-token-is-never-used branch from ad382e0 to ad81622 Compare May 21, 2023 09:58
@@ -100,6 +100,14 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
return _completer?.isCompleted == true;
}

AutocompleteSessionToken _getSessionToken({required bool force}) {
final localToken = _lastSessionToken;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on it a bit?

I need to understand how this code is supposed to work.
According to code, _lastSessionToken is always null just because it's never assigned.

Shouldn't it be something like

 return force || _lastSessionToken == null ? (_lastSessionToken = AutocompleteSessionToken()) : _lastSessionToken!;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreiMisiukevich ther last session token should be set from the response - not from us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreiMisiukevich Before, the _lastSessionToken was always null, now on each request we check if the session token is valid and set a new session token if needed: _lastSessionToken is null on first request.

@@ -116,13 +124,15 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
// https://issuetracker.google.com/issues/36219203
log("locationRestriction is not supported: https://issuetracker.google.com/issues/36219203");
}
final sessionToken = _getSessionToken(force: newSessionToken == true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final sessionToken = _getSessionToken(force: newSessionToken == true);
final sessionToken = _getSessionToken(force: newSessionToken ?? false);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreiMisiukevich it has the same meaning, and == true is what we do in the mobile implementation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matanshukry Yeah, I got it.
Just think it doesn't look good. But yeah, it's a personal preference, I think. Not a clean code rule :)

Copy link
Owner

@matanshukry matanshukry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also mentioned that in the comments - but the last session token should be set based on the response -which is missing here.

Also see this: #31 fro the corect usage of the tokens, which it doesn't do.

  1. If you match the web package to the mobile (missing setting the value from the response) - we'll merge.
  2. If you prefer to go ahead and impleemnt the correct behavior based on the issue - we can merge that too.

@@ -116,13 +124,15 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
// https://issuetracker.google.com/issues/36219203
log("locationRestriction is not supported: https://issuetracker.google.com/issues/36219203");
}
final sessionToken = _getSessionToken(force: newSessionToken == true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreiMisiukevich it has the same meaning, and == true is what we do in the mobile implementation

@@ -100,6 +100,14 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
return _completer?.isCompleted == true;
}

AutocompleteSessionToken _getSessionToken({required bool force}) {
final localToken = _lastSessionToken;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreiMisiukevich ther last session token should be set from the response - not from us.

@mrcsilverfox
Copy link
Contributor Author

@AndreiMisiukevich why the install dependencies failed? Which version of flutter is needed?

@matanshukry
Copy link
Owner

@mrcsilverfox it's because of the flutter version the CI is using; you can ignore that.

@mrcsilverfox
Copy link
Contributor Author

mrcsilverfox commented May 26, 2023

I also mentioned that in the comments - but the last session token should be set based on the response -which is missing here.

Also see this: #31 fro the corect usage of the tokens, which it doesn't do.

  1. If you match the web package to the mobile (missing setting the value from the response) - we'll merge.
  2. If you prefer to go ahead and impleemnt the correct behavior based on the issue - we can merge that too.

Do you think that is enough?

final prom = _svcAutoComplete!.getPlacePredictions(
      AutocompletionRequest()
        ..input = query
        ..origin = origin == null ? null : core.LatLng(origin.lat, origin.lng)
        ..types = typeFilterStr == null ? null : [typeFilterStr]
        ..componentRestrictions = (ComponentRestrictions()..country = countries)
        ..bounds = _boundsToWeb(locationBias)
        ..sessionToken = sessionToken
        ..language = _language,
      (results, status) {
        if (status == PlacesServiceStatus.OK ||
            status == PlacesServiceStatus.ZERO_RESULTS ||
            status == PlacesServiceStatus.NOT_FOUND) {
          _lastSessionToken = sessionToken;
        } else {
          log('API_ERROR: $status');
        }
      },
    );

Or we have to use the completer as used in _getDetails method?

Although I didn't understand why the session token should be set based on the response. Why can't the session token be set in the getSessionToken method?

@mrcsilverfox mrcsilverfox force-pushed the web-session-token-is-never-used branch 2 times, most recently from b7fecf5 to 3dc608f Compare May 27, 2023 17:46
@mrcsilverfox mrcsilverfox force-pushed the web-session-token-is-never-used branch from 3dc608f to 2630d5a Compare May 27, 2023 17:47
@mrcsilverfox
Copy link
Contributor Author

@matanshukry Any updates on this PR?

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

Successfully merging this pull request may close these issues.

3 participants