Skip to content

api: Rename stream to channel in events #841

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 1 commit into from
Jul 28, 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
34 changes: 17 additions & 17 deletions lib/api/model/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ sealed class Event {
}
case 'stream':
switch (json['op'] as String) {
case 'create': return StreamCreateEvent.fromJson(json);
case 'delete': return StreamDeleteEvent.fromJson(json);
case 'create': return ChannelCreateEvent.fromJson(json);
case 'delete': return ChannelDeleteEvent.fromJson(json);
// TODO(#182): case 'update': …
default: return UnexpectedEvent.fromJson(json);
}
Expand Down Expand Up @@ -332,51 +332,51 @@ class RealmUserUpdateEvent extends RealmUserEvent {
///
/// The corresponding API docs are in several places for
/// different values of `op`; see subclasses.
sealed class StreamEvent extends Event {
sealed class ChannelEvent extends Event {
@override
@JsonKey(includeToJson: true)
String get type => 'stream';

String get op;

StreamEvent({required super.id});
ChannelEvent({required super.id});
}

/// A [StreamEvent] with op `create`: https://zulip.com/api/get-events#stream-create
/// A [ChannelEvent] with op `create`: https://zulip.com/api/get-events#stream-create
@JsonSerializable(fieldRename: FieldRename.snake)
class StreamCreateEvent extends StreamEvent {
class ChannelCreateEvent extends ChannelEvent {
@override
String get op => 'create';

final List<ZulipStream> streams;

StreamCreateEvent({required super.id, required this.streams});
ChannelCreateEvent({required super.id, required this.streams});

factory StreamCreateEvent.fromJson(Map<String, dynamic> json) =>
_$StreamCreateEventFromJson(json);
factory ChannelCreateEvent.fromJson(Map<String, dynamic> json) =>
_$ChannelCreateEventFromJson(json);

@override
Map<String, dynamic> toJson() => _$StreamCreateEventToJson(this);
Map<String, dynamic> toJson() => _$ChannelCreateEventToJson(this);
}

/// A [StreamEvent] with op `delete`: https://zulip.com/api/get-events#stream-delete
/// A [ChannelEvent] with op `delete`: https://zulip.com/api/get-events#stream-delete
@JsonSerializable(fieldRename: FieldRename.snake)
class StreamDeleteEvent extends StreamEvent {
class ChannelDeleteEvent extends ChannelEvent {
@override
String get op => 'delete';

final List<ZulipStream> streams;

StreamDeleteEvent({required super.id, required this.streams});
ChannelDeleteEvent({required super.id, required this.streams});

factory StreamDeleteEvent.fromJson(Map<String, dynamic> json) =>
_$StreamDeleteEventFromJson(json);
factory ChannelDeleteEvent.fromJson(Map<String, dynamic> json) =>
_$ChannelDeleteEventFromJson(json);

@override
Map<String, dynamic> toJson() => _$StreamDeleteEventToJson(this);
Map<String, dynamic> toJson() => _$ChannelDeleteEventToJson(this);
}

// TODO(#182) StreamUpdateEvent, for a [StreamEvent] with op `update`:
// TODO(#182) ChannelUpdateEvent, for a [ChannelEvent] with op `update`:
// https://zulip.com/api/get-events#stream-update

/// A Zulip event of type `subscription`.
Expand Down
12 changes: 6 additions & 6 deletions lib/api/model/events.g.dart

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

6 changes: 3 additions & 3 deletions lib/model/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ class ChannelStoreImpl with ChannelStore {
return false;
}

void handleStreamEvent(StreamEvent event) {
void handleChannelEvent(ChannelEvent event) {
switch (event) {
case StreamCreateEvent():
case ChannelCreateEvent():
assert(event.streams.every((stream) =>
!streams.containsKey(stream.streamId)
&& !streamsByName.containsKey(stream.name)));
Expand All @@ -140,7 +140,7 @@ class ChannelStoreImpl with ChannelStore {
// (Don't touch `subscriptions`. If the user is subscribed to the stream,
// details will come in a later `subscription` event.)

case StreamDeleteEvent():
case ChannelDeleteEvent():
for (final stream in event.streams) {
assert(identical(streams[stream.streamId], streamsByName[stream.name]));
assert(subscriptions[stream.streamId] == null
Expand Down
4 changes: 2 additions & 2 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
autocompleteViewManager.handleRealmUserUpdateEvent(event);
notifyListeners();

case StreamEvent():
case ChannelEvent():
assert(debugLog("server event: stream/${event.op}"));
_channels.handleStreamEvent(event);
_channels.handleChannelEvent(event);
notifyListeners();

case SubscriptionEvent():
Expand Down
2 changes: 1 addition & 1 deletion test/model/test_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension PerAccountStoreTestExtension on PerAccountStore {
}

Future<void> addStreams(List<ZulipStream> streams) async {
await handleEvent(StreamCreateEvent(id: 1, streams: streams));
await handleEvent(ChannelCreateEvent(id: 1, streams: streams));
}

Future<void> addSubscription(Subscription subscription) async {
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void main() {

testWidgets('show stream name from stream data when known', (tester) async {
final streamBefore = eg.stream(name: 'old stream name');
// TODO(#182) this test would be more realistic using a StreamUpdateEvent
// TODO(#182) this test would be more realistic using a ChannelUpdateEvent
final streamAfter = ZulipStream.fromJson({
...(deepToJson(streamBefore) as Map<String, dynamic>),
'name': 'new stream name',
Expand Down