Skip to content

Commit

Permalink
chore: improved codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
harljo committed Apr 9, 2024
1 parent 3aa8e14 commit c3ac345
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 175 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.21"
}

ext.abiCodes = ["x86_64": 1, "armeabi-v7a": 2, "arm64-v8a": 3]
ext.abiCodes = ["x86_64": 3, "armeabi-v7a": 6, "arm64-v8a": 9]
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def abiVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
Expand Down
25 changes: 10 additions & 15 deletions lib/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class _FritterTwitterClient extends TwitterClient {
if (response.statusCode >= 200 && response.statusCode < 300) {
return response;
} else {
print(response.reasonPhrase);
return Future.error(HttpException(response.reasonPhrase ?? response.statusCode.toString()));
}
});
Expand All @@ -47,6 +46,7 @@ class _FritterTwitterClient extends TwitterClient {
log.info('Fetching $uri');

var prefs = await PrefServiceShared.init(prefix: 'pref_');

WebFlowAuthModel webFlowAuthModel = WebFlowAuthModel(prefs);
var authHeader = await webFlowAuthModel.GetAuthHeader(userAgentHeader);
var response = await http.get(uri, headers: {
Expand Down Expand Up @@ -249,11 +249,12 @@ class Twitter {
for (var entry in addEntries) {
var entryId = entry['entryId'] as String;
if (entryId.startsWith('tweet-')) {
var result;
if (entry['content']['itemContent']['tweet_results']['result']["__typename"] == "TweetWithVisibilityResults")
dynamic result;
if (entry['content']['itemContent']['tweet_results']['result']["__typename"] == "TweetWithVisibilityResults") {
result = entry['content']['itemContent']['tweet_results']['result']['tweet'];
else
} else {
result = entry['content']['itemContent']['tweet_results']['result'];
}

if (result != null) {
replies
Expand Down Expand Up @@ -375,7 +376,7 @@ class Twitter {
var rootTweet = chains.first;
chains.remove(rootTweet);
chains.sort((a, b) {
return b.id!.compareTo(a.id!);
return b.id.compareTo(a.id);
});
chains.insert(0, rootTweet);

Expand All @@ -397,7 +398,7 @@ class Twitter {
"withReactionsPerspective": false
};

var _features = {
var features = {
"responsive_web_graphql_exclude_directive_enabled": true,
"verified_phone_label_enabled": false,
"creator_subscriptions_tweet_preview_api_enabled": true,
Expand Down Expand Up @@ -425,7 +426,7 @@ class Twitter {
}

var uri = Uri.https('twitter.com', '/i/api/graphql/flaR-PUMshxFWZWPNpq4zA/SearchTimeline',
{'variables': jsonEncode(variables), 'features': jsonEncode(_features)});
{'variables': jsonEncode(variables), 'features': jsonEncode(features)});

var response = await _twitterApi.client.get(uri);
var result = json.decode(response.body);
Expand Down Expand Up @@ -542,12 +543,6 @@ class Twitter {
required void Function() incrementTweetsCounter,
}) async {
bool showPinnedTweet = true;
var query = {
...defaultParams,
'include_tweet_replies': includeReplies ? '1' : '0',
'include_want_retweets': includeRetweets ? '1' : '0', // This may not actually do anything
'count': count.toString(),
};
Map<String, Object> defaultUserTweetsParam = {
"variables":
"{\"userId\":\"160534877\",\"count\":20,\"includePromotedContent\":true,\"withQuickPromoteEligibilityTweetFields\":true,\"withVoice\":true,\"withV2Timeline\":true}",
Expand Down Expand Up @@ -759,7 +754,7 @@ class Twitter {
// Order all the conversations by newest first (assuming the ID is an incrementing key),
// and create a chain from them
chains.sort((a, b) {
return b.id!.compareTo(a.id!);
return b.id.compareTo(a.id);
});

//If we want to show pinned tweets, add them before the others that we already have
Expand Down Expand Up @@ -810,7 +805,7 @@ class Twitter {
// Order all the conversations by newest first (assuming the ID is an incrementing key),
// and create a chain from them
chains.sort((a, b) {
return b.id!.compareTo(a.id!);
return b.id.compareTo(a.id);
});

//If we want to show pinned tweets, add them before the others that we already have
Expand Down
14 changes: 4 additions & 10 deletions lib/client/regularAccount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:pref/pref.dart';
import 'package:quacker/ui/errors.dart';

import '../constants.dart';

Expand Down Expand Up @@ -64,7 +63,6 @@ class WebFlowAuthModel extends ChangeNotifier {
}

Future<String?> GetGT(Map<String, String> userAgentHeader) async {
Map<String, String> result = new Map<String, String>();
var request = http.Request("Get", Uri.parse('https://twitter.com/i/flow/login'))..followRedirects = false;
request.headers.addAll(userAgentHeader);
request.headers.addAll({"Host": "twitter.com"});
Expand Down Expand Up @@ -363,18 +361,17 @@ class WebFlowAuthModel extends ChangeNotifier {
var response = await client.send(request);

if (response.statusCode == 200) {
final stringData = await response.stream.transform(utf8.decoder).join();
var responseHeader = response.headers.toString();
final expAuthToken = RegExp(r'(auth_token=(.+?));');
RegExpMatch? matchAuthToken = expAuthToken.firstMatch(responseHeader);
auth_token = matchAuthToken!.group(2).toString();
var auth_token_Coookie = matchAuthToken!.group(1).toString();
var auth_token_Coookie = matchAuthToken.group(1).toString();
cookies.add(auth_token_Coookie);
GetAuthTokenLimits(responseHeader);
final expCt0 = RegExp(r'(ct0=(.+?));');
RegExpMatch? matchCt0 = expCt0.firstMatch(responseHeader);
csrf_token = matchCt0!.group(2).toString();
var csrf_token_Coookie = matchCt0!.group(1).toString();
var csrf_token_Coookie = matchCt0.group(1).toString();
cookies.add(csrf_token_Coookie);

if (kdt_Coookie == null) {
Expand Down Expand Up @@ -426,7 +423,7 @@ class WebFlowAuthModel extends ChangeNotifier {
//log.info('Refreshing the Twitter token');
}

Future<void> GetAuthTokenFromPref() async {
Future<void> getAuthTokenFromPref() async {
if (_expiresAt == -1) _expiresAt = await GetTokenExpires();
if (_tokenRemaining == -1) _tokenRemaining = await GetTokenRemaining();
if (_tokenLimit == -1) _tokenLimit = await GetTokenLimit();
Expand Down Expand Up @@ -463,7 +460,7 @@ class WebFlowAuthModel extends ChangeNotifier {
Future<Map<dynamic, dynamic>> GetAuthHeader(Map<String, String> userAgentHeader,
{String? authCode, BuildContext? context}) async {
try {
if (_authHeader == null) await GetAuthTokenFromPref();
if (_authHeader == null) await getAuthTokenFromPref();
if (!await IsTokenExpired()) return _authHeader!;
await GetGuestId(userAgentHeader);
await GetGT(userAgentHeader);
Expand Down Expand Up @@ -527,7 +524,6 @@ class WebFlowAuthModel extends ChangeNotifier {

Future<int> GetTokenExpires() async {
return prefs.get("auth_expiresAt") ?? -1;
;
}

Future DeleteTokenExpires() async {
Expand All @@ -540,7 +536,6 @@ class WebFlowAuthModel extends ChangeNotifier {

Future<int> GetTokenRemaining() async {
return prefs.get("auth_tokenRemaining") ?? -1;
;
}

Future DeleteTokenRemaining() async {
Expand All @@ -553,7 +548,6 @@ class WebFlowAuthModel extends ChangeNotifier {

Future<int> GetTokenLimit() async {
return prefs.get("auth_tokenLimit") ?? -1;
;
}

Future DeleteTokenLimit() async {
Expand Down
7 changes: 2 additions & 5 deletions lib/group/_settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_triple/flutter_triple.dart';
import 'package:pref/pref.dart';
import 'package:quacker/database/entities.dart';
import 'package:quacker/generated/l10n.dart';
import 'package:quacker/group/group_model.dart';
Expand All @@ -9,8 +8,6 @@ void showFeedSettings(BuildContext context, GroupModel model) {
showModalBottomSheet(
context: context,
builder: (context) {
var theme = Theme.of(context);

return Column(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down Expand Up @@ -45,15 +42,15 @@ void showFeedSettings(BuildContext context, GroupModel model) {
),
value: model.state.includeReplies,
onChanged: (value) async {
await model.toggleSubscriptionGroupIncludeReplies(value ?? false);
await model.toggleSubscriptionGroupIncludeReplies(value);
}),
SwitchListTile(
title: Text(
L10n.of(context).include_retweets,
),
value: model.state.includeRetweets,
onChanged: (value) async {
await model.toggleSubscriptionGroupIncludeRetweets(value ?? false);
await model.toggleSubscriptionGroupIncludeRetweets(value);
}),
],
);
Expand Down
1 change: 0 additions & 1 deletion lib/home/_feed.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pref/pref.dart';
import 'package:provider/provider.dart';
import 'package:quacker/constants.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:quacker/constants.dart';
import 'package:quacker/generated/l10n.dart';
import 'package:quacker/group/group_screen.dart';
import 'package:quacker/home/_feed.dart';
import 'package:quacker/home/_groups.dart';
import 'package:quacker/home/_missing.dart';
import 'package:quacker/home/_saved.dart';
import 'package:quacker/home/home_model.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import 'package:quacker/settings/_home.dart';
import 'package:quacker/settings/settings.dart';
import 'package:quacker/settings/settings_export_screen.dart';
import 'package:quacker/status.dart';
import 'package:quacker/subscriptions/_import.dart';
import 'package:quacker/subscriptions/users_model.dart';
import 'package:quacker/trends/trends_model.dart';
import 'package:quacker/tweet/_video.dart';
Expand Down Expand Up @@ -515,6 +514,7 @@ class _DefaultPageState extends State<DefaultPage> {
_migrationError = e;
_migrationStackTrace = s;
});
return e;
});

getInitialUri().then((link) {
Expand Down
2 changes: 0 additions & 2 deletions lib/profile/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import 'package:measure_size/measure_size.dart';
import 'package:pref/pref.dart';
import 'package:provider/provider.dart';

import '../settings/_account.dart';

class ProfileScreenArguments {
final String? id;
final String? screenName;
Expand Down
99 changes: 55 additions & 44 deletions lib/settings/_about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,64 @@ class SettingsAboutFragment extends StatelessWidget {
Future<void> _appInfo(BuildContext context) async {
var deviceInfo = DeviceInfoPlugin();
var packageInfo = await PackageInfo.fromPlatform();
var prefService = PrefService.of(context);
Map<String, Object> metadata;
Map<String, Object>? metadata;

if (Platform.isAndroid) {
if (Platform.isAndroid && context.mounted) {
var info = await deviceInfo.androidInfo;

metadata = {
'abis': info.supportedAbis,
'device': info.device,
'flavor': String.fromEnvironment('app.flavor') != '' ? String.fromEnvironment('app.flavor') : 'fdroid',
'locale': Localizations.localeOf(context).languageCode,
'os': 'android',
'system': info.version.sdkInt.toString(),
'version': packageInfo.buildNumber,
};
if (context.mounted) {
metadata = {
'abis': info.supportedAbis,
'device': info.device,
'flavor':
const String.fromEnvironment('app.flavor') != '' ? const String.fromEnvironment('app.flavor') : 'fdroid',
'locale': Localizations.localeOf(context).languageCode,
'os': 'android',
'system': info.version.sdkInt.toString(),
'version': packageInfo.buildNumber,
};
}
} else {
var info = await deviceInfo.iosInfo;

metadata = {
'abis': [],
'device': info.utsname.machine,
'flavor': String.fromEnvironment('app.flavor') != '' ? String.fromEnvironment('app.flavor') : 'fdroid',
'locale': Localizations.localeOf(context).languageCode,
'os': 'ios',
'system': info.systemVersion,
'version': packageInfo.buildNumber,
};
}
if (context.mounted) {
metadata = {
'abis': [],
'device': info.utsname.machine,
'flavor': String.fromEnvironment('app.flavor') != '' ? String.fromEnvironment('app.flavor') : 'fdroid',
'locale': Localizations.localeOf(context).languageCode,
'os': 'ios',
'system': info.systemVersion,
'version': packageInfo.buildNumber,
};
}

showDialog(
context: context,
builder: (context) {
var content = JsonEncoder.withIndent(' ' * 2).convert(metadata);
if (context.mounted) {
showDialog(
context: context,
builder: (context) {
var content = JsonEncoder.withIndent(' ' * 2).convert(metadata);

return AlertDialog(
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(L10n.of(context).ok)),
],
title: Text(L10n.of(context).app_info),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [const SizedBox(height: 16), Text(content, style: const TextStyle(fontFamily: 'monospace'))],
));
});
return AlertDialog(
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(L10n.of(context).ok)),
],
title: Text(L10n.of(context).app_info),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 16),
Text(content, style: const TextStyle(fontFamily: 'monospace'))
],
));
});
}
}
}

@override
Expand All @@ -80,9 +89,11 @@ class SettingsAboutFragment extends StatelessWidget {
onTap: () async {
await Clipboard.setData(ClipboardData(text: appVersion));

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(L10n.of(context).copied_version_to_clipboard),
));
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(L10n.of(context).copied_version_to_clipboard),
));
}
},
)),
PrefLabel(
Expand Down
1 change: 0 additions & 1 deletion lib/settings/_accessibility.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:quacker/constants.dart';
import 'package:quacker/generated/l10n.dart';
import 'package:quacker/utils/iterables.dart';
import 'package:pref/pref.dart';

class SettingsAccessibilityFragment extends StatelessWidget {
Expand Down
Loading

0 comments on commit c3ac345

Please sign in to comment.