Skip to content

Conversation

@BillCarsonFr
Copy link
Member

Fixes #4045

Align default encrypted for restricted room as web is doing it, i.e use what is in well-known (default e2e).
Private and restricted encrypted switch is on if well-known e2e is by default.
=> Also if the user did manually change the encrypted toggled then always take that value and not the default.

Additional Fix:
When no space was selected, the option to set the room to restricted was visible, that would create a room restricted to nothing. So now if no space selected you'll only have a choice between Private or Public

+ hide restricted rule if no current space selected
@github-actions
Copy link

github-actions bot commented Sep 27, 2021

Unit Test Results

  42 files  ±0    42 suites  ±0   46s ⏱️ ±0s
  83 tests ±0    83 ✔️ ±0  0 💤 ±0  0 ±0 
220 runs  ±0  220 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 242b172. ± Comparison against base commit 242b172.

♻️ This comment has been updated with latest results.

}
)
switchChecked(viewState.isEncrypted)
if (viewState.isEncrypted != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Something I've noticed through the codebase is we tend to favour inverted if conditions, it might just be me but I find positive conditions much easier on the brain

if (viewState.isEncrypted == null) {
  switchChecked(viewState.defaultEncrypted[viewState.roomJoinRules] ?: false)
} else {
  switchChecked(viewState.isEncrypted)
}

and whilst inverting the if ^^^ I also noticed we could simplify the checked state by chaining the fallbacks

val isSwitchChecked = viewState.isEncrypted ?: viewState.defaultEncrypted[viewState.roomJoinRules] ?: false

Copy link
Member

Choose a reason for hiding this comment

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

Generally I agree to avoid if(!cond) {} else {}, but sometimes it also nice to have the most common case first. I'm not saying this is the case here, just wanted to add my two pence :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I explicitly used the if/else like that thinking it will ease reading of the code (otherwise I would have gone for the chaining).
Looks like I failed :D.

val allowed = if (state.supportsRestricted) {
// If restricted is supported and the user is in the context of a parent space
// then show restricted option.
val allowed = if (state.supportsRestricted && state.parentSpaceId != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: if we wanted to avoid using separate branches for appending to the list (and potentially be more kotlin idiomatic) we could use

listOfNotNull

val list = listOfNotNull(
        INVITE,
        PUBLIC,
        RESTRICTED.takeIf { state.supportsRestricted && state.parentSpaceId != null }
)

or buildList

val list = buildList {
    add(INVITE)
    add(PUBLIC)
    if (state.supportsRestricted && state.parentSpaceId != null) {
        add(RESTRICTED)
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

AS is telling me that it's experimental

Copy link
Contributor

Choose a reason for hiding this comment

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

ah my bad, I totally forgot that buildList is still experimental

if (state.isEncrypted) {
enableEncryption()
// we ignore the isEncrypted for public room as the switch is hidden in this case
if (state.roomJoinRules != RoomJoinRules.PUBLIC && state.isEncrypted != null) {
Copy link
Contributor

@ouchadam ouchadam Sep 28, 2021

Choose a reason for hiding this comment

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

NIT: it might be clearer to convert this to a when and decouple isEncrypted creation from the enableEncryption()

val isEncrypted = when {
  // public rooms use the default encrypted join rules as the switch is hidden
  state.roomJoinRules == RoomJoinRules.PUBLIC -> state.defaultEncrypted[state.roomJoinRules] ?: false
  else -> state.isEncrypted ?: false
}

if (isEncrypted) {
  enableEncryption()
}

what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

?: false can also get out the when branch. We also have a nice .orFalse extension.
@BillCarsonFr if you copy this code, please fix the typo in isEncrpyted 😛

Copy link
Contributor

Choose a reason for hiding this comment

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

for some reason I can't type isEncrypted 🤦

Copy link
Member Author

Choose a reason for hiding this comment

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

ah ah I definitly failed to make it clearer :D

@ouchadam
Copy link
Contributor

ouchadam commented Sep 28, 2021

awesome stuff! 💯 I'm attempting to use https://emmer.dev/blog/code-review-comment-prefixes/ to hopefully avoid confusion in my reviews 😅

NIT being opinionated optional comments

would be handy to have screenshots for those of us who aren't familiar with the area (if possible) 🙏

switchChecked(viewState.isEncrypted)
} else {
switchChecked(viewState.defaultEncrypted[viewState.roomJoinRules] ?: false)
}
Copy link
Member

Choose a reason for hiding this comment

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

In this case, I would have probably write:

switchChecked(
    viewState.isEncrypted
    ?: viewState.defaultEncrypted[viewState.roomJoinRules]
    ?: false
)

val aliasLocalPart: String? = null,
val isSubSpace: Boolean = false
val isSubSpace: Boolean = false,
val defaultEncrypted: Map<RoomJoinRules, Boolean> = emptyMap()
Copy link
Member

Choose a reason for hiding this comment

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

I'm sensitive to ordering declarations, why not adding this just after val isEncrypted, instead of appending it at the end?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

LGTM, just some comment on top on @adam comments :)

@BillCarsonFr BillCarsonFr added A-Spaces Spaces, groups, communities Z-NextRelease For issues and PRs which should be included in the NextRelease. labels Sep 29, 2021
@BillCarsonFr BillCarsonFr requested a review from bmarty September 30, 2021 07:15
@bmarty bmarty merged commit 242b172 into develop Oct 1, 2021
@bmarty bmarty deleted the feature/bca/spaces_fix_4045 branch October 1, 2021 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Spaces Spaces, groups, communities Z-NextRelease For issues and PRs which should be included in the NextRelease.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align new room encryption default to Web

4 participants