Skip to content

Commit b515da9

Browse files
committed
autocomplete: Use topic data from store in topic autocomplete
1 parent 342e468 commit b515da9

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/model/autocomplete.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:unorm_dart/unorm_dart.dart' as unorm;
66

77
import '../api/model/events.dart';
88
import '../api/model/model.dart';
9-
import '../api/route/channels.dart';
109
import '../generated/l10n/zulip_localizations.dart';
1110
import '../widgets/compose_box.dart';
1211
import 'algorithms.dart';
@@ -1175,10 +1174,8 @@ class TopicAutocompleteView extends AutocompleteView<TopicAutocompleteQuery, Top
11751174
Future<void> _fetch() async {
11761175
assert(!_isFetching);
11771176
_isFetching = true;
1178-
final result = await getStreamTopics(store.connection, streamId: streamId,
1179-
allowEmptyTopicName: true,
1180-
);
1181-
_topics = result.topics.map((e) => e.name);
1177+
await store.fetchTopics(streamId);
1178+
_topics = store.getChannelTopics(streamId)!.map((e) => e.name);
11821179
_isFetching = false;
11831180
return _startSearch();
11841181
}

test/model/autocomplete_test.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,19 +1277,28 @@ void main() {
12771277
check(done).isTrue();
12781278
});
12791279

1280-
test('TopicAutocompleteView getStreamTopics request', () async {
1280+
test('TopicAutocompleteView fetch topics once for a channel', () async {
12811281
final store = eg.store();
12821282
final connection = store.connection as FakeApiConnection;
12831283

12841284
connection.prepare(json: GetStreamTopicsResult(
1285-
topics: [eg.getStreamTopicsEntry(name: '')],
1285+
topics: [eg.getStreamTopicsEntry(name: 'topic')],
12861286
).toJson());
1287-
TopicAutocompleteView.init(store: store, streamId: 1000,
1288-
query: TopicAutocompleteQuery('foo'));
1289-
check(connection.lastRequest).isA<http.Request>()
1287+
final view = TopicAutocompleteView.init(store: store, streamId: 1000,
1288+
query: TopicAutocompleteQuery(''));
1289+
check(connection.takeRequests()).last.isA<http.Request>()
12901290
..method.equals('GET')
12911291
..url.path.equals('/api/v1/users/me/1000/topics')
12921292
..url.queryParameters['allow_empty_topic_name'].equals('true');
1293+
await Future(() {});
1294+
1295+
view.query = TopicAutocompleteQuery('top');
1296+
check(connection.takeRequests()).isEmpty();
1297+
view.dispose();
1298+
1299+
TopicAutocompleteView.init(store: store, streamId: 1000,
1300+
query: TopicAutocompleteQuery('topic'));
1301+
check(connection.takeRequests()).isEmpty();
12931302
});
12941303

12951304
group('TopicAutocompleteQuery.testTopic', () {

0 commit comments

Comments
 (0)