Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add streams to PerAccountStore #139

Merged
merged 4 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ part 'initial_snapshot.g.dart';
// https://zulip.com/api/register-queue#response
@JsonSerializable(fieldRename: FieldRename.snake)
class InitialSnapshot {
// Keep these fields in the order they appear in the API docs.
// (For many API types we choose a more logical order than the docs.
// But this one is so long that that'd make it become impossible to
// compare the lists by hand.)

final String? queueId;
final int lastEventId;
final int zulipFeatureLevel;
Expand All @@ -21,6 +26,8 @@ class InitialSnapshot {

final List<Subscription> subscriptions;

final List<ZulipStream> streams;

final int maxFileUploadSizeMib;

@JsonKey(readValue: _readUsersIsActiveFallbackTrue)
Expand All @@ -31,6 +38,7 @@ class InitialSnapshot {
final List<User> crossRealmBots;

// TODO etc., etc.
// If adding fields, keep them all in the order they appear in the API docs.

// `is_active` is sometimes absent:
// https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/.60is_active.60.20in.20.60.2Fregister.60.20response/near/1371603
Expand Down Expand Up @@ -59,6 +67,7 @@ class InitialSnapshot {
required this.alertWords,
required this.customProfileFields,
required this.subscriptions,
required this.streams,
required this.maxFileUploadSizeMib,
required this.realmUsers,
required this.realmNonActiveUsers,
Expand Down
4 changes: 4 additions & 0 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.

91 changes: 73 additions & 18 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ part 'model.g.dart';

/// As in [InitialSnapshot.customProfileFields].
///
/// https://zulip.com/api/register-queue#response
/// For docs, search for "custom_profile_fields:"
/// in <https://zulip.com/api/register-queue>.
@JsonSerializable(fieldRename: FieldRename.snake)
class CustomProfileField {
final int id;
Expand Down Expand Up @@ -50,7 +51,8 @@ class ProfileFieldUserData {
/// cross_realm_bots are all extremely similar. They differ only in that
/// cross_realm_bots has is_system_bot.
///
/// https://zulip.com/api/register-queue#response
/// For docs, search for "realm_users:"
/// in <https://zulip.com/api/register-queue>.
@JsonSerializable(fieldRename: FieldRename.snake)
class User {
final int userId;
Expand Down Expand Up @@ -118,18 +120,86 @@ class User {
Map<String, dynamic> toJson() => _$UserToJson(this);
}

/// As in `streams` in the initial snapshot.
///
/// Not called `Stream` because dart:async uses that name.
///
/// For docs, search for "if stream"
/// in <https://zulip.com/api/register-queue>.
@JsonSerializable(fieldRename: FieldRename.snake)
class ZulipStream {
final int streamId;
final String name;
final String description;
final String renderedDescription;

final int dateCreated;
final int? firstMessageId;

final bool inviteOnly;
final bool isWebPublic; // present since 2.1, according to /api/changelog
final bool historyPublicToSubscribers;
final int? messageRetentionDays;

final int streamPostPolicy; // TODO enum
// final bool isAnnouncementOnly; // deprecated; ignore

final int? canRemoveSubscribersGroupId; // TODO(server-6)

ZulipStream({
required this.streamId,
required this.name,
required this.description,
required this.renderedDescription,
required this.dateCreated,
required this.firstMessageId,
required this.inviteOnly,
required this.isWebPublic,
required this.historyPublicToSubscribers,
required this.messageRetentionDays,
required this.streamPostPolicy,
required this.canRemoveSubscribersGroupId,
});

factory ZulipStream.fromJson(Map<String, dynamic> json) =>
_$ZulipStreamFromJson(json);

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

/// As in `subscriptions` in the initial snapshot.
///
/// For docs, search for "subscriptions:"
/// in <https://zulip.com/api/register-queue>.
@JsonSerializable(fieldRename: FieldRename.snake)
class Subscription {
// First, fields that are about the stream and not the user's relation to it.
// These are largely the same as in [ZulipStream].

final int streamId;
final String name;
final String description;
final String renderedDescription;

final int dateCreated;
final bool inviteOnly;
final int? firstMessageId;
final int? streamWeeklyTraffic;

final bool inviteOnly;
final bool? isWebPublic; // TODO(server-??): doc doesn't say when added
final bool historyPublicToSubscribers;
final int? messageRetentionDays;
// final List<int> subscribers; // we register with includeSubscribers false

final int streamPostPolicy; // TODO enum
// final bool? isAnnouncementOnly; // deprecated; ignore
final String emailAddress;

final int? canRemoveSubscribersGroupId; // TODO(server-6)

// Then, fields that are specific to the subscription,
// i.e. the user's relationship to the stream.

final bool? desktopNotifications;
final bool? emailNotifications;
final bool? wildcardMentionsNotify;
Expand All @@ -138,26 +208,11 @@ class Subscription {

final bool pinToTop;

final String emailAddress;

final bool isMuted;

// final bool? inHomeView; // deprecated; ignore

// final bool? isAnnouncementOnly; // deprecated; ignore
final bool? isWebPublic; // TODO(server-??): doc doesn't say when added

final String color;

final int streamPostPolicy; // TODO enum
final int? messageRetentionDays;
final bool historyPublicToSubscribers;

final int? firstMessageId;
final int? streamWeeklyTraffic;

final int? canRemoveSubscribersGroupId; // TODO(server-6)

Subscription({
required this.streamId,
required this.name,
Expand Down
32 changes: 32 additions & 0 deletions lib/api/model/model.g.dart

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

4 changes: 4 additions & 0 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,19 @@ class PerAccountStore extends ChangeNotifier {
.followedBy(initialSnapshot.realmNonActiveUsers)
.followedBy(initialSnapshot.crossRealmBots)
.map((user) => MapEntry(user.userId, user))),
streams = Map.fromEntries(initialSnapshot.streams.map(
(stream) => MapEntry(stream.streamId, stream))),
subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
(subscription) => MapEntry(subscription.streamId, subscription))),
maxFileUploadSizeMib = initialSnapshot.maxFileUploadSizeMib;

final Account account;
final ApiConnection connection;

// TODO(#135): Keep all this data updated by handling Zulip events from the server.
final String zulipVersion;
final Map<int, User> users;
final Map<int, ZulipStream> streams;
final Map<int, Subscription> subscriptions;
final int maxFileUploadSizeMib; // No event for this.

Expand Down
1 change: 1 addition & 0 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ final InitialSnapshot initialSnapshot = InitialSnapshot(
alertWords: ['klaxon'],
customProfileFields: [],
subscriptions: [], // TODO add subscriptions to example initial snapshot
streams: [], // TODO add streams to example initial snapshot
maxFileUploadSizeMib: 25,
realmUsers: [],
realmNonActiveUsers: [],
Expand Down