kopia lustrzana https://gitlab.com/mysocialportal/relatica
Move reshareable logic to extension method w/network prohibitions hardcoded
rodzic
f6402c5422
commit
ad1b557dad
|
@ -1,16 +1,16 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:relatica/models/exec_error.dart';
|
||||
import 'package:result_monad/result_monad.dart';
|
||||
|
||||
import '../../globals.dart';
|
||||
import '../../models/exec_error.dart';
|
||||
import '../../models/timeline_entry.dart';
|
||||
import '../../models/visibility.dart' as v;
|
||||
import '../../services/feature_version_checker.dart';
|
||||
import '../../services/fediverse_server_validator.dart';
|
||||
import '../../services/timeline_manager.dart';
|
||||
import '../../utils/active_profile_selector.dart';
|
||||
import '../../utils/interaction_availability_util.dart';
|
||||
import '../../utils/snackbar_builder.dart';
|
||||
|
||||
class InteractionsBarControl extends StatefulWidget {
|
||||
|
@ -181,19 +181,13 @@ class _InteractionsBarControlState extends State<InteractionsBarControl> {
|
|||
}
|
||||
|
||||
Widget buildReshareButton() {
|
||||
final canReshare = !widget.isMine &&
|
||||
widget.entry.visibility.type == v.VisibilityType.public;
|
||||
final reshareable = widget.entry.getIsReshareable(widget.isMine);
|
||||
final canReshare = reshareable.isReshareable == Reshareable.yes;
|
||||
late final String tooltip;
|
||||
if (canReshare) {
|
||||
tooltip = youReshared ? 'Press to undo reshare' : 'Press to reshare';
|
||||
} else {
|
||||
if (widget.isMine) {
|
||||
tooltip = "Can't reshare your own post";
|
||||
} else if (widget.entry.visibility.type != v.VisibilityType.public) {
|
||||
tooltip = "Can't reshare a private post";
|
||||
} else {
|
||||
tooltip = "Can't reshare at this time";
|
||||
}
|
||||
tooltip = reshareable.reason;
|
||||
}
|
||||
return buildButton(
|
||||
youReshared ? Icons.repeat_on_outlined : Icons.repeat,
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import 'package:relatica/models/timeline_entry.dart';
|
||||
import 'package:relatica/models/timeline_network_info.dart';
|
||||
|
||||
import '../models/visibility.dart';
|
||||
|
||||
enum Reshareable {
|
||||
no,
|
||||
yes,
|
||||
}
|
||||
|
||||
class ReshareableResult {
|
||||
final Reshareable isReshareable;
|
||||
final String reason;
|
||||
|
||||
const ReshareableResult({required this.isReshareable, required this.reason});
|
||||
}
|
||||
|
||||
extension InteractionAvailabilityExtension on TimelineEntry {
|
||||
ReshareableResult getIsReshareable(bool isMine) {
|
||||
if (isMine) {
|
||||
return const ReshareableResult(
|
||||
isReshareable: Reshareable.no,
|
||||
reason: "Can't reshare your own post",
|
||||
);
|
||||
}
|
||||
|
||||
if (networkInfo.network == KnownNetworks.threads) {
|
||||
return const ReshareableResult(
|
||||
isReshareable: Reshareable.no,
|
||||
reason: "You have requested to not allow resharing of Threads posts.",
|
||||
);
|
||||
}
|
||||
|
||||
if (networkInfo.network == KnownNetworks.bluesky) {
|
||||
return const ReshareableResult(
|
||||
isReshareable: Reshareable.no,
|
||||
reason:
|
||||
"Resharing of Bluesky posts through the API isn't supported by Friendica.",
|
||||
);
|
||||
}
|
||||
|
||||
if (visibility.type == VisibilityType.public ||
|
||||
visibility.type == VisibilityType.unlisted) {
|
||||
return const ReshareableResult(
|
||||
isReshareable: Reshareable.yes,
|
||||
reason: "Can reshare post",
|
||||
);
|
||||
}
|
||||
|
||||
return const ReshareableResult(
|
||||
isReshareable: Reshareable.no,
|
||||
reason: "Can't reshare private posts",
|
||||
);
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue