Skip to content
Merged
6 changes: 6 additions & 0 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class InitialSnapshot {

final bool realmMandatoryTopics;

final String realmName;

/// The number of days until a user's account is treated as a full member.
///
/// Search for "realm_waiting_period_threshold" in https://zulip.com/api/register-queue.
Expand All @@ -103,6 +105,8 @@ class InitialSnapshot {

final bool realmEnableReadReceipts;

final Uri realmIconUrl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api: Add realmName and realmIcon to InitialSnapshot

nit: realmIconUrl in commit message, right?


final bool realmPresenceDisabled;

final Map<String, RealmDefaultExternalAccount> realmDefaultExternalAccounts;
Expand Down Expand Up @@ -174,11 +178,13 @@ class InitialSnapshot {
required this.realmDeleteOwnMessagePolicy,
required this.realmWildcardMentionPolicy,
required this.realmMandatoryTopics,
required this.realmName,
required this.realmWaitingPeriodThreshold,
required this.realmMessageContentDeleteLimitSeconds,
required this.realmAllowMessageEditing,
required this.realmMessageContentEditLimitSeconds,
required this.realmEnableReadReceipts,
required this.realmIconUrl,
required this.realmPresenceDisabled,
required this.realmDefaultExternalAccounts,
required this.maxFileUploadSizeMib,
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.

2 changes: 1 addition & 1 deletion lib/api/route/realm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class GetServerSettingsResult {
final Uri realmUrl;

final String realmName;
final String realmIcon;
final Uri realmIcon;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do this before adding the corresponding field on InitialSnapshot; that way they agree from the beginning

final String realmDescription;
final bool realmWebPublicAccessEnabled;

Expand Down
4 changes: 2 additions & 2 deletions lib/api/route/realm.g.dart

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

21 changes: 20 additions & 1 deletion lib/model/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:drift/internal/versioned_schema.dart';
import 'package:drift/remote.dart';
import 'package:sqlite3/common.dart';

import '../api/route/realm.dart';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db: Store realmName and realmIcon in the Accounts table

And update account creation during login to populate
these fields from server settings.

Updates: #1036

Hmm I haven't seen an Updates: <issue> line before; what does that mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I just meant to relate to the issue that this commit partly fixes. I guess Related: or the more direct Fixes-partly: fits better here.

import '../log.dart';
import 'legacy_app_data.dart';
import 'schema_versions.g.dart';
Expand Down Expand Up @@ -128,6 +129,20 @@ class Accounts extends Table {
/// It never changes for a given account.
Column<String> get realmUrl => text().map(const UriConverter())();

/// The name of the Zulip realm this account is on.
///
/// This corresponds to [GetServerSettingsResult.realmName].
///
/// Nullable just because older versions of the app didn't store this.
Column<String> get realmName => text().nullable()();

/// The icon URL of the Zulip realm this account is on.
///
/// This corresponds to [GetServerSettingsResult.realmIcon].
///
/// Nullable just because older versions of the app didn't store this.
Column<String> get realmIcon => text().map(const UriConverter()).nullable()();

/// The Zulip user ID of this account.
///
/// This is the identifier the server uses for the account.
Expand Down Expand Up @@ -169,7 +184,7 @@ class AppDatabase extends _$AppDatabase {
// information on using the build_runner.
// * Write a migration in `_migrationSteps` below.
// * Write tests.
static const int latestSchemaVersion = 11; // See note.
static const int latestSchemaVersion = 12; // See note.

@override
int get schemaVersion => latestSchemaVersion;
Expand Down Expand Up @@ -264,6 +279,10 @@ class AppDatabase extends _$AppDatabase {
'value': Variable(firstAccountId),
}));
},
from11To12: (Migrator m, Schema12 schema) async {
await m.addColumn(schema.accounts, schema.accounts.realmName);
await m.addColumn(schema.accounts, schema.accounts.realmIcon);
},
);

Future<void> _createLatestSchema(Migrator m) async {
Expand Down
Loading