Skip to content

api: Cut ZulipStream.canRemoveSubscribersGroup as it changes format #1084

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 3 commits into from
Nov 25, 2024
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
3 changes: 0 additions & 3 deletions lib/api/model/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,6 @@ class ChannelUpdateEvent extends ChannelEvent {
return value as int?;
case ChannelPropertyName.channelPostPolicy:
return ChannelPostPolicy.fromApiValue(value as int);
case ChannelPropertyName.canRemoveSubscribersGroup:
case ChannelPropertyName.canRemoveSubscribersGroupId:
return value as int;
case ChannelPropertyName.streamWeeklyTraffic:
return value as int?;
case null:
Expand Down
3 changes: 0 additions & 3 deletions lib/api/model/events.g.dart

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

16 changes: 3 additions & 13 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,11 @@ class ZulipStream {
ChannelPostPolicy channelPostPolicy;
// final bool isAnnouncementOnly; // deprecated for `channelPostPolicy`; ignore

// TODO(server-6): `canRemoveSubscribersGroupId` added in FL 142
// TODO(server-8): in FL 197 renamed to `canRemoveSubscribersGroup`
@JsonKey(readValue: _readCanRemoveSubscribersGroup)
int? canRemoveSubscribersGroup;
// GroupSettingsValue canRemoveSubscribersGroup; // TODO(#814)

// TODO(server-8): added in FL 199, was previously only on [Subscription] objects
int? streamWeeklyTraffic;

static int? _readCanRemoveSubscribersGroup(Map<dynamic, dynamic> json, String key) {
return (json[key] as int?)
?? (json['can_remove_subscribers_group_id'] as int?);
}

ZulipStream({
required this.streamId,
required this.name,
Expand All @@ -367,7 +359,6 @@ class ZulipStream {
required this.historyPublicToSubscribers,
required this.messageRetentionDays,
required this.channelPostPolicy,
required this.canRemoveSubscribersGroup,
required this.streamWeeklyTraffic,
});

Expand Down Expand Up @@ -397,8 +388,8 @@ enum ChannelPropertyName {
messageRetentionDays,
@JsonValue('stream_post_policy')
channelPostPolicy,
canRemoveSubscribersGroup,
canRemoveSubscribersGroupId, // TODO(server-8): remove, replaced by canRemoveSubscribersGroup
// canRemoveSubscribersGroup, // TODO(#814)
// canRemoveSubscribersGroupId, // TODO(#814) handle // TODO(server-8) remove
streamWeeklyTraffic;

/// Get a [ChannelPropertyName] from a raw, snake-case string we recognize, else null.
Expand Down Expand Up @@ -478,7 +469,6 @@ class Subscription extends ZulipStream {
required super.historyPublicToSubscribers,
required super.messageRetentionDays,
required super.channelPostPolicy,
required super.canRemoveSubscribersGroup,
required super.streamWeeklyTraffic,
required this.desktopNotifications,
required this.emailNotifications,
Expand Down
11 changes: 0 additions & 11 deletions lib/api/model/model.g.dart

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

3 changes: 0 additions & 3 deletions lib/model/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ class ChannelStoreImpl with ChannelStore {
stream.messageRetentionDays = event.value as int?;
case ChannelPropertyName.channelPostPolicy:
stream.channelPostPolicy = event.value as ChannelPostPolicy;
case ChannelPropertyName.canRemoveSubscribersGroup:
case ChannelPropertyName.canRemoveSubscribersGroupId:
stream.canRemoveSubscribersGroup = event.value as int?;
case ChannelPropertyName.streamWeeklyTraffic:
stream.streamWeeklyTraffic = event.value as int?;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,12 @@ class UpdateMachine {
while (true) {
try {
return await registerQueue(connection);
} catch (e) {
assert(debugLog('Error fetching initial snapshot: $e\n'
'Backing off, then will retry…'));
} catch (e, s) {
assert(debugLog('Error fetching initial snapshot: $e'));
// Print stack trace in its own log entry; log entries are truncated
// at 1 kiB (at least on Android), and stack can be longer than that.
assert(debugLog('Stack:\n$s'));
assert(debugLog('Backing off, then will retry…'));
// TODO tell user if initial-fetch errors persist, or look non-transient
await (backoffMachine ??= BackoffMachine()).wait();
assert(debugLog('… Backoff wait complete, retrying initial fetch.'));
Expand Down
1 change: 0 additions & 1 deletion test/api/model/model_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extension UserChecks on Subject<User> {
}

extension ZulipStreamChecks on Subject<ZulipStream> {
Subject<int?> get canRemoveSubscribersGroup => has((e) => e.canRemoveSubscribersGroup, 'canRemoveSubscribersGroup');
}

extension MessageChecks on Subject<Message> {
Expand Down
37 changes: 0 additions & 37 deletions test/api/model/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,43 +67,6 @@ void main() {
});
});

group('ZulipStream.canRemoveSubscribersGroup', () {
final Map<String, dynamic> baseJson = Map.unmodifiable({
'stream_id': 123,
'name': 'A stream',
'description': 'A description',
'rendered_description': '<p>A description</p>',
'date_created': 1686774898,
'first_message_id': null,
'invite_only': false,
'is_web_public': false,
'history_public_to_subscribers': true,
'message_retention_days': null,
'stream_post_policy': ChannelPostPolicy.any.apiValue,
// 'can_remove_subscribers_group': null,
'stream_weekly_traffic': null,
});

test('smoke', () {
check(ZulipStream.fromJson({ ...baseJson,
'can_remove_subscribers_group': 123,
})).canRemoveSubscribersGroup.equals(123);
});

// TODO(server-8): field renamed in FL 197
test('support old can_remove_subscribers_group_id', () {
check(ZulipStream.fromJson({ ...baseJson,
'can_remove_subscribers_group_id': 456,
})).canRemoveSubscribersGroup.equals(456);
});

// TODO(server-6): field added in FL 142
test('support field missing', () {
check(ZulipStream.fromJson({ ...baseJson,
})).canRemoveSubscribersGroup.isNull();
});
});

group('Subscription', () {
test('converts color to int', () {
Subscription subWithColor(String color) {
Expand Down
5 changes: 0 additions & 5 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ ZulipStream stream({
bool? historyPublicToSubscribers,
int? messageRetentionDays,
ChannelPostPolicy? channelPostPolicy,
int? canRemoveSubscribersGroup,
int? streamWeeklyTraffic,
}) {
_checkPositive(streamId, 'stream ID');
Expand All @@ -232,7 +231,6 @@ ZulipStream stream({
historyPublicToSubscribers: historyPublicToSubscribers ?? true,
messageRetentionDays: messageRetentionDays,
channelPostPolicy: channelPostPolicy ?? ChannelPostPolicy.any,
canRemoveSubscribersGroup: canRemoveSubscribersGroup ?? 123,
streamWeeklyTraffic: streamWeeklyTraffic,
);
}
Expand Down Expand Up @@ -270,7 +268,6 @@ Subscription subscription(
historyPublicToSubscribers: stream.historyPublicToSubscribers,
messageRetentionDays: stream.messageRetentionDays,
channelPostPolicy: stream.channelPostPolicy,
canRemoveSubscribersGroup: stream.canRemoveSubscribersGroup,
streamWeeklyTraffic: stream.streamWeeklyTraffic,
desktopNotifications: desktopNotifications ?? false,
emailNotifications: emailNotifications ?? false,
Expand Down Expand Up @@ -789,8 +786,6 @@ ChannelUpdateEvent channelUpdateEvent(
assert(value is int?);
case ChannelPropertyName.channelPostPolicy:
assert(value is ChannelPostPolicy);
case ChannelPropertyName.canRemoveSubscribersGroup:
case ChannelPropertyName.canRemoveSubscribersGroupId:
case ChannelPropertyName.streamWeeklyTraffic:
assert(value is int?);
}
Expand Down