Skip to content

api: Rename ApiNarrowStream to ApiNarrowChannel #847

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions lib/api/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ sealed class ApiNarrowElement {
};
}

class ApiNarrowStream extends ApiNarrowElement {
class ApiNarrowChannel extends ApiNarrowElement {
@override String get operator => 'stream';
Comment on lines -37 to 38
Copy link
Member

Choose a reason for hiding this comment

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

An instance of an ApiNarrowElement subclass represents a narrow filter:
https://zulip.com/api/construct-narrow
and generally the subclass ApiNarrowFoo represents narrow filters with the operator "foo".

Here, we're going to want to start representing the operator "channel" and sending that to the server instead of "stream". That's a bit tricky because we can't say "channel" to a server that doesn't understand it, i.e. one older than feature level 250. We've successfully handled the same thing for the pm-with to dm operator; see ApiNarrowDm and its subclasses.

I think I don't want to rename this class without doing that handling, though — I feel like that will make it harder for us to notice that that's something we still need to do. So I'll close this PR for now.

(This is different from the situation with parts of the API that are about data we receive. For those, generally the server is still sending the old name and there's nothing for us to do yet toward speaking the new name with the server; the next steps are on the server side. Here, the server accepts both the old and the new name, so it's done what it can and the next steps are entirely on the client side, for us to start sending the new name instead of the old.)


@override final int operand;

ApiNarrowStream(this.operand, {super.negated});
ApiNarrowChannel(this.operand, {super.negated});

factory ApiNarrowStream.fromJson(Map<String, dynamic> json) => ApiNarrowStream(
factory ApiNarrowChannel.fromJson(Map<String, dynamic> json) => ApiNarrowChannel(
json['operand'] as int,
negated: json['negated'] as bool? ?? false,
);
Expand Down
14 changes: 7 additions & 7 deletions lib/model/internal_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
fragment.write('${element.operator}/');

switch (element) {
case ApiNarrowStream():
case ApiNarrowChannel():
final streamId = element.operand;
final name = store.streams[streamId]?.name ?? 'unknown';
final slugifiedName = _encodeHashComponent(name.replaceAll(' ', '-'));
Expand Down Expand Up @@ -149,7 +149,7 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
assert(segments.isNotEmpty);
assert(segments.length.isEven);

ApiNarrowStream? streamElement;
ApiNarrowChannel? channelElement;
ApiNarrowTopic? topicElement;
ApiNarrowDm? dmElement;

Expand All @@ -160,10 +160,10 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
switch (operator) {
case _NarrowOperator.stream:
case _NarrowOperator.channel:
if (streamElement != null) return null;
if (channelElement != null) return null;
final streamId = _parseStreamOperand(operand, store);
if (streamId == null) return null;
streamElement = ApiNarrowStream(streamId, negated: negated);
channelElement = ApiNarrowChannel(streamId, negated: negated);

case _NarrowOperator.topic:
case _NarrowOperator.subject:
Expand All @@ -189,10 +189,10 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
}

if (dmElement != null) {
if (streamElement != null || topicElement != null) return null;
if (channelElement != null || topicElement != null) return null;
return DmNarrow.withUsers(dmElement.operand, selfUserId: store.selfUserId);
} else if (streamElement != null) {
final streamId = streamElement.operand;
} else if (channelElement != null) {
final streamId = channelElement.operand;
if (topicElement != null) {
return TopicNarrow(streamId, topicElement.operand);
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ChannelNarrow extends Narrow {
}

@override
ApiNarrow apiEncode() => [ApiNarrowStream(streamId)];
ApiNarrow apiEncode() => [ApiNarrowChannel(streamId)];

@override
String toString() => 'ChannelNarrow($streamId)';
Expand Down Expand Up @@ -108,7 +108,7 @@ class TopicNarrow extends Narrow implements SendableNarrow {
}

@override
ApiNarrow apiEncode() => [ApiNarrowStream(streamId), ApiNarrowTopic(topic)];
ApiNarrow apiEncode() => [ApiNarrowChannel(streamId), ApiNarrowTopic(topic)];

@override
StreamDestination get destination => StreamDestination(streamId, topic);
Expand Down