Skip to content

Commit

Permalink
for Future
Browse files Browse the repository at this point in the history
  • Loading branch information
chimnayajith committed Jan 31, 2025
1 parent abec662 commit c78d914
Show file tree
Hide file tree
Showing 14 changed files with 876 additions and 17 deletions.
76 changes: 76 additions & 0 deletions lib/api/model/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ sealed class Event {
default: return UnexpectedEvent.fromJson(json);
}
case 'custom_profile_fields': return CustomProfileFieldsEvent.fromJson(json);
case 'realm':
switch (json['op'] as String) {
case 'update': return RealmUpdateEvent.fromJson(json);
case 'update_dict': return RealmUpdateDictEvent.fromJson(json);
default: return UnexpectedEvent.fromJson(json);
}
case 'realm_user':
switch (json['op'] as String) {
case 'add': return RealmUserAddEvent.fromJson(json);
Expand Down Expand Up @@ -196,6 +202,76 @@ class CustomProfileFieldsEvent extends Event {
@override
Map<String, dynamic> toJson() => _$CustomProfileFieldsEventToJson(this);
}
/// A Zulip event of type `realm`.
///
/// The corresponding API docs are in several places for
/// different values of `op`; see subclasses.
sealed class RealmEvent extends Event {
@override
@JsonKey(includeToJson: true)
String get type => 'realm';

String get op;

RealmEvent({required super.id});
}

/// A [RealmEvent] with op `update`: Represents an update to a specific property in the realm configuration.
/// See: https://zulip.com/api/get-events#realm-update
@JsonSerializable(fieldRename: FieldRename.snake)
class RealmUpdateEvent extends RealmEvent {
@override
@JsonKey(includeToJson: true)
String get op => 'update';

final String property;
final dynamic value;

RealmUpdateEvent({
required super.id,
required this.property,
required this.value,
});

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

@override
Map<String, dynamic> toJson() => _$RealmUpdateEventToJson(this);

/// Converts this update event into an update_dict event
RealmUpdateDictEvent toUpdateDictEvent() {
return RealmUpdateDictEvent(
id: id,
property: 'default',
data: {property: value},
);
}
}

/// A [RealmEvent] with op `update_dict`: Represents an update to multiple properties in the realm configuration.
/// See: https://zulip.com/api/get-events#realm-update_dict
@JsonSerializable(fieldRename: FieldRename.snake)
class RealmUpdateDictEvent extends RealmEvent {
@override
@JsonKey(includeToJson: true)
String get op => 'update';

final String property;
final Map<String, dynamic> data;

RealmUpdateDictEvent({
required super.id,
required this.property,
required this.data,
});

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

@override
Map<String, dynamic> toJson() => _$RealmUpdateDictEventToJson(this);
}

/// A Zulip event of type `realm_user`.
///
Expand Down
34 changes: 34 additions & 0 deletions lib/api/model/events.g.dart

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

8 changes: 7 additions & 1 deletion lib/model/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Accounts extends Table {
/// This corresponds to [GetServerSettingsResult.realmUrl].
/// It never changes for a given account.
Column<String> get realmUrl => text().map(const UriConverter())();
Column<String> get realmName => text().nullable()();
Column<String> get realmIcon => text().nullable()();

/// The Zulip user ID of this account.
///
Expand Down Expand Up @@ -74,7 +76,7 @@ class AppDatabase extends _$AppDatabase {
// * Write a migration in `onUpgrade` below.
// * Write tests.
@override
int get schemaVersion => 2; // See note.
int get schemaVersion => 3; // See note.

@override
MigrationStrategy get migration {
Expand All @@ -100,6 +102,10 @@ class AppDatabase extends _$AppDatabase {
if (from < 2 && 2 <= to) {
await m.addColumn(accounts, accounts.ackedPushToken);
}
if (from < 3 && 3 <= to) {
await m.addColumn(accounts, accounts.realmName);
await m.addColumn(accounts, accounts.realmIcon);
}
// New migrations go here.
}
);
Expand Down
Loading

0 comments on commit c78d914

Please sign in to comment.