Skip to content

Commit 2e0d903

Browse files
Khader-1gnprice
authored andcommitted
api [nfc]: Rename references of UnreadChannelSnapshot to match it's name
1 parent 3a57292 commit 2e0d903

File tree

8 files changed

+43
-21
lines changed

8 files changed

+43
-21
lines changed

lib/api/model/initial_snapshot.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ class UnreadMessagesSnapshot {
229229
@JsonKey(name: 'pms')
230230
final List<UnreadDmSnapshot> dms;
231231

232-
final List<UnreadChannelSnapshot> streams;
232+
@JsonKey(name: 'streams')
233+
final List<UnreadChannelSnapshot> channels;
233234
final List<UnreadHuddleSnapshot> huddles;
234235

235236
// Unlike other lists of message IDs here, [mentions] is *not* sorted.
@@ -240,7 +241,7 @@ class UnreadMessagesSnapshot {
240241
const UnreadMessagesSnapshot({
241242
required this.count,
242243
required this.dms,
243-
required this.streams,
244+
required this.channels,
244245
required this.huddles,
245246
required this.mentions,
246247
required this.oldUnreadsMissing,
@@ -275,7 +276,7 @@ class UnreadDmSnapshot {
275276
Map<String, dynamic> toJson() => _$UnreadDmSnapshotToJson(this);
276277
}
277278

278-
/// An item in [UnreadMessagesSnapshot.streams].
279+
/// An item in [UnreadMessagesSnapshot.channels].
279280
@JsonSerializable(fieldRename: FieldRename.snake)
280281
class UnreadChannelSnapshot {
281282
final String topic;

lib/api/model/initial_snapshot.g.dart

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

lib/model/unreads.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class Unreads extends ChangeNotifier {
4545
final dms = <DmNarrow, QueueList<int>>{};
4646
final mentions = Set.of(initial.mentions);
4747

48-
for (final unreadStreamSnapshot in initial.streams) {
49-
final streamId = unreadStreamSnapshot.streamId;
50-
final topic = unreadStreamSnapshot.topic;
51-
(streams[streamId] ??= {})[topic] = QueueList.from(unreadStreamSnapshot.unreadMessageIds);
48+
for (final unreadChannelSnapshot in initial.channels) {
49+
final streamId = unreadChannelSnapshot.streamId;
50+
final topic = unreadChannelSnapshot.topic;
51+
(streams[streamId] ??= {})[topic] = QueueList.from(unreadChannelSnapshot.unreadMessageIds);
5252
}
5353

5454
for (final unreadDmSnapshot in initial.dms) {

test/api/model/initial_snapshot_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,28 @@ import 'package:checks/checks.dart';
22
import 'package:test/scaffolding.dart';
33
import 'package:zulip/api/model/initial_snapshot.dart';
44

5+
import '../../stdlib_checks.dart';
6+
57
void main() {
8+
test('UnreadMessagesSnapshot from json recognizes channels as streams', () {
9+
final snapshot = UnreadMessagesSnapshot.fromJson({
10+
'count': 1,
11+
'pms': <dynamic>[],
12+
'huddles': <dynamic>[],
13+
'mentions': <dynamic>[],
14+
'old_unreads_missing': false,
15+
'streams': [{
16+
'stream_id': 1,
17+
'topic': 'topic name',
18+
'unread_message_ids': [1, 2]}]
19+
});
20+
21+
check(snapshot.channels).single.jsonEquals(
22+
UnreadChannelSnapshot(
23+
topic: 'topic name', streamId: 1,
24+
unreadMessageIds: [1, 2]));
25+
});
26+
627
test('UnreadDmSnapshot: require sorted unreadMessageIds', () {
728
check(() => UnreadDmSnapshot.fromJson({
829
'other_user_id': 1,

test/example_data.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,15 @@ DmMessage dmMessage({
396396
UnreadMessagesSnapshot unreadMsgs({
397397
int? count,
398398
List<UnreadDmSnapshot>? dms,
399-
List<UnreadChannelSnapshot>? streams,
399+
List<UnreadChannelSnapshot>? channels,
400400
List<UnreadHuddleSnapshot>? huddles,
401401
List<int>? mentions,
402402
bool? oldUnreadsMissing,
403403
}) {
404404
return UnreadMessagesSnapshot(
405405
count: count ?? 0,
406406
dms: dms ?? [],
407-
streams: streams ?? [],
407+
channels: channels ?? [],
408408
huddles: huddles ?? [],
409409
mentions: mentions ?? [],
410410
oldUnreadsMissing: oldUnreadsMissing ?? false,

test/model/unreads_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void main() {
3030
void prepare({
3131
UnreadMessagesSnapshot initial = const UnreadMessagesSnapshot(
3232
count: 0,
33-
streams: [],
33+
channels: [],
3434
dms: [],
3535
huddles: [],
3636
mentions: [],
@@ -113,7 +113,7 @@ void main() {
113113

114114
prepare(initial: UnreadMessagesSnapshot(
115115
count: 0,
116-
streams: [
116+
channels: [
117117
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
118118
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'b', unreadMessageIds: [3, 4]),
119119
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [5, 6]),

test/widgets/message_list_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ void main() {
865865

866866
testWidgets('from unread to read', (WidgetTester tester) async {
867867
final message = eg.streamMessage(flags: []);
868-
final unreadMsgs = eg.unreadMsgs(streams:[
868+
final unreadMsgs = eg.unreadMsgs(channels:[
869869
UnreadChannelSnapshot(topic: message.topic, streamId: message.streamId, unreadMessageIds: [message.id])
870870
]);
871871
await setupMessageListPage(tester, messages: [message], unreadMsgs: unreadMsgs);
@@ -883,7 +883,7 @@ void main() {
883883

884884
testWidgets("messages don't shift position", (WidgetTester tester) async {
885885
final message = eg.streamMessage(flags: []);
886-
final unreadMsgs = eg.unreadMsgs(streams:[
886+
final unreadMsgs = eg.unreadMsgs(channels:[
887887
UnreadChannelSnapshot(topic: message.topic, streamId: message.streamId,
888888
unreadMessageIds: [message.id])
889889
]);
@@ -912,7 +912,7 @@ void main() {
912912
// and a couple of smoke tests showing this button is wired up to it.
913913

914914
final message = eg.streamMessage(flags: []);
915-
final unreadMsgs = eg.unreadMsgs(streams: [
915+
final unreadMsgs = eg.unreadMsgs(channels: [
916916
UnreadChannelSnapshot(streamId: message.streamId, topic: message.topic,
917917
unreadMessageIds: [message.id]),
918918
]);

test/widgets/subscription_list_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void main() {
146146

147147
testWidgets('unread badge shows with unreads', (tester) async {
148148
final stream = eg.stream();
149-
final unreadMsgs = eg.unreadMsgs(streams: [
149+
final unreadMsgs = eg.unreadMsgs(channels: [
150150
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
151151
]);
152152
await setupStreamListPage(tester, subscriptions: [
@@ -157,7 +157,7 @@ void main() {
157157

158158
testWidgets('unread badge counts unmuted only', (tester) async {
159159
final stream = eg.stream();
160-
final unreadMsgs = eg.unreadMsgs(streams: [
160+
final unreadMsgs = eg.unreadMsgs(channels: [
161161
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
162162
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
163163
]);
@@ -177,7 +177,7 @@ void main() {
177177

178178
testWidgets('unread badge does not show with no unreads', (tester) async {
179179
final stream = eg.stream();
180-
final unreadMsgs = eg.unreadMsgs(streams: []);
180+
final unreadMsgs = eg.unreadMsgs(channels: []);
181181
await setupStreamListPage(tester, subscriptions: [
182182
eg.subscription(stream),
183183
], unreadMsgs: unreadMsgs);
@@ -186,7 +186,7 @@ void main() {
186186

187187
testWidgets('color propagates to icon and badge', (tester) async {
188188
final stream = eg.stream();
189-
final unreadMsgs = eg.unreadMsgs(streams: [
189+
final unreadMsgs = eg.unreadMsgs(channels: [
190190
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
191191
]);
192192
final subscription = eg.subscription(stream, color: Colors.red.value);
@@ -224,7 +224,7 @@ void main() {
224224
eg.userTopicItem(stream1, 'a', UserTopicVisibilityPolicy.unmuted),
225225
eg.userTopicItem(stream2, 'b', UserTopicVisibilityPolicy.unmuted),
226226
],
227-
unreadMsgs: eg.unreadMsgs(streams: [
227+
unreadMsgs: eg.unreadMsgs(channels: [
228228
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
229229
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
230230
]),

0 commit comments

Comments
 (0)