2024-11-22 20:19:11 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
2024-12-10 11:54:45 +00:00
|
|
|
import '../models/auth/profile.dart';
|
2024-06-26 18:58:02 +00:00
|
|
|
import '../models/timeline_entry.dart';
|
|
|
|
import '../models/timeline_network_info.dart';
|
2024-06-26 13:52:31 +00:00
|
|
|
import '../models/visibility.dart';
|
2024-12-10 11:54:45 +00:00
|
|
|
import '../riverpod_controllers/feature_checker_services.dart';
|
2024-11-22 20:19:11 +00:00
|
|
|
import '../riverpod_controllers/settings_services.dart';
|
2024-06-26 18:58:02 +00:00
|
|
|
import 'known_network_extensions.dart';
|
2024-06-26 13:52:31 +00:00
|
|
|
|
2024-06-26 19:11:58 +00:00
|
|
|
class InteractionCapabilityResult {
|
|
|
|
final bool canDo;
|
2024-06-26 13:52:31 +00:00
|
|
|
final String reason;
|
|
|
|
|
2024-06-26 19:11:58 +00:00
|
|
|
const InteractionCapabilityResult(
|
|
|
|
{required this.canDo, required this.reason});
|
2024-06-26 13:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension InteractionAvailabilityExtension on TimelineEntry {
|
2024-11-22 20:19:11 +00:00
|
|
|
InteractionCapabilityResult getCanComment(WidgetRef ref) {
|
|
|
|
final nc = ref
|
|
|
|
.read(networkCapabilitiesSettingProvider)
|
2024-06-26 19:11:58 +00:00
|
|
|
.getCapabilities(networkInfo.network);
|
|
|
|
|
|
|
|
if (!nc.comment) {
|
|
|
|
return InteractionCapabilityResult(
|
|
|
|
canDo: false,
|
|
|
|
reason:
|
|
|
|
"User disabled commenting on ${networkInfo.network.labelName} items. Go into settings to change.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-26 19:14:05 +00:00
|
|
|
return const InteractionCapabilityResult(
|
2024-06-26 19:11:58 +00:00
|
|
|
canDo: true,
|
|
|
|
reason: "Can comment on item",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-11-22 20:19:11 +00:00
|
|
|
InteractionCapabilityResult getCanReact(WidgetRef ref) {
|
|
|
|
final nc = ref
|
|
|
|
.read(networkCapabilitiesSettingProvider)
|
2024-06-26 19:14:05 +00:00
|
|
|
.getCapabilities(networkInfo.network);
|
|
|
|
|
|
|
|
if (!nc.react) {
|
|
|
|
return InteractionCapabilityResult(
|
|
|
|
canDo: false,
|
|
|
|
reason:
|
|
|
|
"User disabled reacting on ${networkInfo.network.labelName} items. Go into settings to change.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return const InteractionCapabilityResult(
|
|
|
|
canDo: true,
|
|
|
|
reason: "Can react on item",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-10 11:54:45 +00:00
|
|
|
InteractionCapabilityResult getIsReshareable(
|
|
|
|
WidgetRef ref, Profile profile, bool isMine) {
|
2024-06-26 13:52:31 +00:00
|
|
|
if (isMine) {
|
2024-06-26 19:11:58 +00:00
|
|
|
return const InteractionCapabilityResult(
|
|
|
|
canDo: false,
|
2024-06-26 13:52:31 +00:00
|
|
|
reason: "Can't reshare your own post",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-26 18:58:02 +00:00
|
|
|
if (networkInfo.network == KnownNetworks.bluesky) {
|
2024-12-10 11:54:45 +00:00
|
|
|
final result = ref.read(
|
|
|
|
featureCheckResultProvider(profile, RelaticaFeatures.blueskyReshare));
|
2024-08-31 02:25:13 +00:00
|
|
|
|
|
|
|
if (result.isFailure) {
|
|
|
|
return InteractionCapabilityResult(
|
|
|
|
canDo: false,
|
|
|
|
reason: result.error.message,
|
|
|
|
);
|
|
|
|
}
|
2024-06-26 13:52:31 +00:00
|
|
|
}
|
|
|
|
|
2024-11-22 20:19:11 +00:00
|
|
|
final nc = ref
|
|
|
|
.read(networkCapabilitiesSettingProvider)
|
2024-06-26 18:58:02 +00:00
|
|
|
.getCapabilities(networkInfo.network);
|
|
|
|
|
|
|
|
if (!nc.reshare) {
|
2024-06-26 19:11:58 +00:00
|
|
|
return InteractionCapabilityResult(
|
|
|
|
canDo: false,
|
2024-06-26 13:52:31 +00:00
|
|
|
reason:
|
2024-06-26 19:11:58 +00:00
|
|
|
"User disabled resharing ${networkInfo.network.labelName} items. Go into settings to change.",
|
2024-06-26 13:52:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibility.type == VisibilityType.public ||
|
|
|
|
visibility.type == VisibilityType.unlisted) {
|
2024-06-26 19:11:58 +00:00
|
|
|
return const InteractionCapabilityResult(
|
|
|
|
canDo: true,
|
|
|
|
reason: "Can reshare item",
|
2024-06-26 13:52:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-26 19:11:58 +00:00
|
|
|
return const InteractionCapabilityResult(
|
|
|
|
canDo: false,
|
|
|
|
reason: "Can't reshare private items",
|
2024-06-26 13:52:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|