Skip to content

Commit

Permalink
Add new setting for custom proxy servers and fix non subscribed threa…
Browse files Browse the repository at this point in the history
…ds not marking as read
  • Loading branch information
dasmikko committed Feb 15, 2023
1 parent e8c8cce commit 4165918
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/controllers/settingsController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:get/get.dart';

class SettingsController extends GetxController {
final String defaultAPIURL = 'https://knockyauth.rekna.xyz/';
final RxBool useDevAPI = false.obs;
var apiEnv = 'knockout'.obs;
final showNSFWThreads = false.obs;
RxString apiEndpoint = 'https://knockyauth.rekna.xyz/'.obs;
Expand Down
10 changes: 6 additions & 4 deletions lib/controllers/syncController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class SyncController extends GetxController {
isFetching.value = true;
var syncDataValue = await KnockoutAPI().getSyncData();

subscriptionNotificationCount.value = syncDataValue.subscriptions!
.where((threadAlert) => threadAlert.unreadPostCount! > 0)
.length;
if (syncDataValue.subscriptions != null) {
subscriptionNotificationCount.value = syncDataValue.subscriptions!
.where((threadAlert) => threadAlert.unreadPostCount! > 0)
.length;

mentions.value = syncDataValue.mentions!;
mentions.value = syncDataValue.mentions!;
}

isFetching.value = false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/threadController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ThreadController extends PaginatedController<Thread> {

void updateReadThread(Thread thread) async {
DateTime lastPostDate = thread.posts!.last.createdAt!;
if (thread.readThreadLastSeen != null &&
if (thread.readThreadLastSeen == null ||
thread.readThreadLastSeen!.isBefore(lastPostDate)) {
await KnockoutAPI().readThreads(lastPostDate, thread.id);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void main() async {
settingsController.apiEndpoint.value = prefs.read('apiEndpoint');
}

if (prefs.hasData('useDevAPI')) {
settingsController.useDevAPI.value = prefs.read('useDevAPI');
}

authController.getStoredAuthInfo();

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
Expand Down
4 changes: 4 additions & 0 deletions lib/main_nonfdroid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void main() async {
settingsController.apiEndpoint.value = prefs.read('apiEndpoint');
}

if (prefs.hasData('useDevAPI')) {
settingsController.useDevAPI.value = prefs.read('useDevAPI');
}

authController.getStoredAuthInfo();

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
Expand Down
13 changes: 10 additions & 3 deletions lib/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ class _LoginScreenState extends State<LoginScreen> {
// Start listening to auth finish url
initUniLinks();

// Launch login url
await launch(
'${settingsController.apiEndpoint.value}auth/$provider/login?redirect=${settingsController.apiEndpoint.value}handleAuth');
if (settingsController.useDevAPI.value) {
print(
'${settingsController.apiEndpoint.value}auth/$provider/login?redirect=${settingsController.apiEndpoint.value}handleAuth');
await launch(
'${settingsController.apiEndpoint.value}auth/$provider/login?redirect=${settingsController.apiEndpoint.value}handleAuth');
} else {
// Launch login url
await launch(
'https://api.knockout.chat/auth/$provider/login?redirect=${settingsController.apiEndpoint.value}handleAuth');
}
}

@override
Expand Down
17 changes: 15 additions & 2 deletions lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class SettingsScreen extends StatelessWidget {
),
onTap: () async {
var dialogResult = await Get.dialog(InputDialog(
title: 'Enter API URL token',
title: 'Enter Proxy API URL',
content: settingsController.apiEndpoint.value,
));

Expand All @@ -172,11 +172,24 @@ class SettingsScreen extends StatelessWidget {
GetStorage prefs = GetStorage();
prefs.write('apiEndpoint', dialogResult);

KnockySnackbar.success('API URL was saved!',
KnockySnackbar.success('Proxy API URL was saved!',
icon: Icon(Icons.check));
}
},
),
Obx(
() => SwitchListTile(
title: Text('Use Proxy API for login'),
subtitle: Text('(Only needed for development)',
style: TextStyle(color: Colors.grey)),
value: settingsController.useDevAPI.value,
onChanged: (bool value) {
settingsController.useDevAPI.value = value;
GetStorage prefs = GetStorage();
prefs.write('useDevAPI', value);
},
),
),
ListTile(
title: Text('Reset API URL to default'),
onTap: () async {
Expand Down

0 comments on commit 4165918

Please sign in to comment.