Skip to content

Commit 429fa9e

Browse files
committed
api [nfc]: Mark all never-updated User fields final
This was prompted by noticing recently that we weren't updating [User.isActive]: zulip#816 (comment) 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.
1 parent 241f6d7 commit 429fa9e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/api/model/model.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,25 @@ enum Emojiset {
188188
/// in <https://zulip.com/api/register-queue>.
189189
@JsonSerializable(fieldRename: FieldRename.snake)
190190
class User {
191+
// When adding a field to this class:
192+
// * If a [RealmUserUpdateEvent] can update it, be sure to add
193+
// that case to [RealmUserUpdateEvent] and its handler.
194+
// * If the field can never change for a given Zulip user, mark it final.
195+
// * (If it can change but [RealmUserUpdateEvent] doesn't cover that,
196+
// then that's a bug in the API; raise it in `#api design`.)
197+
191198
final int userId;
192199
String? deliveryEmail;
193200
String email;
194201
String fullName;
195-
String dateJoined;
202+
final String dateJoined;
196203
bool isActive; // Really sometimes absent in /register, but we normalize that away; see [InitialSnapshot.realmUsers].
197204
// bool isOwner; // obsoleted by [role]; ignore
198205
// bool isAdmin; // obsoleted by [role]; ignore
199206
// bool isGuest; // obsoleted by [role]; ignore
200207
bool? isBillingAdmin; // TODO(server-5)
201-
bool isBot;
202-
int? botType; // TODO enum
208+
final bool isBot;
209+
final int? botType; // TODO enum
203210
int? botOwnerId;
204211
@JsonKey(unknownEnumValue: UserRole.unknown)
205212
UserRole role;
@@ -214,7 +221,7 @@ class User {
214221
Map<int, ProfileFieldUserData>? profileData;
215222

216223
@JsonKey(readValue: _readIsSystemBot)
217-
bool isSystemBot;
224+
final bool isSystemBot;
218225

219226
static Map<String, dynamic>? _readProfileData(Map<dynamic, dynamic> json, String key) {
220227
final value = (json[key] as Map<String, dynamic>?);

0 commit comments

Comments
 (0)