Skip to content

Commit 0ca9c68

Browse files
committed
api [nfc]: Rename streamId to channelId in Channel model
Fixes parts of zulip#631
1 parent 5eb3e75 commit 0ca9c68

22 files changed

+189
-189
lines changed

lib/api/model/model.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ enum UserRole{
306306
/// in <https://zulip.com/api/register-queue>.
307307
@JsonSerializable(fieldRename: FieldRename.snake)
308308
class Channel {
309-
final int streamId;
309+
final int channelId;
310310
final String name;
311311
final String description;
312312
final String renderedDescription;
@@ -336,7 +336,7 @@ class Channel {
336336
}
337337

338338
Channel({
339-
required this.streamId,
339+
required this.channelId,
340340
required this.name,
341341
required this.description,
342342
required this.renderedDescription,
@@ -407,7 +407,7 @@ class Subscription extends Channel {
407407
}
408408

409409
Subscription({
410-
required super.streamId,
410+
required super.channelId,
411411
required super.name,
412412
required super.description,
413413
required super.renderedDescription,

lib/api/model/model.g.dart

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/model/internal_link.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ int? _parseStreamOperand(String operand, StreamStore store) {
258258
final String? streamName = decodeHashComponent(operand);
259259
if (streamName == null) return null;
260260
final stream = store.streamsByName[streamName];
261-
if (stream != null) return stream.streamId;
261+
if (stream != null) return stream.channelId;
262262

263263
if (newFormatStreamId != null) {
264264
// Neither format found a stream, so it's hidden or doesn't exist. But

lib/model/stream.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ mixin StreamStore {
7575
class StreamStoreImpl with StreamStore {
7676
factory StreamStoreImpl({required InitialSnapshot initialSnapshot}) {
7777
final subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
78-
(subscription) => MapEntry(subscription.streamId, subscription)));
78+
(subscription) => MapEntry(subscription.channelId, subscription)));
7979

8080
final streams = Map<int, Channel>.of(subscriptions);
8181
for (final stream in initialSnapshot.streams) {
82-
streams.putIfAbsent(stream.streamId, () => stream);
82+
streams.putIfAbsent(stream.channelId, () => stream);
8383
}
8484

8585
final topicVisibility = <int, Map<String, UserTopicVisibilityPolicy>>{};
@@ -133,21 +133,21 @@ class StreamStoreImpl with StreamStore {
133133
switch (event) {
134134
case StreamCreateEvent():
135135
assert(event.streams.every((stream) =>
136-
!streams.containsKey(stream.streamId)
136+
!streams.containsKey(stream.channelId)
137137
&& !streamsByName.containsKey(stream.name)));
138-
streams.addEntries(event.streams.map((stream) => MapEntry(stream.streamId, stream)));
138+
streams.addEntries(event.streams.map((stream) => MapEntry(stream.channelId, stream)));
139139
streamsByName.addEntries(event.streams.map((stream) => MapEntry(stream.name, stream)));
140140
// (Don't touch `subscriptions`. If the user is subscribed to the stream,
141141
// details will come in a later `subscription` event.)
142142

143143
case StreamDeleteEvent():
144144
for (final stream in event.streams) {
145-
assert(identical(streams[stream.streamId], streamsByName[stream.name]));
146-
assert(subscriptions[stream.streamId] == null
147-
|| identical(subscriptions[stream.streamId], streams[stream.streamId]));
148-
streams.remove(stream.streamId);
145+
assert(identical(streams[stream.channelId], streamsByName[stream.name]));
146+
assert(subscriptions[stream.channelId] == null
147+
|| identical(subscriptions[stream.channelId], streams[stream.channelId]));
148+
streams.remove(stream.channelId);
149149
streamsByName.remove(stream.name);
150-
subscriptions.remove(stream.streamId);
150+
subscriptions.remove(stream.channelId);
151151
}
152152
}
153153
}
@@ -156,14 +156,14 @@ class StreamStoreImpl with StreamStore {
156156
switch (event) {
157157
case SubscriptionAddEvent():
158158
for (final subscription in event.subscriptions) {
159-
assert(streams.containsKey(subscription.streamId)
160-
&& streams[subscription.streamId] is! Subscription);
159+
assert(streams.containsKey(subscription.channelId)
160+
&& streams[subscription.channelId] is! Subscription);
161161
assert(streamsByName.containsKey(subscription.name)
162162
&& streamsByName[subscription.name] is! Subscription);
163-
assert(!subscriptions.containsKey(subscription.streamId));
164-
streams[subscription.streamId] = subscription;
163+
assert(!subscriptions.containsKey(subscription.channelId));
164+
streams[subscription.channelId] = subscription;
165165
streamsByName[subscription.name] = subscription;
166-
subscriptions[subscription.streamId] = subscription;
166+
subscriptions[subscription.channelId] = subscription;
167167
}
168168

169169
case SubscriptionRemoveEvent():

lib/widgets/inbox.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ class _StreamHeaderItem extends _HeaderItem {
436436
@override Future<void> onCollapseButtonTap() async {
437437
await super.onCollapseButtonTap();
438438
if (collapsed) {
439-
pageState.uncollapseStream(subscription.streamId);
439+
pageState.uncollapseStream(subscription.channelId);
440440
} else {
441-
pageState.collapseStream(subscription.streamId);
441+
pageState.collapseStream(subscription.channelId);
442442
}
443443
}
444444
@override Future<void> onRowTap() => onCollapseButtonTap(); // TODO open stream narrow

lib/widgets/subscription_list.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class _SubscriptionList extends StatelessWidget {
180180
itemCount: subscriptions.length,
181181
itemBuilder: (BuildContext context, int index) {
182182
final subscription = subscriptions[index];
183-
final unreadCount = unreadsModel!.countInStream(subscription.streamId);
183+
final unreadCount = unreadsModel!.countInStream(subscription.channelId);
184184
// TODO(#712): if stream muted, show a dot for unreads
185185
return SubscriptionItem(subscription: subscription, unreadCount: unreadCount);
186186
});
@@ -209,7 +209,7 @@ class SubscriptionItem extends StatelessWidget {
209209
onTap: () {
210210
Navigator.push(context,
211211
MessageListPage.buildRoute(context: context,
212-
narrow: StreamNarrow(subscription.streamId)));
212+
narrow: StreamNarrow(subscription.channelId)));
213213
},
214214
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
215215
const SizedBox(width: 16),

test/api/model/events_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void main() {
9999
'message_ids': [message.id],
100100
'flags': <String>[],
101101
'edit_timestamp': 1718741351,
102-
'stream_id': eg.stream().streamId,
102+
'stream_id': eg.stream().channelId,
103103
};
104104

105105
test('stream_id -> origStreamId', () {

test/api/model/model_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void main() {
6868

6969
group('Channel.canRemoveSubscribersGroup', () {
7070
final Map<String, dynamic> baseJson = Map.unmodifiable({
71-
'stream_id': 123,
71+
'channel_id': 123,
7272
'name': 'A stream',
7373
'description': 'A description',
7474
'rendered_description': '<p>A description</p>',

test/example_data.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ final User fourthUser = user(fullName: 'Fourth User', email: 'fourth@example');
150150
//
151151

152152
Channel stream({
153-
int? streamId,
153+
int? channelId,
154154
String? name,
155155
String? description,
156156
String? renderedDescription,
@@ -165,7 +165,7 @@ Channel stream({
165165
int? streamWeeklyTraffic,
166166
}) {
167167
return Channel(
168-
streamId: streamId ?? 123, // TODO generate example IDs
168+
channelId: channelId ?? 123, // TODO generate example IDs
169169
name: name ?? 'A stream', // TODO generate example names
170170
description: description ?? 'A description', // TODO generate example descriptions
171171
renderedDescription: renderedDescription ?? '<p>A description</p>', // TODO generate random
@@ -198,7 +198,7 @@ Subscription subscription(
198198
int? color,
199199
}) {
200200
return Subscription(
201-
streamId: stream.streamId,
201+
channelId: stream.channelId,
202202
name: stream.name,
203203
description: stream.description,
204204
renderedDescription: stream.renderedDescription,
@@ -314,7 +314,7 @@ StreamMessage streamMessage({
314314
..._messagePropertiesFromSender(sender),
315315
..._messagePropertiesFromContent(content, contentMarkdown),
316316
'display_recipient': effectiveStream.name,
317-
'stream_id': effectiveStream.streamId,
317+
'stream_id': effectiveStream.channelId,
318318
'reactions': reactions == null ? <Reaction>[] : Reactions(reactions),
319319
'flags': flags ?? [],
320320
'id': id ?? _nextMessageId(),

test/model/compose_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ hello
240240
}) async {
241241
assert(expectedFragment.startsWith('#'), 'wrong-looking expectedFragment');
242242
final store = eg.store();
243-
await store.addStream(eg.stream(streamId: streamId, name: name));
243+
await store.addStream(eg.stream(channelId: streamId, name: name));
244244
final narrow = topic == null
245245
? StreamNarrow(streamId)
246246
: TopicNarrow(streamId, topic);
@@ -337,7 +337,7 @@ hello
337337

338338
test('quoteAndReply / quoteAndReplyPlaceholder', () async {
339339
final sender = eg.user(userId: 123, fullName: 'Full Name');
340-
final stream = eg.stream(streamId: 1, name: 'test here');
340+
final stream = eg.stream(channelId: 1, name: 'test here');
341341
final message = eg.streamMessage(sender: sender, stream: stream, topic: 'some topic');
342342
final store = eg.store();
343343
await store.addStream(stream);

test/model/internal_link_test.dart

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void main() {
5656

5757
group('parseInternalLink', () {
5858
final streams = [
59-
eg.stream(streamId: 1, name: 'check'),
59+
eg.stream(channelId: 1, name: 'check'),
6060
];
6161
final testCases = [
6262
(true, 'legacy: stream name, no ID',
@@ -153,10 +153,10 @@ void main() {
153153

154154
group('parseInternalLink', () {
155155
final streams = [
156-
eg.stream(streamId: 1, name: 'check'),
157-
eg.stream(streamId: 3, name: 'mobile'),
158-
eg.stream(streamId: 5, name: 'stream'),
159-
eg.stream(streamId: 123, name: 'topic'),
156+
eg.stream(channelId: 1, name: 'check'),
157+
eg.stream(channelId: 3, name: 'mobile'),
158+
eg.stream(channelId: 5, name: 'stream'),
159+
eg.stream(channelId: 123, name: 'topic'),
160160
];
161161

162162
group('"/#narrow/stream/<...>" returns expected StreamNarrow', () {
@@ -262,9 +262,9 @@ void main() {
262262

263263
group('parses correctly in stream and topic operands', () {
264264
final streams = [
265-
eg.stream(streamId: 1, name: 'some_stream'),
266-
eg.stream(streamId: 2, name: 'some stream'),
267-
eg.stream(streamId: 3, name: 'some.stream'),
265+
eg.stream(channelId: 1, name: 'some_stream'),
266+
eg.stream(channelId: 2, name: 'some stream'),
267+
eg.stream(channelId: 3, name: 'some.stream'),
268268
];
269269
const testCases = [
270270
('/#narrow/stream/some_stream', StreamNarrow(1)),
@@ -282,7 +282,7 @@ void main() {
282282
void testExpectedStreamNarrow(String testCase, int? streamId) {
283283
final streamNarrow = (streamId != null) ? StreamNarrow(streamId) : null;
284284
testExpectedNarrows([(testCase, streamNarrow)], streams: [
285-
eg.stream(streamId: 1, name: "general"),
285+
eg.stream(channelId: 1, name: "general"),
286286
]);
287287
}
288288

@@ -309,11 +309,11 @@ void main() {
309309
group('parseInternalLink with historic links', () {
310310
group('for stream with hyphens or even looking like new-style', () {
311311
final streams = [
312-
eg.stream(streamId: 1, name: 'test-team'),
313-
eg.stream(streamId: 2, name: '311'),
314-
eg.stream(streamId: 3, name: '311-'),
315-
eg.stream(streamId: 4, name: '311-help'),
316-
eg.stream(streamId: 5, name: '--help'),
312+
eg.stream(channelId: 1, name: 'test-team'),
313+
eg.stream(channelId: 2, name: '311'),
314+
eg.stream(channelId: 3, name: '311-'),
315+
eg.stream(channelId: 4, name: '311-help'),
316+
eg.stream(channelId: 5, name: '--help'),
317317
];
318318
const testCases = [
319319
('#narrow/stream/test-team/', StreamNarrow(1)),
@@ -327,10 +327,10 @@ void main() {
327327

328328
group('on ambiguous new- or old-style: new wins', () {
329329
final streams = [
330-
eg.stream(streamId: 1, name: '311'),
331-
eg.stream(streamId: 2, name: '311-'),
332-
eg.stream(streamId: 3, name: '311-help'),
333-
eg.stream(streamId: 311, name: 'collider'),
330+
eg.stream(channelId: 1, name: '311'),
331+
eg.stream(channelId: 2, name: '311-'),
332+
eg.stream(channelId: 3, name: '311-help'),
333+
eg.stream(channelId: 311, name: 'collider'),
334334
];
335335
const testCases = [
336336
('#narrow/stream/311/', StreamNarrow(311)),
@@ -342,11 +342,11 @@ void main() {
342342

343343
group('on old stream link', () {
344344
final streams = [
345-
eg.stream(streamId: 1, name: 'check'),
346-
eg.stream(streamId: 2, name: 'bot testing'),
347-
eg.stream(streamId: 3, name: 'check.API'),
348-
eg.stream(streamId: 4, name: 'stream'),
349-
eg.stream(streamId: 5, name: 'topic'),
345+
eg.stream(channelId: 1, name: 'check'),
346+
eg.stream(channelId: 2, name: 'bot testing'),
347+
eg.stream(channelId: 3, name: 'check.API'),
348+
eg.stream(channelId: 4, name: 'stream'),
349+
eg.stream(channelId: 5, name: 'topic'),
350350
];
351351
const testCases = [
352352
('#narrow/stream/check/', StreamNarrow(1)),
@@ -367,11 +367,11 @@ void main() {
367367

368368
group('basic', () {
369369
String mkUrlString(String operand) {
370-
return '#narrow/stream/${stream.streamId}-${stream.name}/topic/$operand';
370+
return '#narrow/stream/${stream.channelId}-${stream.name}/topic/$operand';
371371
}
372372
final testCases = [
373-
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
374-
(mkUrlString('lunch'), TopicNarrow(stream.streamId, 'lunch')),
373+
(mkUrlString('(no.20topic)'), TopicNarrow(stream.channelId, '(no topic)')),
374+
(mkUrlString('lunch'), TopicNarrow(stream.channelId, 'lunch')),
375375
];
376376
testExpectedNarrows(testCases, streams: [stream]);
377377
});
@@ -381,12 +381,12 @@ void main() {
381381
return '#narrow/stream/${stream.name}/topic/$operand';
382382
}
383383
final testCases = [
384-
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
385-
(mkUrlString('google.2Ecom'), TopicNarrow(stream.streamId, 'google.com')),
384+
(mkUrlString('(no.20topic)'), TopicNarrow(stream.channelId, '(no topic)')),
385+
(mkUrlString('google.2Ecom'), TopicNarrow(stream.channelId, 'google.com')),
386386
(mkUrlString('google.com'), null),
387-
(mkUrlString('topic.20name'), TopicNarrow(stream.streamId, 'topic name')),
388-
(mkUrlString('stream'), TopicNarrow(stream.streamId, 'stream')),
389-
(mkUrlString('topic'), TopicNarrow(stream.streamId, 'topic')),
387+
(mkUrlString('topic.20name'), TopicNarrow(stream.channelId, 'topic name')),
388+
(mkUrlString('stream'), TopicNarrow(stream.channelId, 'stream')),
389+
(mkUrlString('topic'), TopicNarrow(stream.channelId, 'topic')),
390390
];
391391
testExpectedNarrows(testCases, streams: [stream]);
392392
});

0 commit comments

Comments
 (0)