Check for Friendica version before trying to reshare Diaspora posts

codemagic-setup
Hank Grabowski 2023-03-23 10:51:41 -04:00
rodzic 1311cbb979
commit 7dbe520c73
5 zmienionych plików z 41 dodań i 6 usunięć

Wyświetl plik

@ -5,6 +5,7 @@
* Changes
* Uses "Sentence Capitalization" keyboard to have shift on for first letter of beginning of each
sentence.
* Add version error check messages on DM sending and Resharing Diaspora posts for pre-2023.03 Friendica servers
* Fixes
* New Features

Wyświetl plik

@ -135,6 +135,8 @@ wanted to lay out some expectations before getting into the small details
### Broken and hopefully fixed in the very near future:
* Sending direct messages only works if you are logged in with username/password due to limitations of the existing DM
API. (Fixed in Friendica 2023.03)
* Resharing of Diaspora federated posts is currently broken server side. All other posts should be
reshareable. (Fixed in Friendica 2023.03)
* Content Warnings/Spoiler Text on *posts* aren't federating over to Mastodon well so only use it on

Wyświetl plik

@ -36,6 +36,7 @@ enum ErrorType {
authentication,
localError,
missingEndpoint,
minVersionError,
notFound,
parsingError,
serverError,

Wyświetl plik

@ -1,5 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
import 'package:relatica/models/auth/oauth_credentials.dart';
import 'package:relatica/services/feature_version_checker.dart';
import 'package:result_monad/result_monad.dart';
import '../friendica_client/friendica_client.dart';
@ -63,9 +65,16 @@ class DirectMessageService extends ChangeNotifier {
FutureResult<DirectMessage, ExecError> newThread(
Connection receiver, String text) async {
final result =
await DirectMessagingClient(getIt<AccountsService>().currentProfile)
.postDirectMessage(
final profile = getIt<AccountsService>().currentProfile;
if (profile.credentials is OAuthCredentials) {
final result = getIt<FriendicaVersionChecker>()
.canUseFeatureResult(RelaticaFeatures.directMessageCreation);
if (result.isFailure) {
return result.errorCast();
}
}
final result = await DirectMessagingClient(profile).postDirectMessage(
null,
receiver.id,
text,
@ -103,9 +112,16 @@ class DirectMessageService extends ChangeNotifier {
);
}
final result =
await DirectMessagingClient(getIt<AccountsService>().currentProfile)
.postDirectMessage(
final profile = getIt<AccountsService>().currentProfile;
if (profile.credentials is OAuthCredentials) {
final result = getIt<FriendicaVersionChecker>()
.canUseFeatureResult(RelaticaFeatures.directMessageCreation);
if (result.isFailure) {
return result.errorCast();
}
}
final result = await DirectMessagingClient(profile).postDirectMessage(
original.id,
original.senderId,
text,

Wyświetl plik

@ -1,12 +1,15 @@
import 'package:logging/logging.dart';
import 'package:relatica/models/instance_info.dart';
import 'package:relatica/utils/active_profile_selector.dart';
import 'package:result_monad/result_monad.dart';
import '../globals.dart';
import '../models/exec_error.dart';
import '../models/friendica_version.dart';
enum RelaticaFeatures {
diasporaReshare('Resharing Diaspora Posts'),
directMessageCreation('Direct message creation with OAuth login'),
postSpoilerText('Spoiler Text on Posts'),
statusEditing('Post/Comment Editing'),
usingActualFollowRequests(
@ -47,6 +50,17 @@ class FriendicaVersionChecker {
);
}
Result<bool, ExecError> canUseFeatureResult(RelaticaFeatures feature) {
if (canUseFeature(feature)) {
return Result.ok(true);
}
return buildErrorResult(
type: ErrorType.minVersionError,
message: versionErrorString(feature),
);
}
FriendicaVersion getVersionRequirement(RelaticaFeatures feature) =>
featureVersionRequirement[feature] ?? unknown;
@ -55,6 +69,7 @@ class FriendicaVersionChecker {
static final featureVersionRequirement = <RelaticaFeatures, FriendicaVersion>{
RelaticaFeatures.diasporaReshare: v2023_03,
RelaticaFeatures.directMessageCreation: v2023_03,
RelaticaFeatures.postSpoilerText: v2023_03,
RelaticaFeatures.statusEditing: v2023_03,
RelaticaFeatures.usingActualFollowRequests: v2023_03,