Skip to content

Commit 7a40e0a

Browse files
committed
api: Add realmUserGroups to InitialSnapshot
1 parent 092d035 commit 7a40e0a

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

lib/api/model/initial_snapshot.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class InitialSnapshot {
5656

5757
final Map<String, RealmEmojiItem> realmEmoji;
5858

59+
final List<UserGroup> realmUserGroups;
60+
5961
final List<RecentDmConversation> recentPrivateConversations;
6062

6163
final List<SavedSnippet>? savedSnippets; // TODO(server-10)
@@ -149,6 +151,7 @@ class InitialSnapshot {
149151
required this.mutedUsers,
150152
required this.presences,
151153
required this.realmEmoji,
154+
required this.realmUserGroups,
152155
required this.recentPrivateConversations,
153156
required this.savedSnippets,
154157
required this.subscriptions,

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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ enum Emojiset {
199199
.map((key, value) => MapEntry(value, key));
200200
}
201201

202+
/// As in [InitialSnapshot.realmUserGroups].
203+
@JsonSerializable(fieldRename: FieldRename.snake)
204+
class UserGroup {
205+
final int id;
206+
207+
// List<int> members; // TODO(#1687) track group members
208+
// List<int> directSubgroupIds; // TODO(#1687) track group members
209+
210+
String name;
211+
String description;
212+
213+
// final int? dateCreated; // not using; ignore
214+
// final int? creatorId; // not using; ignore
215+
216+
final bool isSystemGroup;
217+
218+
// TODO(server-10): [deactivated] new in FL 290; previously no groups were deactivated
219+
@JsonKey(defaultValue: false)
220+
bool deactivated;
221+
222+
// TODO(#814): GroupSettingValue canAddMembersGroup, etc.
223+
224+
UserGroup({
225+
required this.id,
226+
required this.name,
227+
required this.description,
228+
required this.isSystemGroup,
229+
required this.deactivated,
230+
});
231+
232+
factory UserGroup.fromJson(Map<String, dynamic> json) => _$UserGroupFromJson(json);
233+
234+
Map<String, dynamic> toJson() => _$UserGroupToJson(this);
235+
}
236+
202237
/// As in [InitialSnapshot.realmUsers], [InitialSnapshot.realmNonActiveUsers], and [InitialSnapshot.crossRealmBots].
203238
///
204239
/// In the Zulip API, the items in realm_users, realm_non_active_users, and

lib/api/model/model.g.dart

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

test/api/model/model_checks.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import 'package:checks/checks.dart';
22
import 'package:zulip/api/model/model.dart';
33
import 'package:zulip/api/model/submessage.dart';
44

5+
extension UserGroupChecks on Subject<UserGroup> {
6+
Subject<int> get id => has((x) => x.id, 'id');
7+
Subject<String> get name => has((x) => x.name, 'name');
8+
Subject<String> get description => has((x) => x.description, 'description');
9+
Subject<bool> get isSystemGroup => has((x) => x.isSystemGroup, 'isSystemGroup');
10+
Subject<bool> get deactivated => has((x) => x.deactivated, 'deactivated');
11+
}
12+
513
extension UserChecks on Subject<User> {
614
Subject<int> get userId => has((x) => x.userId, 'userId');
715
Subject<String?> get deliveryEmail => has((x) => x.deliveryEmail, 'deliveryEmail');

test/example_data.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ ServerEmojiData serverEmojiDataPopularLegacy = ServerEmojiData(codeToNames: {
166166
'1f419': ['octopus'],
167167
});
168168

169+
/// A fresh user-group ID, from a random but always strictly increasing sequence.
170+
int _nextUserGroupId() => (_lastUserGroupId += 1 + Random().nextInt(10));
171+
int _lastUserGroupId = 100;
172+
173+
UserGroup userGroup({
174+
int? id,
175+
String? name,
176+
String? description,
177+
bool isSystemGroup = false,
178+
bool deactivated = false,
179+
}) {
180+
return UserGroup(
181+
id: id ??= _nextUserGroupId(),
182+
name: name ??= 'group-$id',
183+
description: description ?? 'A group named $name',
184+
isSystemGroup: isSystemGroup,
185+
deactivated: deactivated,
186+
);
187+
}
188+
169189
RealmEmojiItem realmEmojiItem({
170190
required String emojiCode,
171191
required String emojiName,
@@ -1112,6 +1132,7 @@ InitialSnapshot initialSnapshot({
11121132
List<MutedUserItem>? mutedUsers,
11131133
Map<int, PerUserPresence>? presences,
11141134
Map<String, RealmEmojiItem>? realmEmoji,
1135+
List<UserGroup>? realmUserGroups,
11151136
List<RecentDmConversation>? recentPrivateConversations,
11161137
List<SavedSnippet>? savedSnippets,
11171138
List<Subscription>? subscriptions,
@@ -1153,6 +1174,7 @@ InitialSnapshot initialSnapshot({
11531174
mutedUsers: mutedUsers ?? [],
11541175
presences: presences ?? {},
11551176
realmEmoji: realmEmoji ?? {},
1177+
realmUserGroups: realmUserGroups ?? [],
11561178
recentPrivateConversations: recentPrivateConversations ?? [],
11571179
savedSnippets: savedSnippets ?? [],
11581180
subscriptions: subscriptions ?? [], // TODO add subscriptions to default

0 commit comments

Comments
 (0)