models: Refactor UserBaseSettings `property_types` structure.

To prevent new contributors who are adding new user settings from
being confused about the legacy dicts for display settings and
notifications settings, we create `modern_settings` and
`modern_notifications_settings` dicts with comments documenting
that new user settings should be added to one of them.

Note that the `modern_notification_settings` is a placeholder for
new notifications settings as there have been no new notification
settings added since 430c5cb8 (when the legacy dicts were created)
and is currently annotated as `Dict[str, Any]` (which can be
removed if/when a new setting is added).
This commit is contained in:
Lauryn Menard 2022-05-03 11:21:42 +02:00 committed by Tim Abbott
parent 0543f4596c
commit 22c4763a61
1 changed files with 21 additions and 10 deletions

View File

@ -1562,6 +1562,8 @@ class UserBaseSettings(models.Model):
send_read_receipts: bool = models.BooleanField(default=True)
display_settings_legacy = dict(
# Don't add anything new to this legacy dict.
# Instead, see `modern_settings` below.
color_scheme=int,
default_language=str,
default_view=str,
@ -1579,6 +1581,8 @@ class UserBaseSettings(models.Model):
)
notification_settings_legacy = dict(
# Don't add anything new to this legacy dict.
# Instead, see `modern_notification_settings` below.
desktop_icon_count_display=int,
email_notifications_batching_period_seconds=int,
enable_desktop_notifications=bool,
@ -1601,22 +1605,29 @@ class UserBaseSettings(models.Model):
wildcard_mentions_notify=bool,
)
modern_settings = dict(
# Add new general settings here.
display_emoji_reaction_users=bool,
escape_navigates_to_default_view=bool,
send_private_typing_notifications=bool,
send_read_receipts=bool,
send_stream_typing_notifications=bool,
)
modern_notification_settings: Dict[str, Any] = dict(
# Add new notification settings here.
)
notification_setting_types = {
**notification_settings_legacy
} # Add new notifications settings here.
**notification_settings_legacy,
**modern_notification_settings,
}
# Define the types of the various automatically managed properties
property_types = {
**display_settings_legacy,
**notification_setting_types,
**dict(
# Add new general settings here.
display_emoji_reaction_users=bool,
escape_navigates_to_default_view=bool,
send_private_typing_notifications=bool,
send_read_receipts=bool,
send_stream_typing_notifications=bool,
),
**modern_settings,
}
class Meta: