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

compose_box: Replace compose box with a banner when cannot post in a channel #886

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ class User {
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);

Map<String, dynamic> toJson() => _$UserToJson(this);

/// Whether the user has passed the realm's waiting period to be a full member.
///
/// See:
/// https://zulip.com/api/roles-and-permissions#determining-if-a-user-is-a-full-member
///
/// To determine if a user is a full member, callers must also check that the
/// user's role is at least Role.Member.
bool hasPassedWaitingPeriod(DateTime byDate, int realmWaitingPeriodThreshold) {
final dateJoined = DateTime.parse(this.dateJoined);
Copy link
Member

Choose a reason for hiding this comment

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

We could simplify this by parsing dateJoined as we deserialize the User JSON object.

Copy link
Member

Choose a reason for hiding this comment

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

We could, but I'd prefer to keep that parsing deferred: converting user objects from JSON is a hot spot performance-wise, because there can be so many of them, and parsing a DateTime is the sort of thing that I feel could easily be slow.

And conversely I think there's only a few places like here where we care about the value of dateJoined, so it's not much burden on code complexity for these to have to handle the parsing; and they're all for just one user at a time, so there's no performance concern.

return byDate.difference(dateJoined).inDays >= realmWaitingPeriodThreshold;
}
}

/// As in [User.profileData].
Expand Down