Skip to content

Commit 7291212

Browse files
gnpricechrisbobbe
authored andcommitted
api [nfc]: Introduce TopicName.apiName, and use for making API requests
1 parent 99c4b0b commit 7291212

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

lib/api/model/model.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,12 @@ enum MessageFlag {
658658
/// The name of a Zulip topic.
659659
// TODO(#1250): Migrate all implicit uses as String; remove "implements String".
660660
extension type const TopicName(String _value) implements String {
661+
/// The string this topic is identified by in the Zulip API.
662+
String get apiName => _value;
663+
661664
TopicName.fromJson(this._value);
662665

663-
String toJson() => _value;
666+
String toJson() => apiName;
664667
}
665668

666669
@JsonSerializable(fieldRename: FieldRename.snake)

lib/api/route/channels.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Future<void> updateUserTopicCompat(ApiConnection connection, {
5959
// https://zulip.com/api/mute-topic
6060
return connection.patch('muteTopic', (_) {}, 'users/me/subscriptions/muted_topics', {
6161
'stream_id': streamId,
62-
'topic': RawParameter(topic),
62+
'topic': RawParameter(topic.apiName),
6363
'op': RawParameter(op),
6464
});
6565
} else {
@@ -83,7 +83,7 @@ Future<void> updateUserTopic(ApiConnection connection, {
8383
assert(connection.zulipFeatureLevel! >= 170);
8484
return connection.post('updateUserTopic', (_) {}, 'user_topics', {
8585
'stream_id': streamId,
86-
'topic': RawParameter(topic),
86+
'topic': RawParameter(topic.apiName),
8787
'visibility_policy': visibilityPolicy,
8888
});
8989
}

lib/api/route/messages.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Future<SendMessageResult> sendMessage(
186186
StreamDestination() => {
187187
'type': RawParameter('stream'),
188188
'to': destination.streamId,
189-
'topic': RawParameter(destination.topic),
189+
'topic': RawParameter(destination.topic.apiName),
190190
},
191191
DmDestination() => {
192192
'type': supportsTypeDirect ? RawParameter('direct') : RawParameter('private'),
@@ -453,6 +453,6 @@ Future<void> markTopicAsRead(ApiConnection connection, {
453453
}) {
454454
return connection.post('markTopicAsRead', (_) {}, 'mark_topic_as_read', {
455455
'stream_id': streamId,
456-
'topic_name': RawParameter(topicName),
456+
'topic_name': RawParameter(topicName.apiName),
457457
});
458458
}

lib/api/route/typing.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Future<void> setTypingStatus(ApiConnection connection, {
1717
'type': RawParameter(supportsTypeChannel ? 'channel' : 'stream'),
1818
if (supportsStreamId) 'stream_id': destination.streamId
1919
else 'to': [destination.streamId],
20-
'topic': RawParameter(destination.topic),
20+
'topic': RawParameter(destination.topic.apiName),
2121
});
2222
case DmDestination():
2323
final supportsDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7)

test/api/model/model_checks.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ extension MessageChecks on Subject<Message> {
4646
Subject<String?> get matchTopic => has((e) => e.matchTopic, 'matchTopic');
4747
}
4848

49+
extension TopicNameChecks on Subject<TopicName> {
50+
Subject<String> get apiName => has((x) => x.apiName, 'apiName');
51+
}
52+
4953
extension StreamMessageChecks on Subject<StreamMessage> {
5054
Subject<String?> get displayRecipient => has((e) => e.displayRecipient, 'displayRecipient');
5155
Subject<TopicName> get topic => has((e) => e.topic, 'topic');

test/model/typing_status_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void checkSetTypingStatusRequests(
3535
'type': 'channel',
3636
'op': op.toJson(),
3737
'stream_id': narrow.streamId.toString(),
38-
'topic': narrow.topic}),
38+
'topic': narrow.topic.apiName}),
3939
DmNarrow() => conditionTypingRequest({
4040
'type': 'direct',
4141
'op': op.toJson(),

0 commit comments

Comments
 (0)