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

check whether notif level is undefined, because 0 is falsey #651

Merged
merged 3 commits into from
May 29, 2018

Conversation

t3chguy
Copy link
Member

@t3chguy t3chguy commented May 27, 2018

so if you set @room notif=0, then js-sdk would think its actually 50 :(

Signed-off-by: Michael Telatynski 7t3chguy@gmail.com

…failed

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
@@ -455,7 +455,7 @@ RoomState.prototype.mayTriggerNotifOfType = function(notifLevelKey, userId) {
powerLevelsEvent &&
powerLevelsEvent.getContent() &&
powerLevelsEvent.getContent().notifications &&
powerLevelsEvent.getContent().notifications[notifLevelKey]
powerLevelsEvent.getContent().notifications[notifLevelKey] !== undefined
Copy link
Member

Choose a reason for hiding this comment

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

and if it's null, false, NaN, or []? Might be best to change the check to be something like this:

!isNaN(powerLevelsEvent.getContent().notifications[notifLevelKey]) 
&& typeof(powerLevelsEvent.getContent().notifications[notifLevelKey]) === 'number'

Copy link
Member Author

Choose a reason for hiding this comment

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

I got impatient and switched it and the others in this file over to a utils method isNumber I added which does pretty much the above

@t3chguy
Copy link
Member Author

t3chguy commented May 27, 2018

I kept it consistent with the other checks but did a not NaN previously, will make another pr to change them all after this one. I guess here we're trusting the server to sanitize the values

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
@t3chguy t3chguy assigned lukebarnard1 and unassigned dbkr May 29, 2018
src/utils.js Outdated
* Returns whether the given value is a finite number without type-coercion
*
* @param {*} value the value to test
* @return {boolean} whether ot not value is a finite number without type-coercion
Copy link
Contributor

Choose a reason for hiding this comment

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

"ot"

@lukebarnard1
Copy link
Contributor

I guess here we're trusting the server to sanitize the values

I don't think we are doing that here.

but did a not NaN previously

I can't see evidence of us doing that before. isFinite(NaN) returns false so I think we're fine here.

@lukebarnard1 lukebarnard1 assigned t3chguy and unassigned lukebarnard1 May 29, 2018
@t3chguy
Copy link
Member Author

t3chguy commented May 29, 2018

but did a not NaN previously

as in a local change before this commit I made, then went for !== undefined to match the rest of the class, then refactored the class

@t3chguy t3chguy assigned lukebarnard1 and unassigned t3chguy May 29, 2018
@lukebarnard1 lukebarnard1 merged commit 172044a into develop May 29, 2018
@t3chguy t3chguy deleted the t3chguy/fix_mayTriggerNotifOfType branch March 1, 2021 10:25
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.

4 participants