Skip to content

Commit 9c1128e

Browse files
committed
api: Add Subscription type, and deserialize at init
1 parent 7073a6e commit 9c1128e

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

lib/api/model/initial_snapshot.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class InitialSnapshot {
1919

2020
final List<CustomProfileField> custom_profile_fields;
2121

22-
// TODO many more
22+
// TODO etc., etc.
23+
24+
final List<Subscription> subscriptions;
25+
26+
// TODO etc., etc.
2327

2428
InitialSnapshot({
2529
this.queue_id,
@@ -29,6 +33,7 @@ class InitialSnapshot {
2933
this.zulip_merge_base,
3034
required this.alert_words,
3135
required this.custom_profile_fields,
36+
required this.subscriptions,
3237
});
3338

3439
factory InitialSnapshot.fromJson(Map<String, dynamic> json) =>

lib/api/model/initial_snapshot.g.dart

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

lib/api/model/model.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,72 @@ class CustomProfileField {
3030
factory CustomProfileField.fromJson(Map<String, dynamic> json) =>
3131
_$CustomProfileFieldFromJson(json);
3232
}
33+
34+
/// As in `subscriptions` in the initial snapshot.
35+
@JsonSerializable()
36+
class Subscription {
37+
final int stream_id;
38+
final String name;
39+
final String description;
40+
final String rendered_description;
41+
final int date_created;
42+
final bool invite_only;
43+
44+
// final List<int> subscribers; // we register with include_subscribers false
45+
46+
final bool? desktop_notifications;
47+
final bool? email_notifications;
48+
final bool? wildcard_mentions_notify;
49+
final bool? push_notifications;
50+
final bool? audible_notifications;
51+
52+
final bool pin_to_top;
53+
54+
final String email_address;
55+
56+
final bool is_muted;
57+
58+
// final bool? in_home_view; // deprecated; ignore
59+
60+
// final bool? is_announcement_only; // deprecated; ignore
61+
final bool? is_web_public; // TODO(server-??): doc doesn't say when added
62+
63+
final String color;
64+
65+
final int stream_post_policy; // TODO enum
66+
final int? message_retention_days;
67+
final bool history_public_to_subscribers;
68+
69+
final int? first_message_id;
70+
final int? stream_weekly_traffic;
71+
72+
final int? can_remove_subscribers_group_id; // TODO(server-6)
73+
74+
Subscription({
75+
required this.stream_id,
76+
required this.name,
77+
required this.description,
78+
required this.rendered_description,
79+
required this.date_created,
80+
required this.invite_only,
81+
this.desktop_notifications,
82+
this.email_notifications,
83+
this.wildcard_mentions_notify,
84+
this.push_notifications,
85+
this.audible_notifications,
86+
required this.pin_to_top,
87+
required this.email_address,
88+
required this.is_muted,
89+
this.is_web_public,
90+
required this.color,
91+
required this.stream_post_policy,
92+
this.message_retention_days,
93+
required this.history_public_to_subscribers,
94+
this.first_message_id,
95+
this.stream_weekly_traffic,
96+
this.can_remove_subscribers_group_id,
97+
});
98+
99+
factory Subscription.fromJson(Map<String, dynamic> json) =>
100+
_$SubscriptionFromJson(json);
101+
}

lib/api/model/model.g.dart

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

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class HomePage extends StatelessWidget {
9393
const SizedBox(height: 8),
9494
Text('Connected to: ${store.account.realmUrl}'),
9595
Text('Zulip server version: ${store.initialSnapshot.zulip_version}'),
96+
Text(
97+
'Subscribed to ${store.initialSnapshot.subscriptions.length} streams'),
9698
])));
9799
}
98100
}

0 commit comments

Comments
 (0)