Skip to content

Commit

Permalink
api [nfc]: Rename UnreadStreamSnapshot to UnreadChannelSnapshot
Browse files Browse the repository at this point in the history
Fixes parts of zulip#631
  • Loading branch information
Khader-1 authored and gnprice committed Jul 30, 2024
1 parent 26fc976 commit 3a57292
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class UnreadMessagesSnapshot {
@JsonKey(name: 'pms')
final List<UnreadDmSnapshot> dms;

final List<UnreadStreamSnapshot> streams;
final List<UnreadChannelSnapshot> streams;
final List<UnreadHuddleSnapshot> huddles;

// Unlike other lists of message IDs here, [mentions] is *not* sorted.
Expand Down Expand Up @@ -277,21 +277,21 @@ class UnreadDmSnapshot {

/// An item in [UnreadMessagesSnapshot.streams].
@JsonSerializable(fieldRename: FieldRename.snake)
class UnreadStreamSnapshot {
class UnreadChannelSnapshot {
final String topic;
final int streamId;
final List<int> unreadMessageIds;

UnreadStreamSnapshot({
UnreadChannelSnapshot({
required this.topic,
required this.streamId,
required this.unreadMessageIds,
}) : assert(isSortedWithoutDuplicates(unreadMessageIds));

factory UnreadStreamSnapshot.fromJson(Map<String, dynamic> json) =>
_$UnreadStreamSnapshotFromJson(json);
factory UnreadChannelSnapshot.fromJson(Map<String, dynamic> json) =>
_$UnreadChannelSnapshotFromJson(json);

Map<String, dynamic> toJson() => _$UnreadStreamSnapshotToJson(this);
Map<String, dynamic> toJson() => _$UnreadChannelSnapshotToJson(this);
}

/// An item in [UnreadMessagesSnapshot.huddles].
Expand Down
10 changes: 5 additions & 5 deletions lib/api/model/initial_snapshot.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/api/model/initial_snapshot_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ void main() {
})).throws<AssertionError>();
});

test('UnreadStreamSnapshot: require sorted unreadMessageIds', () {
check(() => UnreadStreamSnapshot.fromJson({
test('UnreadChannelSnapshot: require sorted unreadMessageIds', () {
check(() => UnreadChannelSnapshot.fromJson({
'topic': 'a',
'stream_id': 1,
'unread_message_ids': [1, 2, 3],
})).returnsNormally();

check(() => UnreadStreamSnapshot.fromJson({
check(() => UnreadChannelSnapshot.fromJson({
'topic': 'a',
'stream_id': 1,
'unread_message_ids': [11, 2, 3],
Expand Down
2 changes: 1 addition & 1 deletion test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ DmMessage dmMessage({
UnreadMessagesSnapshot unreadMsgs({
int? count,
List<UnreadDmSnapshot>? dms,
List<UnreadStreamSnapshot>? streams,
List<UnreadChannelSnapshot>? streams,
List<UnreadHuddleSnapshot>? huddles,
List<int>? mentions,
bool? oldUnreadsMissing,
Expand Down
8 changes: 4 additions & 4 deletions test/model/unreads_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ void main() {
prepare(initial: UnreadMessagesSnapshot(
count: 0,
streams: [
UnreadStreamSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadStreamSnapshot(streamId: stream1.streamId, topic: 'b', unreadMessageIds: [3, 4]),
UnreadStreamSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [5, 6]),
UnreadStreamSnapshot(streamId: stream2.streamId, topic: 'c', unreadMessageIds: [7, 8]),
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'b', unreadMessageIds: [3, 4]),
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [5, 6]),
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'c', unreadMessageIds: [7, 8]),
],
dms: [
UnreadDmSnapshot(otherUserId: 1, unreadMessageIds: [9, 10]),
Expand Down
6 changes: 3 additions & 3 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ void main() {
testWidgets('from unread to read', (WidgetTester tester) async {
final message = eg.streamMessage(flags: []);
final unreadMsgs = eg.unreadMsgs(streams:[
UnreadStreamSnapshot(topic: message.topic, streamId: message.streamId, unreadMessageIds: [message.id])
UnreadChannelSnapshot(topic: message.topic, streamId: message.streamId, unreadMessageIds: [message.id])
]);
await setupMessageListPage(tester, messages: [message], unreadMsgs: unreadMsgs);
check(isMarkAsReadButtonVisible(tester)).isTrue();
Expand All @@ -884,7 +884,7 @@ void main() {
testWidgets("messages don't shift position", (WidgetTester tester) async {
final message = eg.streamMessage(flags: []);
final unreadMsgs = eg.unreadMsgs(streams:[
UnreadStreamSnapshot(topic: message.topic, streamId: message.streamId,
UnreadChannelSnapshot(topic: message.topic, streamId: message.streamId,
unreadMessageIds: [message.id])
]);
await setupMessageListPage(tester,
Expand Down Expand Up @@ -913,7 +913,7 @@ void main() {

final message = eg.streamMessage(flags: []);
final unreadMsgs = eg.unreadMsgs(streams: [
UnreadStreamSnapshot(streamId: message.streamId, topic: message.topic,
UnreadChannelSnapshot(streamId: message.streamId, topic: message.topic,
unreadMessageIds: [message.id]),
]);

Expand Down
12 changes: 6 additions & 6 deletions test/widgets/subscription_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void main() {
testWidgets('unread badge shows with unreads', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(streams: [
UnreadStreamSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
]);
await setupStreamListPage(tester, subscriptions: [
eg.subscription(stream),
Expand All @@ -158,8 +158,8 @@ void main() {
testWidgets('unread badge counts unmuted only', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(streams: [
UnreadStreamSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadStreamSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
]);
await setupStreamListPage(tester,
subscriptions: [eg.subscription(stream, isMuted: true)],
Expand Down Expand Up @@ -187,7 +187,7 @@ void main() {
testWidgets('color propagates to icon and badge', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(streams: [
UnreadStreamSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
]);
final subscription = eg.subscription(stream, color: Colors.red.value);
final swatch = StreamColorSwatch.light(subscription.color);
Expand Down Expand Up @@ -225,8 +225,8 @@ void main() {
eg.userTopicItem(stream2, 'b', UserTopicVisibilityPolicy.unmuted),
],
unreadMsgs: eg.unreadMsgs(streams: [
UnreadStreamSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadStreamSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
]),
);

Expand Down

0 comments on commit 3a57292

Please sign in to comment.