Skip to content
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
12 changes: 12 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,18 @@
"@yesterday": {
"description": "Term to use to reference the previous day."
},
"invisibleMode": "Invisible mode",
"@invisibleMode": {
"description": "Label for the 'Invisible mode' switch on the profile page."
},
"turnOnInvisibleModeErrorTitle": "Error turning on invisible mode. Please try again.",
"@turnOnInvisibleModeErrorTitle": {
"description": "Error title when turning on invisible mode failed."
},
"turnOffInvisibleModeErrorTitle": "Error turning off invisible mode. Please try again.",
"@turnOffInvisibleModeErrorTitle": {
"description": "Error title when turning off invisible mode failed."
},
"userRoleOwner": "Owner",
"@userRoleOwner": {
"description": "Label for UserRole.owner"
Expand Down
2 changes: 2 additions & 0 deletions lib/api/model/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class UserSettingsUpdateEvent extends Event {
return value as bool;
case UserSettingName.emojiset:
return Emojiset.fromRawString(value as String);
case UserSettingName.presenceEnabled:
return value as bool;
case null:
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/api/model/events.g.dart

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

11 changes: 4 additions & 7 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ class InitialSnapshot {

final List<ZulipStream> streams;

// Servers pre-5.0 don't have `user_settings`, and instead provide whatever
// user settings they support at toplevel in the initial snapshot. Since we're
// likely to desupport pre-5.0 servers before wide release, we prefer to
// ignore the toplevel fields and use `user_settings` where present instead,
// even at the expense of functionality with pre-5.0 servers.
// TODO(server-5) remove pre-5.0 comment
final UserSettings? userSettings; // TODO(server-5)
final UserSettings userSettings;

final List<UserTopicItem>? userTopics; // TODO(server-6)

Expand Down Expand Up @@ -257,16 +251,19 @@ class UserSettings {
bool twentyFourHourTime;
bool? displayEmojiReactionUsers; // TODO(server-6)
Emojiset emojiset;
bool presenceEnabled;

// TODO more, as needed. When adding a setting here, please also:
// (1) add it to the [UserSettingName] enum
// (2) then re-run the command to refresh the .g.dart files
// (3) handle the event that signals an update to the setting
// (4) add the setting to the [updateSettings] route binding

UserSettings({
required this.twentyFourHourTime,
required this.displayEmojiReactionUsers,
required this.emojiset,
required this.presenceEnabled,
});

factory UserSettings.fromJson(Map<String, dynamic> json) =>
Expand Down
11 changes: 7 additions & 4 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.

8 changes: 7 additions & 1 deletion lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class RealmEmojiItem {
enum UserSettingName {
twentyFourHourTime,
displayEmojiReactionUsers,
emojiset;
emojiset,
presenceEnabled,
;

/// Get a [UserSettingName] from a raw, snake-case string we recognize, else null.
///
Expand All @@ -178,6 +180,8 @@ enum UserSettingName {
// _$…EnumMap is thanks to `alwaysCreate: true` and `fieldRename: FieldRename.snake`
static final _byRawString = _$UserSettingNameEnumMap
.map((key, value) => MapEntry(value, key));

String toJson() => _$UserSettingNameEnumMap[this]!;
}

/// As in [UserSettings.emojiset].
Expand All @@ -197,6 +201,8 @@ enum Emojiset {
// _$…EnumMap is thanks to `alwaysCreate: true` and `fieldRename: FieldRename.kebab`
static final _byRawString = _$EmojisetEnumMap
.map((key, value) => MapEntry(value, key));

String toJson() => _$EmojisetEnumMap[this]!;
}

/// As in [InitialSnapshot.realmUserGroups] or [UserGroupAddEvent].
Expand Down
1 change: 1 addition & 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.

22 changes: 22 additions & 0 deletions lib/api/route/settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '../core.dart';
import '../model/model.dart';

/// https://zulip.com/api/update-settings
Future<void> updateSettings(ApiConnection connection, {
required Map<UserSettingName, Object?> newSettings,
}) {
final params = <String, Object?>{};
for (final entry in newSettings.entries) {
final name = entry.key;
final valueRaw = entry.value;
final value = switch (name) {
UserSettingName.twentyFourHourTime => valueRaw as bool,
UserSettingName.displayEmojiReactionUsers => valueRaw as bool,
UserSettingName.emojiset => RawParameter((valueRaw as Emojiset).toJson()),
UserSettingName.presenceEnabled => valueRaw as bool,
};
params[name.toJson()] = value;
}

return connection.patch('updateSettings', (_) {}, 'settings', params);
}
68 changes: 68 additions & 0 deletions lib/basic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

/// Either a value, or the absence of a value.
///
/// An `Option<T>` is either an `OptionSome` representing a `T` value,
/// or an `OptionNone` representing the absence of a value.
///
/// When `T` is non-nullable, this is the same information that is
/// normally represented as a `T?`.
/// This class is useful when T is nullable (or might be nullable).
/// In that case `null` is already a T value,
/// and so can't also be used to represent the absence of a T value,
/// but `OptionNone()` is a different value from `OptionSome(null)`.
///
/// This interface is small because members are added lazily when needed.
/// If adding another member, consider borrowing the naming from Rust:
/// https://doc.rust-lang.org/std/option/enum.Option.html
sealed class Option<T> {
const Option();

/// The value contained in this option, if any; else the given value.
T or(T optb);

/// The value contained in this option, if any;
/// else the value returned by [fn].
///
/// [fn] is called only if its return value is needed.
T orElse(T Function() fn);
}

class OptionNone<T> extends Option<T> {
const OptionNone();

@override
T or(T optb) => optb;

@override
T orElse(T Function() fn) => fn();

@override
bool operator ==(Object other) => other is OptionNone;

@override
int get hashCode => 'OptionNone'.hashCode;

@override
String toString() => 'OptionNone';
}

class OptionSome<T> extends Option<T> {
const OptionSome(this.value);

final T value;

@override
T or(T optb) => value;

@override
T orElse(T Function() fn) => value;

@override
bool operator ==(Object other) => other is OptionSome && value == other.value;

@override
int get hashCode => Object.hash('OptionSome', value);

@override
String toString() => 'OptionSome($value)';
}
18 changes: 18 additions & 0 deletions lib/generated/l10n/zulip_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,24 @@ abstract class ZulipLocalizations {
/// **'Yesterday'**
String get yesterday;

/// Label for the 'Invisible mode' switch on the profile page.
///
/// In en, this message translates to:
/// **'Invisible mode'**
String get invisibleMode;

/// Error title when turning on invisible mode failed.
///
/// In en, this message translates to:
/// **'Error turning on invisible mode. Please try again.'**
String get turnOnInvisibleModeErrorTitle;

/// Error title when turning off invisible mode failed.
///
/// In en, this message translates to:
/// **'Error turning off invisible mode. Please try again.'**
String get turnOffInvisibleModeErrorTitle;

/// Label for UserRole.owner
///
/// In en, this message translates to:
Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n/zulip_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,17 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
@override
String get yesterday => 'Yesterday';

@override
String get invisibleMode => 'Invisible mode';

@override
String get turnOnInvisibleModeErrorTitle =>
'Error turning on invisible mode. Please try again.';

@override
String get turnOffInvisibleModeErrorTitle =>
'Error turning off invisible mode. Please try again.';

@override
String get userRoleOwner => 'Owner';

Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n/zulip_localizations_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,17 @@ class ZulipLocalizationsDe extends ZulipLocalizations {
@override
String get yesterday => 'Gestern';

@override
String get invisibleMode => 'Invisible mode';

@override
String get turnOnInvisibleModeErrorTitle =>
'Error turning on invisible mode. Please try again.';

@override
String get turnOffInvisibleModeErrorTitle =>
'Error turning off invisible mode. Please try again.';

@override
String get userRoleOwner => 'Besitzer';

Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n/zulip_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,17 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
@override
String get yesterday => 'Yesterday';

@override
String get invisibleMode => 'Invisible mode';

@override
String get turnOnInvisibleModeErrorTitle =>
'Error turning on invisible mode. Please try again.';

@override
String get turnOffInvisibleModeErrorTitle =>
'Error turning off invisible mode. Please try again.';

@override
String get userRoleOwner => 'Owner';

Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n/zulip_localizations_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,17 @@ class ZulipLocalizationsIt extends ZulipLocalizations {
@override
String get yesterday => 'Ieri';

@override
String get invisibleMode => 'Invisible mode';

@override
String get turnOnInvisibleModeErrorTitle =>
'Error turning on invisible mode. Please try again.';

@override
String get turnOffInvisibleModeErrorTitle =>
'Error turning off invisible mode. Please try again.';

@override
String get userRoleOwner => 'Proprietario';

Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n/zulip_localizations_ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,17 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
@override
String get yesterday => 'Yesterday';

@override
String get invisibleMode => 'Invisible mode';

@override
String get turnOnInvisibleModeErrorTitle =>
'Error turning on invisible mode. Please try again.';

@override
String get turnOffInvisibleModeErrorTitle =>
'Error turning off invisible mode. Please try again.';

@override
String get userRoleOwner => 'オーナー';

Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n/zulip_localizations_nb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,17 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
@override
String get yesterday => 'Yesterday';

@override
String get invisibleMode => 'Invisible mode';

@override
String get turnOnInvisibleModeErrorTitle =>
'Error turning on invisible mode. Please try again.';

@override
String get turnOffInvisibleModeErrorTitle =>
'Error turning off invisible mode. Please try again.';

@override
String get userRoleOwner => 'Owner';

Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n/zulip_localizations_pl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,17 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
@override
String get yesterday => 'Wczoraj';

@override
String get invisibleMode => 'Invisible mode';

@override
String get turnOnInvisibleModeErrorTitle =>
'Error turning on invisible mode. Please try again.';

@override
String get turnOffInvisibleModeErrorTitle =>
'Error turning off invisible mode. Please try again.';

@override
String get userRoleOwner => 'Właściciel';

Expand Down
Loading