Skip to content

Commit

Permalink
add websockets updates settings in timeline settings
Browse files Browse the repository at this point in the history
  • Loading branch information
xal committed Oct 4, 2020
1 parent ab7583a commit 3166d82
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 16 deletions.
6 changes: 6 additions & 0 deletions assets/langs/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,12 @@
"only_remote": {
"label": "Only remote"
},
"web_sockets_updates": {
"label": "WebSockets updates",
"disabled": {
"desc": "WebSockets disabled in account settings"
}
},
"only_local": {
"label": "Only local"
},
Expand Down
6 changes: 6 additions & 0 deletions lib/app/localization/localization_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ class CodegenLoader extends AssetLoader{
"only_remote": {
"label": "Only remote"
},
"web_sockets_updates": {
"label": "WebSockets updates",
"disabled": {
"desc": "WebSockets disabled in account settings"
}
},
"only_local": {
"label": "Only local"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:fedi/app/account/my/settings/my_account_settings_local_preference_bloc.dart';
import 'package:fedi/app/auth/instance/auth_instance_model.dart';
import 'package:fedi/app/timeline/timeline_model.dart';
import 'package:flutter/cupertino.dart';


extension TimelineRemoteTypeFilterSupportExtension on TimelineType {
Expand Down Expand Up @@ -53,6 +55,10 @@ extension TimelineRemoteTypeFilterSupportExtension on TimelineType {
// require additional pagination handling
return false;
}
bool isWebSocketsUpdatesFilterSupportedOnInstance(BuildContext context) {
var myAccountSettingsLocalPreferenceBloc = IMyAccountSettingsLocalPreferenceBloc.of(context, listen: false);
return myAccountSettingsLocalPreferenceBloc.value?.isRealtimeWebSocketsEnabled ?? true;
}

bool isOnlyRemoteFilterSupportedOnInstance(AuthInstance authInstance) {
switch (this) {
Expand Down
2 changes: 2 additions & 0 deletions lib/app/timeline/settings/timeline_settings_form_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ abstract class ITimelineSettingsFormBloc extends IFormBloc {

FormListValueFieldBloc<PleromaVisibility> get excludeVisibilitiesFieldBloc;

IFormBoolFieldBloc get webSocketsUpdatesFieldBloc;

void fill({
@required TimelineType type,
@required TimelineSettings newSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class TimelineSettingsFormBloc extends FormBloc
@override
FormListValueFieldBloc<PleromaVisibility> excludeVisibilitiesFieldBloc;

@override
final IFormBoolFieldBloc webSocketsUpdatesFieldBloc;

TimelineType type;

TimelineSettingsFormBloc({
Expand Down Expand Up @@ -127,8 +130,9 @@ class TimelineSettingsFormBloc extends FormBloc
originValue: originalSettings?.replyVisibilityFilter,
validators: []),
excludeVisibilitiesFieldBloc = FormListValueFieldBloc(
originValue: originalSettings?.excludeVisibilities,
validators: []) {
originValue: originalSettings?.excludeVisibilities, validators: []),
webSocketsUpdatesFieldBloc = FormBoolFieldBloc(
originValue: originalSettings?.webSocketsUpdates ?? true) {
addDisposable(subject: _timelineSettingsSubject);

addDisposable(disposable: excludeRepliesFieldBloc);
Expand Down Expand Up @@ -215,6 +219,7 @@ class TimelineSettingsFormBloc extends FormBloc
onlyFromRemoteAccount: onlyFromRemoteAccountFieldBloc.currentValue,
excludeReblogs: excludeReblogsFieldBloc.currentValue,
onlyPinned: onlyPinnedFieldBloc.currentValue,
webSocketsUpdates: webSocketsUpdatesFieldBloc.currentValue
);
if (newPreferences != oldPreferences) {
_timelineSettingsSubject.add(newPreferences);
Expand Down
32 changes: 28 additions & 4 deletions lib/app/timeline/settings/timeline_settings_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class TimelineSettings extends IPreferencesObject {
onlyLocal: false,
withMuted: false,
excludeVisibilities: [],
websocketsUpdates: true,
);

static TimelineSettings createDefaultHomeSettings() => TimelineSettings.home(
onlyLocal: false,
withMuted: false,
excludeVisibilities: [],
websocketsUpdates: true,
);

static TimelineSettings createDefaultCustomListSettings({
Expand All @@ -41,6 +43,7 @@ class TimelineSettings extends IPreferencesObject {
withMuted: false,
excludeVisibilities: [],
onlyInRemoteList: onlyInRemoteList,
websocketsUpdates: true,
);

static TimelineSettings createDefaultHashtagSettings({
Expand All @@ -52,6 +55,7 @@ class TimelineSettings extends IPreferencesObject {
withMuted: false,
excludeVisibilities: [],
withRemoteHashtag: withRemoteHashtag,
websocketsUpdates: true,
);

static TimelineSettings createDefaultAccountSettings({
Expand All @@ -63,6 +67,7 @@ class TimelineSettings extends IPreferencesObject {
excludeReplies: false,
onlyPinned: false,
onlyFromRemoteAccount: onlyFromRemoteAccount,
websocketsUpdates: true,
);

@HiveField(1)
Expand Down Expand Up @@ -117,6 +122,10 @@ class TimelineSettings extends IPreferencesObject {
@JsonKey(name: "exclude_reblogs")
final bool excludeReblogs;

@HiveField(16)
@JsonKey(name: "web_sockets_updates")
final bool webSocketsUpdates;

TimelineSettings({
@required this.onlyWithMedia,
@required this.excludeReplies,
Expand All @@ -131,12 +140,14 @@ class TimelineSettings extends IPreferencesObject {
@required this.onlyFromRemoteAccount,
@required this.onlyPinned,
@required this.excludeReblogs,
@required this.webSocketsUpdates,
});

TimelineSettings.home({
@required bool onlyLocal,
@required bool withMuted,
@required List<PleromaVisibility> excludeVisibilities,
@required bool websocketsUpdates,
}) : this(
onlyWithMedia: null,
excludeReplies: null,
Expand All @@ -153,6 +164,7 @@ class TimelineSettings extends IPreferencesObject {
onlyFromRemoteAccount: null,
onlyPinned: null,
excludeReblogs: null,
webSocketsUpdates: websocketsUpdates,
);

TimelineSettings.public({
Expand All @@ -161,6 +173,7 @@ class TimelineSettings extends IPreferencesObject {
@required bool onlyLocal,
@required bool withMuted,
@required List<PleromaVisibility> excludeVisibilities,
@required bool websocketsUpdates,
}) : this(
onlyWithMedia: onlyWithMedia,
excludeReplies: null,
Expand All @@ -177,6 +190,7 @@ class TimelineSettings extends IPreferencesObject {
onlyFromRemoteAccount: null,
onlyPinned: null,
excludeReblogs: null,
webSocketsUpdates: websocketsUpdates,
);

TimelineSettings.hashtag({
Expand All @@ -185,6 +199,7 @@ class TimelineSettings extends IPreferencesObject {
@required bool withMuted,
@required List<PleromaVisibility> excludeVisibilities,
@required String withRemoteHashtag,
@required bool websocketsUpdates,
}) : this(
onlyWithMedia: onlyWithMedia,
excludeReplies: null,
Expand All @@ -201,12 +216,14 @@ class TimelineSettings extends IPreferencesObject {
onlyFromRemoteAccount: null,
onlyPinned: null,
excludeReblogs: null,
webSocketsUpdates: websocketsUpdates,
);

TimelineSettings.list({
@required bool withMuted,
@required List<PleromaVisibility> excludeVisibilities,
@required IPleromaList onlyInRemoteList,
@required bool websocketsUpdates,
}) : this(
onlyWithMedia: null,
excludeReplies: null,
Expand All @@ -223,6 +240,7 @@ class TimelineSettings extends IPreferencesObject {
onlyFromRemoteAccount: null,
onlyPinned: null,
excludeReblogs: null,
webSocketsUpdates: websocketsUpdates,
);

TimelineSettings.account({
Expand All @@ -231,6 +249,7 @@ class TimelineSettings extends IPreferencesObject {
@required bool excludeReplies,
@required bool excludeReblogs,
@required bool onlyPinned,
@required bool websocketsUpdates,
}) : this(
onlyWithMedia: onlyWithMedia,
excludeReplies: excludeReplies,
Expand All @@ -245,6 +264,7 @@ class TimelineSettings extends IPreferencesObject {
onlyFromRemoteAccount: onlyFromRemoteAccount,
onlyPinned: onlyPinned,
excludeReblogs: excludeReblogs,
webSocketsUpdates: websocketsUpdates,
);

TimelineSettings copyWith({
Expand All @@ -260,8 +280,9 @@ class TimelineSettings extends IPreferencesObject {
PleromaTag withRemoteHashtag,
String replyVisibilityFilterString,
PleromaAccount onlyFromRemoteAccount,
bool excludeReblogs,
bool onlyPinned,
bool excludeReblogs,
bool webSocketsUpdates,
}) =>
TimelineSettings(
onlyWithMedia: onlyWithMedia ?? this.onlyWithMedia,
Expand All @@ -278,11 +299,11 @@ class TimelineSettings extends IPreferencesObject {
replyVisibilityFilterString ?? this.replyVisibilityFilterString,
onlyFromRemoteAccount:
onlyFromRemoteAccount ?? this.onlyFromRemoteAccount,
excludeReblogs: excludeReblogs ?? this.excludeReblogs,
onlyPinned: onlyPinned ?? this.onlyPinned,
excludeReblogs: excludeReblogs ?? this.excludeReblogs,
webSocketsUpdates: webSocketsUpdates ?? this.webSocketsUpdates,
);


@override
bool operator ==(Object other) =>
identical(this, other) ||
Expand All @@ -300,7 +321,8 @@ class TimelineSettings extends IPreferencesObject {
replyVisibilityFilterString == other.replyVisibilityFilterString &&
onlyFromRemoteAccount == other.onlyFromRemoteAccount &&
onlyPinned == other.onlyPinned &&
excludeReblogs == other.excludeReblogs;
excludeReblogs == other.excludeReblogs &&
webSocketsUpdates == other.webSocketsUpdates;

@override
int get hashCode =>
Expand All @@ -316,6 +338,7 @@ class TimelineSettings extends IPreferencesObject {
replyVisibilityFilterString.hashCode ^
onlyFromRemoteAccount.hashCode ^
onlyPinned.hashCode ^
webSocketsUpdates.hashCode ^
excludeReblogs.hashCode;

@override
Expand All @@ -332,6 +355,7 @@ class TimelineSettings extends IPreferencesObject {
' PleromaReplyVisibilityFilterString:'
' $replyVisibilityFilterString,'
' onlyFromAccountWithRemoteId: $onlyFromRemoteAccount,'
' websocketsUpdates: $webSocketsUpdates,'
' onlyPinned: $onlyPinned, excludeReblogs: $excludeReblogs}';
}

Expand Down
9 changes: 7 additions & 2 deletions lib/app/timeline/settings/timeline_settings_model.g.dart

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

22 changes: 21 additions & 1 deletion lib/app/timeline/settings/timeline_settings_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TimelineSettingsWidget extends StatelessWidget {
buildWithMutedField(context, settingsBloc, authInstance),
buildOnlyMediaField(context, settingsBloc, authInstance),
buildOnlyLocalField(context, settingsBloc, authInstance),
buildWebSocketsUpdatesField(context, settingsBloc, authInstance),
buildReplyVisibilityFilterField(context, settingsBloc, authInstance),
];
break;
Expand All @@ -48,6 +49,7 @@ class TimelineSettingsWidget extends StatelessWidget {
buildOnlyMediaField(context, settingsBloc, authInstance),
buildOnlyLocalField(context, settingsBloc, authInstance),
buildOnlyRemoteField(context, settingsBloc, authInstance),
buildWebSocketsUpdatesField(context, settingsBloc, authInstance),
buildReplyVisibilityFilterField(context, settingsBloc, authInstance),
];
break;
Expand All @@ -56,6 +58,7 @@ class TimelineSettingsWidget extends StatelessWidget {
buildCustomListField(context, settingsBloc, authInstance),
buildWithMutedField(context, settingsBloc, authInstance),
buildOnlyMediaField(context, settingsBloc, authInstance),
buildWebSocketsUpdatesField(context, settingsBloc, authInstance),
];
break;

Expand All @@ -65,6 +68,7 @@ class TimelineSettingsWidget extends StatelessWidget {
buildWithMutedField(context, settingsBloc, authInstance),
buildOnlyMediaField(context, settingsBloc, authInstance),
buildOnlyLocalField(context, settingsBloc, authInstance),
buildWebSocketsUpdatesField(context, settingsBloc, authInstance),
];
break;
case TimelineType.account:
Expand All @@ -74,6 +78,7 @@ class TimelineSettingsWidget extends StatelessWidget {
buildOnlyPinnedField(context, settingsBloc, authInstance),
buildExcludeReblogsField(context, settingsBloc, authInstance),
buildExcludeRepliesField(context, settingsBloc, authInstance),
buildWebSocketsUpdatesField(context, settingsBloc, authInstance),
buildHashtagField(context, settingsBloc, authInstance),
];
break;
Expand Down Expand Up @@ -171,6 +176,20 @@ class TimelineSettingsWidget extends StatelessWidget {
);
}

FormBoolFieldFormRowWidget buildWebSocketsUpdatesField(
BuildContext context,
ITimelineSettingsFormBloc settingsBloc,
AuthInstance authInstance,
) {
return buildBoolField(
label: tr("app.timeline.settings.field.web_sockets_updates.label"),
fieldBloc: settingsBloc.webSocketsUpdatesFieldBloc,
isSupported: type.isWebSocketsUpdatesFilterSupportedOnInstance(context),
errorDesc:
tr("app.timeline.settings.field.web_sockets_updates.disabled.desc"),
);
}

FormBoolFieldFormRowWidget buildExcludeNsfwField(
BuildContext context,
ITimelineSettingsFormBloc settingsBloc,
Expand Down Expand Up @@ -261,14 +280,15 @@ class TimelineSettingsWidget extends StatelessWidget {
@required String label,
@required IFormBoolFieldBloc fieldBloc,
@required bool isSupported,
String errorDesc,
}) {
return FormBoolFieldFormRowWidget(
label: label,
field: fieldBloc,
enabled: isSupported,
desc: isSupported
? null
: "app.timeline.settings.field.not_supported.desc".tr(),
: errorDesc ?? "app.timeline.settings.field.not_supported.desc".tr(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TimelineStatusCachedListBloc extends DisposableOwner
@required this.webSocketsHandlerManagerBloc,
}) {
// todo: rework listen, due to settings change
if (listenWebSockets) {
if (listenWebSockets && (timeline.webSocketsUpdates ?? true)) {
switch (timelineType) {
case TimelineType.public:
addDisposable(
Expand Down
Loading

0 comments on commit 3166d82

Please sign in to comment.