Skip to content

Clear out some backwards-compat code; inline store.userDisplayEmail #1768

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

Merged
merged 2 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ class InitialSnapshot {

final List<CustomProfileField> customProfileFields;

/// The realm-level policy, on pre-FL 163 servers, for visibility of real email addresses.
///
/// Search for "email_address_visibility" in https://zulip.com/api/register-queue.
///
/// This field is removed in Zulip 7.0 (FL 163) and replaced with a user-level
/// setting:
/// * https://zulip.com/api/update-settings#parameter-email_address_visibility
/// * https://zulip.com/api/update-realm-user-settings-defaults#parameter-email_address_visibility
final EmailAddressVisibility? emailAddressVisibility; // TODO(server-7): remove

final int serverPresencePingIntervalSeconds;
final int serverPresenceOfflineThresholdSeconds;

Expand Down Expand Up @@ -146,7 +136,6 @@ class InitialSnapshot {
required this.zulipMergeBase,
required this.alertWords,
required this.customProfileFields,
required this.emailAddressVisibility,
required this.serverPresencePingIntervalSeconds,
required this.serverPresenceOfflineThresholdSeconds,
required this.serverTypingStartedExpiryPeriodMilliseconds,
Expand Down Expand Up @@ -185,14 +174,6 @@ class InitialSnapshot {
Map<String, dynamic> toJson() => _$InitialSnapshotToJson(this);
}

enum EmailAddressVisibility {
@JsonValue(1) everyone,
@JsonValue(2) members,
@JsonValue(3) admins,
@JsonValue(4) nobody,
@JsonValue(5) moderators,
}

@JsonEnum(valueField: 'apiValue')
enum RealmWildcardMentionPolicy {
everyone(apiValue: 1),
Expand Down
14 changes: 0 additions & 14 deletions lib/api/model/initial_snapshot.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions lib/model/realm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ mixin RealmStore on PerAccountStoreBase {

RealmWildcardMentionPolicy get realmWildcardMentionPolicy; // TODO(#662): replaced by can_mention_many_users_group

EmailAddressVisibility? get emailAddressVisibility; // TODO: replaced at FL-163 by a user setting

//|//////////////////////////////
// Realm settings that lack events.
// (Each of these is probably secretly a server setting.)
Expand Down Expand Up @@ -149,8 +147,6 @@ mixin ProxyRealmStore on RealmStore {
@override
RealmWildcardMentionPolicy get realmWildcardMentionPolicy => realmStore.realmWildcardMentionPolicy;
@override
EmailAddressVisibility? get emailAddressVisibility => realmStore.emailAddressVisibility;
@override
String get realmEmptyTopicDisplayName => realmStore.realmEmptyTopicDisplayName;
@override
Map<String, RealmDefaultExternalAccount> get realmDefaultExternalAccounts => realmStore.realmDefaultExternalAccounts;
Expand Down Expand Up @@ -187,7 +183,6 @@ class RealmStoreImpl extends PerAccountStoreBase with RealmStore {
realmPresenceDisabled = initialSnapshot.realmPresenceDisabled,
realmWaitingPeriodThreshold = initialSnapshot.realmWaitingPeriodThreshold,
realmWildcardMentionPolicy = initialSnapshot.realmWildcardMentionPolicy,
emailAddressVisibility = initialSnapshot.emailAddressVisibility,
_realmEmptyTopicDisplayName = initialSnapshot.realmEmptyTopicDisplayName,
realmDefaultExternalAccounts = initialSnapshot.realmDefaultExternalAccounts,
customProfileFields = _sortCustomProfileFields(initialSnapshot.customProfileFields);
Expand Down Expand Up @@ -220,9 +215,6 @@ class RealmStoreImpl extends PerAccountStoreBase with RealmStore {
@override
final RealmWildcardMentionPolicy realmWildcardMentionPolicy;

@override
final EmailAddressVisibility? emailAddressVisibility;

@override
String get realmEmptyTopicDisplayName {
assert(zulipFeatureLevel >= 334); // TODO(server-10)
Expand Down
30 changes: 0 additions & 30 deletions lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,6 @@ mixin UserStore on PerAccountStoreBase, RealmStore {
return getUser(senderId)?.fullName ?? message.senderFullName;
}

/// The user's real email address, if known, for displaying in the UI.
///
/// Returns null if self-user isn't able to see the user's real email address,
/// or if the user isn't actually a user we know about.
String? userDisplayEmail(int userId) {
final user = getUser(userId);
if (user == null) return null;
if (zulipFeatureLevel >= 163) { // TODO(server-7)
// A non-null value means self-user has access to [user]'s real email,
// while a null value means it doesn't have access to the email.
// Search for "delivery_email" in https://zulip.com/api/register-queue.
return user.deliveryEmail;
} else {
if (user.deliveryEmail != null) {
// A non-null value means self-user has access to [user]'s real email,
// while a null value doesn't necessarily mean it doesn't have access
// to the email, ....
return user.deliveryEmail;
} else if (emailAddressVisibility == EmailAddressVisibility.everyone) {
// ... we have to also check for [PerAccountStore.emailAddressVisibility].
// See:
// * https://github.com/zulip/zulip-mobile/pull/5515#discussion_r997731727
// * https://chat.zulip.org/#narrow/stream/378-api-design/topic/email.20address.20visibility/near/1296133
return user.email;
} else {
return null;
}
}
}

/// Whether [user] has passed the realm's waiting period to be a full member.
///
/// See:
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class MentionAutocompleteItem extends StatelessWidget {
label = store.userDisplayName(userId);
emoji = UserStatusEmoji(userId: userId, size: 18,
padding: const EdgeInsetsDirectional.only(start: 5.0));
sublabel = store.userDisplayEmail(userId);
sublabel = store.getUser(userId)?.deliveryEmail;
case WildcardMentionAutocompleteResult(:var wildcardOption):
avatar = SizedBox.square(dimension: 36,
child: const Icon(ZulipIcons.three_person, size: 24));
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProfilePage extends StatelessWidget {
.merge(weightVariableTextStyle(context, wght: 700));

final userStatus = store.getUserStatus(userId);
final displayEmail = store.userDisplayEmail(userId);
final displayEmail = user.deliveryEmail;
final items = [
Center(
child: Avatar(
Expand Down
4 changes: 1 addition & 3 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ int _lastEmailSuffix = 1000;
/// other data in the test, or if the IDs need to increase in a different order
/// from the calls to [user].
///
/// If `email` is not given, it defaults to `deliveryEmail` if given,
/// If `email` is not given, it defaults to `deliveryEmail` if given and non-null,
/// or else to a value resembling the Zulip server's generated fake emails.
User user({
int? userId,
Expand Down Expand Up @@ -1202,7 +1202,6 @@ InitialSnapshot initialSnapshot({
String? zulipMergeBase,
List<String>? alertWords,
List<CustomProfileField>? customProfileFields,
EmailAddressVisibility? emailAddressVisibility,
int? serverPresencePingIntervalSeconds,
int? serverPresenceOfflineThresholdSeconds,
int? serverTypingStartedExpiryPeriodMilliseconds,
Expand Down Expand Up @@ -1242,7 +1241,6 @@ InitialSnapshot initialSnapshot({
zulipMergeBase: zulipMergeBase ?? recentZulipVersion,
alertWords: alertWords ?? ['klaxon'],
customProfileFields: customProfileFields ?? [],
emailAddressVisibility: emailAddressVisibility ?? EmailAddressVisibility.everyone,
serverPresencePingIntervalSeconds: serverPresencePingIntervalSeconds ?? 60,
serverPresenceOfflineThresholdSeconds: serverPresenceOfflineThresholdSeconds ?? 140,
serverTypingStartedExpiryPeriodMilliseconds:
Expand Down