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

Fixed constant display of error message when Social tab without Token #1849

Merged
merged 15 commits into from
May 16, 2024

Conversation

Kaz-ookid
Copy link
Contributor

addressing issue #1848

Disabled error toast when the error is InvalidPoPTokenException, otherwise it would just pop multiple times for every single chirps. The same error is displayed once on opening the Social Tab in isOwner so the user is still aware that no token is available.

@Kaz-ookid Kaz-ookid requested a review from a team as a code owner May 6, 2024 14:02
Copy link

github-actions bot commented May 6, 2024

Pull reviewers stats

Stats of the last 30 days for popstellar:

User Total reviews Time to review Total comments
K1li4nL
🥇
7
▀▀
4d 5h 54m
27
▀▀▀▀
t1b00
🥈
4
7d 16h 20m
5
onsriahi14
🥉
4
1d 16h 23m
1
arnauds5
3
18h 51m
4
simone-kalbermatter
3
1d 15h 1m
2
pierluca
2
13d 6h 29m
▀▀
5
MariemBaccari
2
1d 5h 39m
0
ljankoschek
2
18m
0
matteosz
2
13d 20h 18m
▀▀
1
DanielTavaresA
2
8d 4h 48m
5
Tyratox
1
12d 20h 49m
6
1florentin
1
2h 20m
0
sgueissa
1
25m
0
osm-alt
1
5d 17h 36m
1
quadcopterman
1
10h 19m
0
Kaz-ookid
1
15d 41m
▀▀
5
⚡️ Pull request stats

@matteosz matteosz linked an issue May 6, 2024 that may be closed by this pull request
6 tasks
Copy link
Contributor

@matteosz matteosz left a comment

Choose a reason for hiding this comment

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

Overall, I don't think that your solution solves the issue in the right way (but also that solves the issue at all, I tested the code and it seems that the message keeps spamming).

If we want the message of the poptoken missing appearing only once, the right approach would be an ad-hoc check done in the fragment creation, which maybe sets a boolean constant that tells whether the user has a valid pop token. Then, all the current methods in the social media view model which catch and log a key exception must be kept to check errors (but simply made silent in case of no token). This is obviously a much longer fix to do and I'm also happy with a more provisional solution, as long as it works though.

I suggest you test this with 2 emulator instances so you can actually simulate this behaviour.

Comment on lines 291 to 298
} catch (e: InvalidPoPTokenException) {
// InvalidPoPTokenException means the user did not attend any roll calls and had no token.
// This is not an issue worth displaying the error for every single chirps.
// This error will already show once in isOwner.
return false
} catch (e: KeyException) {
logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token)
false
Copy link
Contributor

Choose a reason for hiding this comment

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

To simplify a bit the code clarity you can exploit the fact that InvalidPoPTokenException is a subclass of KeyException, so you can use the catch only once for the most generic KeyException and use an if to logAndShow

Suggested change
} catch (e: InvalidPoPTokenException) {
// InvalidPoPTokenException means the user did not attend any roll calls and had no token.
// This is not an issue worth displaying the error for every single chirps.
// This error will already show once in isOwner.
return false
} catch (e: KeyException) {
logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token)
false
} catch (e: KeyException) {
if (e !is InvalidPoPTokenException) {
logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token)
}
false

@Kaz-ookid
Copy link
Contributor Author

I've made some updates to the token check implementation. Here's a quick rundown:

  • Launched the PoPToken validation in the SocialMediaHomeFragment's onCreateView to kick off right when the view is created.
  • Updated the ViewModel to maintain a LiveData that reflects the validity of the token.
  • Adjusted the error handling in isReactionPresent and isOwner to suppress token-related toasts if we already know the token is not setup.

Now, when opening the Social tab, we are not even getting a single toast error, but we are only getting it when trying to send a chirps while not having the token, I think it makes more sense. Finally, the error should trigger if there is an issue with the retrieval of the token, other than it being uninitialized.

This should handle the spamming issue more gracefully by centralizing the token validation and making our error handling smarter. Let me know if this works well on your end too.

matteosz
matteosz previously approved these changes May 10, 2024
Copy link
Contributor

@matteosz matteosz left a comment

Choose a reason for hiding this comment

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

LGTM! Nice job also with testing, now the error handling is much cleaner :)

@matteosz
Copy link
Contributor

LGTM! Nice job also with testing, now the error handling is much cleaner :)

Tests are failing because it hasn't been formatted, so remember to format and then either squash the commit or push it as is

@Kaz-ookid Kaz-ookid self-assigned this May 13, 2024
@CLAassistant
Copy link

CLAassistant commented May 13, 2024

CLA assistant check
All committers have signed the CLA.

…error-msg' into work-fe2-maxime-constant-social-error-msg

# Conflicts:
#	fe2-android/app/src/test/framework/robolectric/java/com/github/dedis/popstellar/testutils/UITestUtils.kt
#	fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/lao/socialmedia/ChirpListAdapterTest.kt
#	fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/lao/socialmedia/SocialMediaHomeFragmentTest.kt
…error-msg' into work-fe2-maxime-constant-social-error-msg
@matteosz matteosz self-requested a review May 15, 2024 14:15
Copy link
Contributor

@matteosz matteosz left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -60,6 +61,8 @@ constructor(
private val mNumberCharsLeft = MutableLiveData<Int>()
val bottomNavigationTab = MutableLiveData(SocialMediaTab.HOME)

private val _hasValidToken = MutableLiveData<Boolean>()
Copy link
Contributor

Choose a reason for hiding this comment

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

How come you decided to use this name convention here (I mean underscore to start the variable name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is supposed to be the convention for mutable and private data. Copilot chose the name for me, and it felt normal since I've already come across this kind of naming. But i recon it can be misleading and there should be no issue not following this dark and unknown convention

@@ -109,7 +112,7 @@ constructor(
val addChirp = AddChirp(text, parentId, timestamp)

return Single.fromCallable { validPoPToken }
.doOnSuccess { token: PoPToken ->
.doOnSuccess { token: PoPToken? ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change that? Technically the token cannot be null there: if a KeyException error is thrown and then become null, the doOnSuccess won't be triggered anyway (as it won't be a success)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.... It helped raising the coverage 😅 (since the tests are having trouble creating valid data, some of them just could not get passed this without the "?"

.subscribeOn(schedulerProvider.io())
.observeOn(schedulerProvider.mainThread())
.subscribe(
{ _ -> _hasValidToken.postValue(true) },
Copy link
Contributor

Choose a reason for hiding this comment

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

You can avoid the _ -> here

quadcopterman
quadcopterman previously approved these changes May 15, 2024
Copy link
Contributor

@quadcopterman quadcopterman left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a little comment. Nice to see that you added many tests for social media

@@ -287,7 +293,9 @@ constructor(
val toSearch = token.publicKey.encoded
senders.contains(toSearch)
} catch (e: KeyException) {
logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token)
if (_hasValidToken.value == true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you remove the "== true" in the if ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure I can since the value is Boolean? (could be null), but I'll check it out while addressing the other comments :thum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, I could not. I tried setting up the value to false in an early stage but did not change it, I guess it's really just a detail

Copy link

sonarcloud bot commented May 15, 2024

Quality Gate Passed Quality Gate passed for 'PoP - PoPCHA-Web-Client'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

sonarcloud bot commented May 15, 2024

Quality Gate Passed Quality Gate passed for 'PoP - Be2-Scala'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

sonarcloud bot commented May 15, 2024

Quality Gate Passed Quality Gate passed for 'PoP - Be1-Go'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

sonarcloud bot commented May 15, 2024

Quality Gate Passed Quality Gate passed for 'PoP - Fe1-Web'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

sonarcloud bot commented May 15, 2024

@matteosz matteosz self-requested a review May 16, 2024 08:14
Copy link
Contributor

@matteosz matteosz left a comment

Choose a reason for hiding this comment

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

LGTM!

@matteosz matteosz added this pull request to the merge queue May 16, 2024
Merged via the queue into master with commit defee58 May 16, 2024
18 checks passed
@matteosz matteosz deleted the work-fe2-maxime-constant-social-error-msg branch May 16, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Spamming Warning Toast when Social without Token
4 participants