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

MM-23853 Support dark mode and light mode syncing with OS theme setting #18140

Closed

Conversation

komik966
Copy link

Summary

This PR adds:

  • validation for dark theme preference
  • db migration to turn off theme synchronization with os for users who have changed their theme before the introduction of this feature

Ticket Link

#15975

Release Note

Added validation for theme_dark preference on API endpoint PUT /users/:user_id/preferences

@mm-cloud-bot mm-cloud-bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Aug 14, 2021
@mattermod
Copy link
Contributor

Hello @komik966,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

@komik966
Copy link
Author

https://github.com/mattermost/mattermost-server/blob/308a88efb17e5756812a992ea17dd2cb346bcb8a/app/export.go#L35
https://github.com/mattermost/mattermost-server/blob/308a88efb17e5756812a992ea17dd2cb346bcb8a/app/import_functions.go#L583
At first sight, import/export will be not complete. From now, full theme preferences consist of theme, theme_dark, disable_theme_sync categories. Should it be fixed in this PR?

@esethna esethna added this to the v6.1.0 milestone Aug 23, 2021
@streamer45 streamer45 added 1: PM Review Requires review by a product manager 2: Dev Review Requires review by a developer 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review labels Aug 30, 2021
@mattermost mattermost deleted a comment from mattermod Sep 2, 2021
Copy link
Contributor

@streamer45 streamer45 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @komik966 🎉! I've left some questions.

@@ -116,7 +118,7 @@ func (o *Preference) PreUpdate() {

// blank out any invalid theme values
for name, value := range props {
if name == "image" || name == "type" || name == "codeTheme" {
if name == "image" || name == "type" || name == "codeTheme" || name == "colorScheme" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this colorScheme name refer to the light/dark mode?

Copy link
Author

Choose a reason for hiding this comment

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

@streamer45 possible values of colorScheme are light / dark. It is used by client apps to categorize themes in theme selection form:
Screen Shot 2021-09-02 at 17 55 32

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks 👍 I am wondering if the name is appropriate. I identify a color scheme as a set of colors and you can have many of those. Maybe lightMode would be more fitting?

Copy link
Author

Choose a reason for hiding this comment

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

@streamer45 React native uses colorScheme https://reactnative.dev/docs/appearance#getcolorscheme. I named it same way to keep "ubiquitous language".

Copy link
Author

Choose a reason for hiding this comment

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

For me, it is no problem to change it 😉

Copy link
Author

Choose a reason for hiding this comment

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

@streamer45 I think isLight would be better (this is theme's property so in the webapp we have theme.isLight)

Copy link
Contributor

Choose a reason for hiding this comment

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

React native uses colorScheme https://reactnative.dev/docs/appearance#getcolorscheme. I named it same way to keep "ubiquitous language".

TIL :)

I think isLight would be better (this is theme's property so in the webapp we have theme.isLight)

Yeah that's good as well but I have no strong opinion. We can also keep it as is since now I know why it was named that way and I am all for consistency :) @esethna , thoughts?

Comment on lines 1353 to 1361
disableThemeSync := `
INSERT INTO preferences (userid, category, name, value)
SELECT userid, '` + model.PreferenceCategoryDisableThemeSync + `', name, 'true'
FROM preferences
WHERE category = 'theme'
`
if _, err := sqlStore.GetMaster().ExecNoTimeout(disableThemeSync); err != nil {
mlog.Error("Error inserting "+model.PreferenceCategoryDisableThemeSync+" preferences", mlog.Err(err))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually needed? I am thinking that if nothing special is found we should consider the feature disabled for the user. Unless we are explicitly making it an opt-out thing.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking the same. In addition to this; if we auto enable this, we will need to set a dark_theme by default as well.

Copy link
Author

Choose a reason for hiding this comment

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

@streamer45 Intention of this DB migration is to disable synchronization for users who already have edited their theme #15975 (comment)
@isacikgoz dark_theme works same way as theme works already. When no dark_theme is saved, client apps use default dark theme.

PreferenceCategoryTheme = "theme"
PreferenceCategoryTheme = "theme"
PreferenceCategoryThemeDark = "theme_dark"
PreferenceCategoryDisableThemeSync = "disable_theme_sync"
Copy link
Contributor

Choose a reason for hiding this comment

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

This goes along with my other comment. Maybe we should consider an enable_theme_sync boolean setting instead.

Copy link
Author

@komik966 komik966 Sep 2, 2021

Choose a reason for hiding this comment

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

By default, theme synchronization should be enabled. Only users who have changed their theme before introduction of this feature should have synchronization disabled.

enable_theme_sync will force us to save this setting during new user registration.
disable_theme_sync is saved only when user explicitly disables / enables it in theme selection form.

So disable_theme_sync have three states:

  • empty (no row in db table) - use default behavior (sync with os), we know that user never has switched it in theme selection form.
  • true - not sync with os
  • false - sync with os

@streamer45
Now I see, the same is doable with enable_theme_sync, and it's easier 🙃:
empty (no row in db table) - use default behavior (sync with os), we know that user never has switched it in theme selection form.
true - sync with os
false - not sync with os

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Also I think that defaulting to positive logic (enable vs disable) in variable/setting naming is usually better and easier to digest.

@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @jfrerich @emilyacook

Copy link
Contributor

@streamer45 streamer45 left a comment

Choose a reason for hiding this comment

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

One change needed but otherwise looks great, thanks @komik966 👍

Comment on lines +1353 to +1361
disableThemeSync := `
INSERT INTO preferences (userid, category, name, value)
SELECT userid, '` + model.PreferenceCategoryEnableThemeSync + `', name, 'false'
FROM preferences
WHERE category = 'theme'
`
if _, err := sqlStore.GetMaster().ExecNoTimeout(disableThemeSync); err != nil {
mlog.Error("Error inserting "+model.PreferenceCategoryEnableThemeSync+" preferences", mlog.Err(err))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be moved to the upgradeDatabaseToVersion610 method now.

Copy link
Author

Choose a reason for hiding this comment

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

moved to 610

Copy link
Contributor

Choose a reason for hiding this comment

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

@komik966 By now this is scheduled for 6.2.0 so it should be moved again. You may have to create a new method for it. Let me know if you need help with that.

Copy link
Contributor

@esethna esethna left a comment

Choose a reason for hiding this comment

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

Approving to not block this, I will review on the webapp PR

@esethna esethna removed the 1: PM Review Requires review by a product manager label Oct 6, 2021
@esethna esethna modified the milestones: v6.1.0, v6.2.0 Oct 6, 2021
Copy link
Member

@isacikgoz isacikgoz left a comment

Choose a reason for hiding this comment

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

Nothing on top of @streamer45's point. Anticipating this feature for a long time, awesome work @komik966 🎉

@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @jfrerich @emilyacook

@esethna esethna removed the 2: Dev Review Requires review by a developer label Oct 26, 2021
@esethna
Copy link
Contributor

esethna commented Oct 26, 2021

Adding @jgilliam17 for QA review.

@komik966 once the changes for webapp are ready we can spin up a test server and as long as the branch names are the same on the webapp and server PRs our test servers will pick up the changes together for testing

FYI @jgilliam17 there's also a mobile PR: mattermost/mattermost-mobile#5635

@amyblais amyblais removed this from the v6.2.0 milestone Nov 15, 2021
@esethna
Copy link
Contributor

esethna commented Nov 17, 2021

@komik966 just circling back on this as I was out for a few weeks. What are the next steps for the server, webapp and mobile PRs? Let us know when/if they are ready for reviews and I can help chase them down

@komik966
Copy link
Author

@esethna

@esethna
Copy link
Contributor

esethna commented Nov 18, 2021

Great, thanks for the update @komik966! We will wait to merge this until it can be tested with the webapp PR cc// @jgilliam17

@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @jfrerich @emilyacook

@esethna
Copy link
Contributor

esethna commented Feb 1, 2022

Hey @komik966, let us know if you're still working on this. Would love to see it in the product!

@esethna esethna requested a review from laneycs February 8, 2022 22:36
@komik966
Copy link
Author

komik966 commented Apr 5, 2022

#15975 (comment)

@komik966 komik966 closed this Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review Hacktoberfest Lifecycle/1:stale release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants