From 780f7c22bc7841b1246d26b8eee4527403996c6a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 16 Sep 2024 11:57:16 +0800 Subject: [PATCH] :lipstick: Better user agent --- lib/bootstrapper.dart | 2 +- lib/providers/account_status.dart | 6 +-- lib/providers/auth.dart | 8 ++-- lib/providers/call.dart | 2 +- lib/providers/content/attachment.dart | 10 ++-- lib/providers/content/channel.dart | 16 +++---- lib/providers/content/posts.dart | 10 ++-- lib/providers/content/realm.dart | 4 +- lib/providers/daily_sign.dart | 6 +-- lib/providers/database/services/messages.dart | 6 +-- lib/providers/link_expander.dart | 2 +- lib/providers/relation.dart | 14 +++--- lib/providers/stickers.dart | 2 +- lib/providers/websocket.dart | 4 +- lib/screens/account.dart | 1 - lib/screens/account/notification.dart | 4 +- lib/screens/account/personalize.dart | 4 +- lib/screens/account/profile_page.dart | 8 ++-- lib/screens/account/stickers.dart | 4 +- lib/screens/auth/signin.dart | 12 +++-- lib/screens/auth/signup.dart | 2 +- lib/screens/channel/channel_chat.dart | 1 - lib/screens/channel/channel_detail.dart | 2 +- lib/screens/posts/post_editor.dart | 2 +- lib/screens/realms/realm_organize.dart | 2 +- lib/services.dart | 46 +++++++++++++++---- .../account/account_profile_popup.dart | 2 +- lib/widgets/account/account_select.dart | 12 ++--- lib/widgets/channel/channel_deletion.dart | 18 ++++---- lib/widgets/channel/channel_member.dart | 6 +-- lib/widgets/chat/call/chat_call_action.dart | 4 +- lib/widgets/chat/chat_event_deletion.dart | 2 +- lib/widgets/chat/chat_message_input.dart | 6 +-- lib/widgets/posts/editor/post_tags_field.dart | 2 +- lib/widgets/posts/post_action.dart | 4 +- lib/widgets/posts/post_quick_action.dart | 2 +- lib/widgets/realms/realm_deletion.dart | 7 ++- lib/widgets/realms/realm_member.dart | 6 +-- lib/widgets/stickers/sticker_uploader.dart | 2 +- 39 files changed, 140 insertions(+), 113 deletions(-) diff --git a/lib/bootstrapper.dart b/lib/bootstrapper.dart index 3d1d366..3ca9646 100644 --- a/lib/bootstrapper.dart +++ b/lib/bootstrapper.dart @@ -71,7 +71,7 @@ class _BootstrapperShellState extends State { ( label: 'bsCheckingServer', action: () async { - final client = ServiceFinder.configureClient('dealer'); + final client = await ServiceFinder.configureClient('dealer'); final resp = await client.get('/.well-known'); if (resp.statusCode != null && resp.statusCode != 200) { setState(() { diff --git a/lib/providers/account_status.dart b/lib/providers/account_status.dart index e7332b1..f70639f 100644 --- a/lib/providers/account_status.dart +++ b/lib/providers/account_status.dart @@ -37,7 +37,7 @@ class StatusProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); return await client.get('/users/me/status'); } @@ -56,7 +56,7 @@ class StatusProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final payload = { 'type': type, @@ -85,7 +85,7 @@ class StatusProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.delete('/users/me/status'); if (resp.statusCode != 200) { diff --git a/lib/providers/auth.dart b/lib/providers/auth.dart index 8b1b0e8..21ee211 100644 --- a/lib/providers/auth.dart +++ b/lib/providers/auth.dart @@ -115,14 +115,14 @@ class AuthProvider extends GetConnect { return request; } - GetConnect configureClient( + Future configureClient( String service, { timeout = const Duration(seconds: 5), - }) { + }) async { final client = GetConnect( maxAuthRetries: 3, timeout: timeout, - userAgent: 'Solian/1.1', + userAgent: await ServiceFinder.getUserAgent(), sendUserAgent: true, ); client.httpClient.addAuthenticator(requestAuthenticator); @@ -204,7 +204,7 @@ class AuthProvider extends GetConnect { Future refreshUserProfile() async { if (!isAuthorized.value) return; - final client = configureClient('auth'); + final client = await configureClient('auth'); final resp = await client.get('/users/me'); if (resp.statusCode != 200) { throw RequestException(resp); diff --git a/lib/providers/call.dart b/lib/providers/call.dart index 298d9db..5f24c13 100644 --- a/lib/providers/call.dart +++ b/lib/providers/call.dart @@ -92,7 +92,7 @@ class ChatCallProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.post( '/channels/global/${channel.value!.alias}/calls/ongoing/token', diff --git a/lib/providers/content/attachment.dart b/lib/providers/content/attachment.dart index 7ed5e30..4f4a302 100644 --- a/lib/providers/content/attachment.dart +++ b/lib/providers/content/attachment.dart @@ -93,7 +93,7 @@ class AttachmentProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient( + final client = await auth.configureClient( 'uc', timeout: const Duration(minutes: 3), ); @@ -135,7 +135,7 @@ class AttachmentProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('uc'); + final client = await auth.configureClient('uc'); final fileAlt = basename(path).contains('.') ? basename(path).substring(0, basename(path).lastIndexOf('.')) @@ -173,7 +173,7 @@ class AttachmentProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient( + final client = await auth.configureClient( 'uc', timeout: const Duration(minutes: 3), ); @@ -198,7 +198,7 @@ class AttachmentProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('files'); + final client = await auth.configureClient('files'); var resp = await client.put('/attachments/$id', { 'alt': alt, @@ -217,7 +217,7 @@ class AttachmentProvider extends GetConnect { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('files'); + final client = await auth.configureClient('files'); var resp = await client.delete('/attachments/$id'); if (resp.statusCode != 200) { diff --git a/lib/providers/content/channel.dart b/lib/providers/content/channel.dart index 22eaef4..34451ad 100644 --- a/lib/providers/content/channel.dart +++ b/lib/providers/content/channel.dart @@ -33,7 +33,7 @@ class ChannelProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get('/channels/$realm/$alias'); if (resp.statusCode != 200) { @@ -48,7 +48,7 @@ class ChannelProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get('/channels/$realm/$alias/me'); if (resp.statusCode != 200) { @@ -63,7 +63,7 @@ class ChannelProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get('/channels/$realm/$alias/calls/ongoing'); if (resp.statusCode == 404) { @@ -79,7 +79,7 @@ class ChannelProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get('/channels/$scope'); if (resp.statusCode != 200) { @@ -93,7 +93,7 @@ class ChannelProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get('/channels/$realm/me/available'); if (resp.statusCode != 200) { @@ -107,7 +107,7 @@ class ChannelProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.post('/channels/$scope', payload); if (resp.statusCode != 200) { @@ -132,7 +132,7 @@ class ChannelProvider extends GetxController { if (related == null) return null; final prof = auth.userProfile.value!; - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.post('/channels/$scope/dm', { 'alias': const Uuid().v4().replaceAll('-', '').substring(0, 12), @@ -153,7 +153,7 @@ class ChannelProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.put('/channels/$scope/$id', payload); if (resp.statusCode != 200) { diff --git a/lib/providers/content/posts.dart b/lib/providers/content/posts.dart index 41b3039..16f2578 100644 --- a/lib/providers/content/posts.dart +++ b/lib/providers/content/posts.dart @@ -14,9 +14,9 @@ class PostProvider extends GetConnect { GetConnect client; final AuthProvider auth = Get.find(); if (auth.isAuthorized.value) { - client = auth.configureClient('co'); + client = await auth.configureClient('co'); } else { - client = ServiceFinder.configureClient('co'); + client = await ServiceFinder.configureClient('co'); } final resp = await client.get('/whats-new?pivot=$pivot'); if (resp.statusCode != 200) { @@ -36,9 +36,9 @@ class PostProvider extends GetConnect { if (realm != null) 'realm=$realm', ]; if (auth.isAuthorized.value) { - client = auth.configureClient('co'); + client = await auth.configureClient('co'); } else { - client = ServiceFinder.configureClient('co'); + client = await ServiceFinder.configureClient('co'); } final resp = await client.get( channel == null @@ -60,7 +60,7 @@ class PostProvider extends GetConnect { 'take=${10}', 'offset=$page', ]; - final client = auth.configureClient('interactive'); + final client = await auth.configureClient('interactive'); final resp = await client.get('/posts/drafts?${queries.join('&')}'); if (resp.statusCode != 200) { throw RequestException(resp); diff --git a/lib/providers/content/realm.dart b/lib/providers/content/realm.dart index 5353947..63760af 100644 --- a/lib/providers/content/realm.dart +++ b/lib/providers/content/realm.dart @@ -25,7 +25,7 @@ class RealmProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.get('/realms/$alias'); if (resp.statusCode != 200) { @@ -39,7 +39,7 @@ class RealmProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.get('/realms/me/available'); if (resp.statusCode != 200) { diff --git a/lib/providers/daily_sign.dart b/lib/providers/daily_sign.dart index 92f3fcb..fd781a3 100644 --- a/lib/providers/daily_sign.dart +++ b/lib/providers/daily_sign.dart @@ -10,7 +10,7 @@ class DailySignProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('id'); + final client = await auth.configureClient('id'); final resp = await client.get('/daily?take=$take'); if (resp.statusCode != 200 && resp.statusCode != 404) { @@ -30,7 +30,7 @@ class DailySignProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('id'); + final client = await auth.configureClient('id'); final resp = await client.get('/daily/today'); if (resp.statusCode != 200 && resp.statusCode != 404) { @@ -46,7 +46,7 @@ class DailySignProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) throw const UnauthorizedException(); - final client = auth.configureClient('id'); + final client = await auth.configureClient('id'); final resp = await client.post('/daily', {}); if (resp.statusCode != 200) { diff --git a/lib/providers/database/services/messages.dart b/lib/providers/database/services/messages.dart index 1907670..8508c0c 100644 --- a/lib/providers/database/services/messages.dart +++ b/lib/providers/database/services/messages.dart @@ -12,7 +12,7 @@ class MessagesFetchingProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return null; - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get( '/whats-new?pivot=$pivot&take=$take', @@ -33,7 +33,7 @@ class MessagesFetchingProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return null; - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get( '/channels/$scope/${channel.alias}/events/$id', @@ -57,7 +57,7 @@ class MessagesFetchingProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return null; - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.get( '/channels/$scope/${channel.alias}/events?take=$take&offset=$offset', diff --git a/lib/providers/link_expander.dart b/lib/providers/link_expander.dart index 281d65e..64c12f4 100644 --- a/lib/providers/link_expander.dart +++ b/lib/providers/link_expander.dart @@ -12,7 +12,7 @@ class LinkExpandProvider extends GetxController { log('[LinkExpander] Expanding link... $url'); final target = utf8.fuse(base64).encode(url); if (_cachedResponse.containsKey(target)) return _cachedResponse[target]; - final client = ServiceFinder.configureClient('dealer'); + final client = await ServiceFinder.configureClient('dealer'); final resp = await client.get('/api/links/$target'); if (resp.statusCode != 200) { log('Unable to expand link ($url), status: ${resp.statusCode}, response: ${resp.body}'); diff --git a/lib/providers/relation.dart b/lib/providers/relation.dart index 9e07f1f..c1fdcac 100644 --- a/lib/providers/relation.dart +++ b/lib/providers/relation.dart @@ -26,21 +26,21 @@ class RelationshipProvider extends GetxController { return _friends.any((x) => x.relatedId == account.id); } - Future listRelation() { + Future listRelation() async { final AuthProvider auth = Get.find(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); return client.get('/users/me/relations'); } - Future listRelationWithStatus(int status) { + Future listRelationWithStatus(int status) async { final AuthProvider auth = Get.find(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); return client.get('/users/me/relations?status=$status'); } Future makeFriend(String username) async { final AuthProvider auth = Get.find(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.post('/users/me/relations?related=$username', {}); if (resp.statusCode != 200) { throw RequestException(resp); @@ -52,7 +52,7 @@ class RelationshipProvider extends GetxController { Future handleRelation( Relationship relationship, bool doAccept) async { final AuthProvider auth = Get.find(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.post( '/users/me/relations/${relationship.relatedId}/${doAccept ? 'accept' : 'decline'}', {}, @@ -66,7 +66,7 @@ class RelationshipProvider extends GetxController { Future editRelation(Relationship relationship, int status) async { final AuthProvider auth = Get.find(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.patch( '/users/me/relations/${relationship.relatedId}', {'status': status}, diff --git a/lib/providers/stickers.dart b/lib/providers/stickers.dart index 1838887..bbe0fc8 100644 --- a/lib/providers/stickers.dart +++ b/lib/providers/stickers.dart @@ -11,7 +11,7 @@ class StickerProvider extends GetxController { availableStickers.clear(); aliasImageMapping.clear(); - final client = ServiceFinder.configureClient('files'); + final client = await ServiceFinder.configureClient('files'); final resp = await client.get( '/stickers/manifest?take=100', ); diff --git a/lib/providers/websocket.dart b/lib/providers/websocket.dart index 914ea32..710c012 100644 --- a/lib/providers/websocket.dart +++ b/lib/providers/websocket.dart @@ -138,7 +138,7 @@ class WebSocketProvider extends GetxController { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.get('/notifications?skip=0&take=100'); if (resp.statusCode == 200) { @@ -182,7 +182,7 @@ class WebSocketProvider extends GetxController { } log('Device Push Token is $token'); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.post('/notifications/subscribe', { 'provider': provider, diff --git a/lib/screens/account.dart b/lib/screens/account.dart index 496344b..88b4b64 100644 --- a/lib/screens/account.dart +++ b/lib/screens/account.dart @@ -205,7 +205,6 @@ class _ActionCard extends StatelessWidget { final Function onTap; const _ActionCard({ - super.key, required this.onTap, required this.title, required this.caption, diff --git a/lib/screens/account/notification.dart b/lib/screens/account/notification.dart index 519ffc1..bda2267 100644 --- a/lib/screens/account/notification.dart +++ b/lib/screens/account/notification.dart @@ -31,7 +31,7 @@ class _NotificationScreenState extends State { } if (markList.isNotEmpty) { - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); await client.put('/notifications/read', {'messages': markList}); } @@ -53,7 +53,7 @@ class _NotificationScreenState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); await client.put('/notifications/read/${element.id}', {}); diff --git a/lib/screens/account/personalize.dart b/lib/screens/account/personalize.dart index b5f8ab1..feb529f 100644 --- a/lib/screens/account/personalize.dart +++ b/lib/screens/account/personalize.dart @@ -126,7 +126,7 @@ class _PersonalizeScreenState extends State { return; } - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.put( '/users/me/$position', @@ -148,7 +148,7 @@ class _PersonalizeScreenState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); _birthday?.toIso8601String(); final resp = await client.put( diff --git a/lib/screens/account/profile_page.dart b/lib/screens/account/profile_page.dart index d058649..9621f9c 100644 --- a/lib/screens/account/profile_page.dart +++ b/lib/screens/account/profile_page.dart @@ -46,7 +46,7 @@ class _AccountProfilePageState extends State { Future _getUserinfo() async { setState(() => _isBusy = true); - var client = ServiceFinder.configureClient('auth'); + var client = await ServiceFinder.configureClient('auth'); var resp = await client.get('/users/${widget.name}'); if (resp.statusCode != 200) { context.showErrorDialog(resp.bodyString).then((_) { @@ -56,7 +56,7 @@ class _AccountProfilePageState extends State { _userinfo = Account.fromJson(resp.body); } - client = ServiceFinder.configureClient('interactive'); + client = await ServiceFinder.configureClient('interactive'); resp = await client.get('/users/${widget.name}'); if (resp.statusCode != 200) { context.showErrorDialog(resp.bodyString).then((_) { @@ -71,7 +71,7 @@ class _AccountProfilePageState extends State { } Future getPinnedPosts() async { - final client = ServiceFinder.configureClient('interactive'); + final client = await ServiceFinder.configureClient('interactive'); final resp = await client.get('/users/${widget.name}/pin'); if (resp.statusCode != 200) { context.showErrorDialog(resp.bodyString).then((_) { @@ -95,7 +95,7 @@ class _AccountProfilePageState extends State { _relationshipProvider = Get.find(); _postController = PostListController(author: widget.name); _albumPagingController.addPageRequestListener((pageKey) async { - final client = ServiceFinder.configureClient('files'); + final client = await ServiceFinder.configureClient('files'); final resp = await client.get( '/attachments?take=10&offset=$pageKey&author=${widget.name}&original=true', ); diff --git a/lib/screens/account/stickers.dart b/lib/screens/account/stickers.dart index d5e0ff5..0e865cd 100644 --- a/lib/screens/account/stickers.dart +++ b/lib/screens/account/stickers.dart @@ -48,7 +48,7 @@ class _StickerScreenState extends State { ); if (confirm != true) return false; - final client = auth.configureClient('files'); + final client = await auth.configureClient('files'); final resp = await client.delete('/stickers/${item.id}'); return resp.statusCode == 200; @@ -107,7 +107,7 @@ class _StickerScreenState extends State { final AuthProvider auth = Get.find(); final name = auth.userProfile.value!['name']; _pagingController.addPageRequestListener((pageKey) async { - final client = ServiceFinder.configureClient('files'); + final client = await ServiceFinder.configureClient('files'); final resp = await client.get( '/stickers/manifest?take=10&offset=$pageKey&author=$name', ); diff --git a/lib/screens/auth/signin.dart b/lib/screens/auth/signin.dart index d4528f5..088498b 100644 --- a/lib/screens/auth/signin.dart +++ b/lib/screens/auth/signin.dart @@ -49,7 +49,7 @@ class _SignInScreenState extends State { setState(() => _isBusy = true); - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); final lookupResp = await client.get('/users/lookup?probe=$username'); if (lookupResp.statusCode != 200) { context.showErrorDialog(lookupResp.bodyString); @@ -74,7 +74,7 @@ class _SignInScreenState extends State { final username = _usernameController.value.text; if (username.isEmpty) return; - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); setState(() => _isBusy = true); @@ -114,7 +114,7 @@ class _SignInScreenState extends State { void _performGetFactorCode() async { if (_factorPicked == null) return; - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); setState(() => _isBusy = true); @@ -147,7 +147,7 @@ class _SignInScreenState extends State { final password = _passwordController.value.text; if (password.isEmpty) return; - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); setState(() => _isBusy = true); @@ -288,7 +288,9 @@ class _SignInScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ TextButton( - onPressed: _isBusy ? null : () => _previousStep(), + onPressed: (_isBusy || _period > 1) + ? null + : () => _previousStep(), style: TextButton.styleFrom(foregroundColor: Colors.grey), child: Row( diff --git a/lib/screens/auth/signup.dart b/lib/screens/auth/signup.dart index 6dfb220..b5bafd9 100644 --- a/lib/screens/auth/signup.dart +++ b/lib/screens/auth/signup.dart @@ -28,7 +28,7 @@ class _SignUpScreenState extends State { nickname.isEmpty || password.isEmpty) return; - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); final resp = await client.post('/users', { 'name': username, diff --git a/lib/screens/channel/channel_chat.dart b/lib/screens/channel/channel_chat.dart index 9232c66..262a11f 100644 --- a/lib/screens/channel/channel_chat.dart +++ b/lib/screens/channel/channel_chat.dart @@ -97,7 +97,6 @@ class _ChannelChatScreenState extends State setState(() => _ongoingCall = Call.fromJson(resp.body)); } } catch (e) { - print((e as dynamic).stackTrace); context.showErrorDialog(e); } diff --git a/lib/screens/channel/channel_detail.dart b/lib/screens/channel/channel_detail.dart index 8369ae2..375df02 100644 --- a/lib/screens/channel/channel_detail.dart +++ b/lib/screens/channel/channel_detail.dart @@ -79,7 +79,7 @@ class _ChannelDetailScreenState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client .put('/channels/${widget.realm}/${widget.channel.alias}/members/me', { diff --git a/lib/screens/posts/post_editor.dart b/lib/screens/posts/post_editor.dart index dc9ce5d..3991b79 100644 --- a/lib/screens/posts/post_editor.dart +++ b/lib/screens/posts/post_editor.dart @@ -75,7 +75,7 @@ class _PostPublishScreenState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('interactive'); + final client = await auth.configureClient('interactive'); Response resp; if (widget.edit != null) { diff --git a/lib/screens/realms/realm_organize.dart b/lib/screens/realms/realm_organize.dart index 89acd26..eba450b 100644 --- a/lib/screens/realms/realm_organize.dart +++ b/lib/screens/realms/realm_organize.dart @@ -43,7 +43,7 @@ class _RealmOrganizeScreenState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final payload = { 'alias': _aliasController.value.text.toLowerCase(), diff --git a/lib/services.dart b/lib/services.dart index 8c60eb1..9e14537 100644 --- a/lib/services.dart +++ b/lib/services.dart @@ -1,28 +1,58 @@ +import 'package:device_info_plus/device_info_plus.dart'; import 'package:get/get.dart'; +import 'package:package_info_plus/package_info_plus.dart'; +import 'package:solian/platform.dart'; abstract class ServiceFinder { - static const bool devFlag = true; + static const bool devFlag = false; static const String dealerUrl = devFlag ? 'http://localhost:8442' : 'https://api.sn.solsynth.dev'; - static const String capitalUrl = - devFlag ? 'http://localhost:8444' : 'https://solsynth.dev'; static String buildUrl(String serviceName, String? append) { append ??= ''; if (serviceName == 'dealer') { return '$dealerUrl$append'; - } else if (serviceName == 'capital') { - return '$capitalUrl$append'; } return '$dealerUrl/cgi/$serviceName$append'; } - static GetConnect configureClient(String serviceName, - {timeout = const Duration(seconds: 5)}) { + static Future getUserAgent() async { + final String platformInfo; + if (PlatformInfo.isAndroid) { + final deviceInfo = await DeviceInfoPlugin().androidInfo; + platformInfo = + 'Android; ${deviceInfo.brand} ${deviceInfo.model}; ${deviceInfo.id}'; + } else if (PlatformInfo.isIOS) { + final deviceInfo = await DeviceInfoPlugin().iosInfo; + platformInfo = 'iOS; ${deviceInfo.model}; ${deviceInfo.name}'; + } else if (PlatformInfo.isMacOS) { + final deviceInfo = await DeviceInfoPlugin().macOsInfo; + platformInfo = 'MacOS; ${deviceInfo.model}; ${deviceInfo.hostName}'; + } else if (PlatformInfo.isWindows) { + final deviceInfo = await DeviceInfoPlugin().windowsInfo; + platformInfo = + 'Windows NT; ${deviceInfo.productName}; ${deviceInfo.computerName}'; + } else if (PlatformInfo.isLinux) { + final deviceInfo = await DeviceInfoPlugin().linuxInfo; + platformInfo = 'Linux; ${deviceInfo.prettyName}'; + } else if (PlatformInfo.isWeb) { + final deviceInfo = await DeviceInfoPlugin().webBrowserInfo; + platformInfo = 'Web; ${deviceInfo.vendor}'; + } else { + platformInfo = 'Unknown'; + } + + final packageInfo = await PackageInfo.fromPlatform(); + + return 'Solian/${packageInfo.version}+${packageInfo.buildNumber} ($platformInfo)'; + } + + static Future configureClient(String serviceName, + {timeout = const Duration(seconds: 5)}) async { final client = GetConnect( timeout: timeout, - userAgent: 'Solian/1.1', + userAgent: await getUserAgent(), sendUserAgent: true, ); client.httpClient.baseUrl = buildUrl(serviceName, null); diff --git a/lib/widgets/account/account_profile_popup.dart b/lib/widgets/account/account_profile_popup.dart index 2d9c08f..e28f14f 100644 --- a/lib/widgets/account/account_profile_popup.dart +++ b/lib/widgets/account/account_profile_popup.dart @@ -26,7 +26,7 @@ class _AccountProfilePopupState extends State { setState(() => _isBusy = true); try { - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); final resp = await client.get('/users/${widget.name}'); if (resp.statusCode == 200) { setState(() { diff --git a/lib/widgets/account/account_select.dart b/lib/widgets/account/account_select.dart index cd34906..2328720 100644 --- a/lib/widgets/account/account_select.dart +++ b/lib/widgets/account/account_select.dart @@ -36,16 +36,13 @@ class _AccountSelectorState extends State { _revertSelectedUsers() async { if (widget.initialSelection?.isEmpty ?? true) return; - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); final idQuery = widget.initialSelection!.join(','); final resp = await client.get('/users?id=$idQuery'); setState(() { _selectedUsers.addAll( - resp.body - .map((e) => Account.fromJson(e)) - .toList() - .cast(), + resp.body.map((e) => Account.fromJson(e)).toList().cast(), ); }); } @@ -73,7 +70,7 @@ class _AccountSelectorState extends State { if (_probeController.text.isEmpty) return; - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.get( '/users/search?probe=${_probeController.text}', ); @@ -156,7 +153,8 @@ class _AccountSelectorState extends State { } setState(() { - final idx = _selectedUsers.indexWhere((x) => x.id == element.id); + final idx = _selectedUsers + .indexWhere((x) => x.id == element.id); if (idx != -1) { _selectedUsers.removeAt(idx); } else { diff --git a/lib/widgets/channel/channel_deletion.dart b/lib/widgets/channel/channel_deletion.dart index 5f4fc13..d761af0 100644 --- a/lib/widgets/channel/channel_deletion.dart +++ b/lib/widgets/channel/channel_deletion.dart @@ -29,10 +29,10 @@ class _ChannelDeletionDialogState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); - final resp = await client - .delete('/channels/${widget.realm}/${widget.channel.id}'); + final resp = + await client.delete('/channels/${widget.realm}/${widget.channel.id}'); if (resp.statusCode != 200) { context.showErrorDialog(resp.bodyString); } else if (Navigator.canPop(context)) { @@ -48,7 +48,7 @@ class _ChannelDeletionDialogState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.delete( '/channels/${widget.realm}/${widget.channel.alias}/members/me', @@ -69,11 +69,11 @@ class _ChannelDeletionDialogState extends State { ? 'channelDeletionConfirm'.tr : 'channelLeaveConfirm'.tr), content: Text( - widget.isOwned ? - 'channelDeletionConfirmCaption' - .trParams({'channel': '#${widget.channel.alias}'}) : - 'channelLeaveConfirmCaption' - .trParams({'channel': '#${widget.channel.alias}'}), + widget.isOwned + ? 'channelDeletionConfirmCaption' + .trParams({'channel': '#${widget.channel.alias}'}) + : 'channelLeaveConfirmCaption' + .trParams({'channel': '#${widget.channel.alias}'}), ), actions: [ TextButton( diff --git a/lib/widgets/channel/channel_member.dart b/lib/widgets/channel/channel_member.dart index 396f4c0..547f078 100644 --- a/lib/widgets/channel/channel_member.dart +++ b/lib/widgets/channel/channel_member.dart @@ -39,7 +39,7 @@ class _ChannelMemberListPopupState extends State { void getMembers() async { setState(() => _isBusy = true); - final client = ServiceFinder.configureClient('messaging'); + final client = await ServiceFinder.configureClient('messaging'); final resp = await client .get('/channels/${widget.realm}/${widget.channel.alias}/members'); @@ -75,7 +75,7 @@ class _ChannelMemberListPopupState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.post( '/channels/${widget.realm}/${widget.channel.alias}/members', @@ -96,7 +96,7 @@ class _ChannelMemberListPopupState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); final resp = await client.request( '/channels/${widget.realm}/${widget.channel.alias}/members', diff --git a/lib/widgets/chat/call/chat_call_action.dart b/lib/widgets/chat/call/chat_call_action.dart index feb3bd3..bc80897 100644 --- a/lib/widgets/chat/call/chat_call_action.dart +++ b/lib/widgets/chat/call/chat_call_action.dart @@ -33,7 +33,7 @@ class _ChatCallButtonState extends State { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); setState(() => _isBusy = true); @@ -57,7 +57,7 @@ class _ChatCallButtonState extends State { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); setState(() => _isBusy = true); diff --git a/lib/widgets/chat/chat_event_deletion.dart b/lib/widgets/chat/chat_event_deletion.dart index 9645b2a..0286a49 100644 --- a/lib/widgets/chat/chat_event_deletion.dart +++ b/lib/widgets/chat/chat_event_deletion.dart @@ -30,7 +30,7 @@ class _ChatEventDeletionDialogState extends State { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; - final client = auth.configureClient('messaging'); + final client = await auth.configureClient('messaging'); setState(() => _isBusy = true); diff --git a/lib/widgets/chat/chat_message_input.dart b/lib/widgets/chat/chat_message_input.dart index 0191f89..b2be661 100644 --- a/lib/widgets/chat/chat_message_input.dart +++ b/lib/widgets/chat/chat_message_input.dart @@ -118,7 +118,7 @@ class _ChatMessageInputState extends State { final mentionedUserNames = _findMentionedUsers(_textController.text); final mentionedUserIds = List.empty(growable: true); - var client = auth.configureClient('auth'); + var client = await auth.configureClient('auth'); if (mentionedUserNames.isNotEmpty) { resp = await client.get('/users?name=${mentionedUserNames.join(',')}'); if (resp.statusCode != 200) { @@ -131,7 +131,7 @@ class _ChatMessageInputState extends State { } } - client = auth.configureClient('messaging'); + client = await auth.configureClient('messaging'); if (_textController.text.trim().isEmpty && _attachments.isEmpty) return; @@ -432,7 +432,7 @@ class _ChatMessageInputState extends State { final userSearch = userMatch[1]!.toLowerCase(); final AuthProvider auth = Get.find(); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.get( '/users/search?probe=$userSearch', ); diff --git a/lib/widgets/posts/editor/post_tags_field.dart b/lib/widgets/posts/editor/post_tags_field.dart index 476b764..16678ef 100644 --- a/lib/widgets/posts/editor/post_tags_field.dart +++ b/lib/widgets/posts/editor/post_tags_field.dart @@ -35,7 +35,7 @@ class _TagsFieldState extends State { Future?> _searchTags(String probe) async { _currentSearchProbe = probe; - final client = ServiceFinder.configureClient('interactive'); + final client = await ServiceFinder.configureClient('interactive'); final resp = await client.get( '/tags?take=10&probe=$_currentSearchProbe', ); diff --git a/lib/widgets/posts/post_action.dart b/lib/widgets/posts/post_action.dart index f000a35..5384a86 100644 --- a/lib/widgets/posts/post_action.dart +++ b/lib/widgets/posts/post_action.dart @@ -192,7 +192,7 @@ class _PostActionState extends State { : 'unpinPost'.tr, ), onTap: () async { - final client = Get.find() + final client = await Get.find() .configureClient('interactive'); await client.post('/posts/${widget.item.id}/pin', {}); Navigator.pop(context, true); @@ -254,7 +254,7 @@ class _PostDeletionDialogState extends State { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; - final client = auth.configureClient('interactive'); + final client = await auth.configureClient('interactive'); setState(() => _isBusy = true); final resp = await client.delete('/posts/${widget.item.id}'); diff --git a/lib/widgets/posts/post_quick_action.dart b/lib/widgets/posts/post_quick_action.dart index ff9d7c0..f9dfe34 100644 --- a/lib/widgets/posts/post_quick_action.dart +++ b/lib/widgets/posts/post_quick_action.dart @@ -49,7 +49,7 @@ class _PostQuickActionState extends State { if (_isSubmitting) return; if (auth.isAuthorized.isFalse) return; - final client = auth.configureClient('interactive'); + final client = await auth.configureClient('interactive'); setState(() => _isSubmitting = true); diff --git a/lib/widgets/realms/realm_deletion.dart b/lib/widgets/realms/realm_deletion.dart index a7ffe34..f91df92 100644 --- a/lib/widgets/realms/realm_deletion.dart +++ b/lib/widgets/realms/realm_deletion.dart @@ -27,7 +27,7 @@ class _RealmDeletionDialogState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.delete('/realms/${widget.realm.id}'); if (resp.statusCode != 200) { @@ -45,10 +45,9 @@ class _RealmDeletionDialogState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); - final resp = - await client.delete('/realms/${widget.realm.id}/members/me'); + final resp = await client.delete('/realms/${widget.realm.id}/members/me'); if (resp.statusCode != 200) { context.showErrorDialog(resp.bodyString); } else if (Navigator.canPop(context)) { diff --git a/lib/widgets/realms/realm_member.dart b/lib/widgets/realms/realm_member.dart index ba2e6e8..b659491 100644 --- a/lib/widgets/realms/realm_member.dart +++ b/lib/widgets/realms/realm_member.dart @@ -37,7 +37,7 @@ class _RealmMemberListPopupState extends State { void getMembers() async { setState(() => _isBusy = true); - final client = ServiceFinder.configureClient('auth'); + final client = await ServiceFinder.configureClient('auth'); final resp = await client.get('/realms/${widget.realm.alias}/members'); if (resp.statusCode == 200) { @@ -72,7 +72,7 @@ class _RealmMemberListPopupState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.post( '/realms/${widget.realm.alias}/members', @@ -93,7 +93,7 @@ class _RealmMemberListPopupState extends State { setState(() => _isBusy = true); - final client = auth.configureClient('auth'); + final client = await auth.configureClient('auth'); final resp = await client.request( '/realms/${widget.realm.alias}/members', diff --git a/lib/widgets/stickers/sticker_uploader.dart b/lib/widgets/stickers/sticker_uploader.dart index 7bd9d30..4f9b834 100644 --- a/lib/widgets/stickers/sticker_uploader.dart +++ b/lib/widgets/stickers/sticker_uploader.dart @@ -63,7 +63,7 @@ class _StickerUploadDialogState extends State { setState(() => _isBusy = true); Response resp; - final client = auth.configureClient('files'); + final client = await auth.configureClient('files'); if (widget.edit == null) { resp = await client.post('/stickers', { 'name': _nameController.text,