From 429fa9e35405f98202f09c304decb5b7e747990c Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 11 Aug 2024 14:02:06 -0700 Subject: [PATCH] api [nfc]: Mark all never-updated User fields final This was prompted by noticing recently that we weren't updating [User.isActive]: https://github.com/zulip/zulip-flutter/pull/816#discussion_r1689098946 After fixing that, I looked and found there were actually three other fields on User which we weren't updating -- a latent bug, since we never looked at those fields, but a bug. Fixed that in the preceding commit. Now the remaining fields that don't get updated are fields that really are immutable on a Zulip user. Mark those as final, and add a comment to help maintain the pattern. --- lib/api/model/model.dart | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/api/model/model.dart b/lib/api/model/model.dart index fc186d15aa8..01bd5e9cbdb 100644 --- a/lib/api/model/model.dart +++ b/lib/api/model/model.dart @@ -188,18 +188,25 @@ enum Emojiset { /// in . @JsonSerializable(fieldRename: FieldRename.snake) class User { + // When adding a field to this class: + // * If a [RealmUserUpdateEvent] can update it, be sure to add + // that case to [RealmUserUpdateEvent] and its handler. + // * If the field can never change for a given Zulip user, mark it final. + // * (If it can change but [RealmUserUpdateEvent] doesn't cover that, + // then that's a bug in the API; raise it in `#api design`.) + final int userId; String? deliveryEmail; String email; String fullName; - String dateJoined; + final String dateJoined; bool isActive; // Really sometimes absent in /register, but we normalize that away; see [InitialSnapshot.realmUsers]. // bool isOwner; // obsoleted by [role]; ignore // bool isAdmin; // obsoleted by [role]; ignore // bool isGuest; // obsoleted by [role]; ignore bool? isBillingAdmin; // TODO(server-5) - bool isBot; - int? botType; // TODO enum + final bool isBot; + final int? botType; // TODO enum int? botOwnerId; @JsonKey(unknownEnumValue: UserRole.unknown) UserRole role; @@ -214,7 +221,7 @@ class User { Map? profileData; @JsonKey(readValue: _readIsSystemBot) - bool isSystemBot; + final bool isSystemBot; static Map? _readProfileData(Map json, String key) { final value = (json[key] as Map?);