From 98a48c0e11c63e0b61858b6a78032c869b7b67d1 Mon Sep 17 00:00:00 2001 From: Khader M Khudair Date: Sun, 28 Jul 2024 07:48:12 +0300 Subject: [PATCH 1/2] api [nfc]: Rename `ApiNarrowStream` to `ApiNarrowChannel` Fixes parts of #631 --- lib/api/model/narrow.dart | 6 +++--- lib/model/internal_link.dart | 6 +++--- lib/model/narrow.dart | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/api/model/narrow.dart b/lib/api/model/narrow.dart index 7383d382ba..1cc854ae8e 100644 --- a/lib/api/model/narrow.dart +++ b/lib/api/model/narrow.dart @@ -34,14 +34,14 @@ sealed class ApiNarrowElement { }; } -class ApiNarrowStream extends ApiNarrowElement { +class ApiNarrowChannel extends ApiNarrowElement { @override String get operator => 'stream'; @override final int operand; - ApiNarrowStream(this.operand, {super.negated}); + ApiNarrowChannel(this.operand, {super.negated}); - factory ApiNarrowStream.fromJson(Map json) => ApiNarrowStream( + factory ApiNarrowChannel.fromJson(Map json) => ApiNarrowChannel( json['operand'] as int, negated: json['negated'] as bool? ?? false, ); diff --git a/lib/model/internal_link.dart b/lib/model/internal_link.dart index 422a0d8182..cb7d00db97 100644 --- a/lib/model/internal_link.dart +++ b/lib/model/internal_link.dart @@ -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(' ', '-')); @@ -149,7 +149,7 @@ Narrow? _interpretNarrowSegments(List segments, PerAccountStore store) { assert(segments.isNotEmpty); assert(segments.length.isEven); - ApiNarrowStream? streamElement; + ApiNarrowChannel? streamElement; ApiNarrowTopic? topicElement; ApiNarrowDm? dmElement; @@ -163,7 +163,7 @@ Narrow? _interpretNarrowSegments(List segments, PerAccountStore store) { if (streamElement != null) return null; final streamId = _parseStreamOperand(operand, store); if (streamId == null) return null; - streamElement = ApiNarrowStream(streamId, negated: negated); + streamElement = ApiNarrowChannel(streamId, negated: negated); case _NarrowOperator.topic: case _NarrowOperator.subject: diff --git a/lib/model/narrow.dart b/lib/model/narrow.dart index a23caa40b9..26744d650e 100644 --- a/lib/model/narrow.dart +++ b/lib/model/narrow.dart @@ -76,7 +76,7 @@ class ChannelNarrow extends Narrow { } @override - ApiNarrow apiEncode() => [ApiNarrowStream(streamId)]; + ApiNarrow apiEncode() => [ApiNarrowChannel(streamId)]; @override String toString() => 'ChannelNarrow($streamId)'; @@ -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); From 4da6c62dc4cb84e87179491cb8554ce98511e68d Mon Sep 17 00:00:00 2001 From: Khader M Khudair Date: Sun, 28 Jul 2024 07:50:15 +0300 Subject: [PATCH 2/2] api [nfc]: Rename references of `ApiNarrowChannel` to match new name --- lib/model/internal_link.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/model/internal_link.dart b/lib/model/internal_link.dart index cb7d00db97..016ee02483 100644 --- a/lib/model/internal_link.dart +++ b/lib/model/internal_link.dart @@ -149,7 +149,7 @@ Narrow? _interpretNarrowSegments(List segments, PerAccountStore store) { assert(segments.isNotEmpty); assert(segments.length.isEven); - ApiNarrowChannel? streamElement; + ApiNarrowChannel? channelElement; ApiNarrowTopic? topicElement; ApiNarrowDm? dmElement; @@ -160,10 +160,10 @@ Narrow? _interpretNarrowSegments(List 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 = ApiNarrowChannel(streamId, negated: negated); + channelElement = ApiNarrowChannel(streamId, negated: negated); case _NarrowOperator.topic: case _NarrowOperator.subject: @@ -189,10 +189,10 @@ Narrow? _interpretNarrowSegments(List 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 {