♻️ Refactored auth system
This commit is contained in:
parent
ef58430060
commit
6d92a16a62
@ -106,9 +106,11 @@ class SolianApp extends StatelessWidget {
|
|||||||
Get.lazyPut(() => ChatCallProvider());
|
Get.lazyPut(() => ChatCallProvider());
|
||||||
|
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (await auth.isAuthorized) {
|
|
||||||
Get.find<WebSocketProvider>().connect();
|
|
||||||
|
|
||||||
|
auth.refreshAuthorizeStatus().then((_) {
|
||||||
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
|
Get.find<WebSocketProvider>().connect();
|
||||||
Get.find<ChannelProvider>().refreshAvailableChannel();
|
Get.find<ChannelProvider>().refreshAvailableChannel();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -118,6 +120,6 @@ class SolianApp extends StatelessWidget {
|
|||||||
'pushNotifyRegisterFailed'.trParams({'reason': err.toString()}),
|
'pushNotifyRegisterFailed'.trParams({'reason': err.toString()}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class StatusProvider extends GetConnect {
|
|||||||
|
|
||||||
Future<Response> getCurrentStatus() async {
|
Future<Response> getCurrentStatus() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('auth');
|
final client = auth.configureClient('auth');
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class StatusProvider extends GetConnect {
|
|||||||
DateTime? clearAt,
|
DateTime? clearAt,
|
||||||
}) async {
|
}) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('auth');
|
final client = auth.configureClient('auth');
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class StatusProvider extends GetConnect {
|
|||||||
|
|
||||||
Future<Response> clearStatus() async {
|
Future<Response> clearStatus() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('auth');
|
final client = auth.configureClient('auth');
|
||||||
|
|
||||||
|
@ -60,7 +60,10 @@ class AuthProvider extends GetConnect {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
httpClient.baseUrl = ServiceFinder.buildUrl('auth', null);
|
httpClient.baseUrl = ServiceFinder.buildUrl('auth', null);
|
||||||
loadCredentials();
|
refreshAuthorizeStatus().then((_) {
|
||||||
|
loadCredentials();
|
||||||
|
refreshUserProfile();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refreshCredentials() async {
|
Future<void> refreshCredentials() async {
|
||||||
@ -116,7 +119,7 @@ class AuthProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> ensureCredentials() async {
|
Future<void> ensureCredentials() async {
|
||||||
if (!await isAuthorized) throw Exception('unauthorized');
|
if (isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
if (credentials == null) await loadCredentials();
|
if (credentials == null) await loadCredentials();
|
||||||
|
|
||||||
if (credentials!.isExpired) {
|
if (credentials!.isExpired) {
|
||||||
@ -126,7 +129,7 @@ class AuthProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadCredentials() async {
|
Future<void> loadCredentials() async {
|
||||||
if (await isAuthorized) {
|
if (isAuthorized.isTrue) {
|
||||||
final content = await storage.read(key: 'auth_credentials');
|
final content = await storage.read(key: 'auth_credentials');
|
||||||
credentials = TokenSet.fromJson(jsonDecode(content!));
|
credentials = TokenSet.fromJson(jsonDecode(content!));
|
||||||
}
|
}
|
||||||
@ -137,7 +140,7 @@ class AuthProvider extends GetConnect {
|
|||||||
String username,
|
String username,
|
||||||
String password,
|
String password,
|
||||||
) async {
|
) async {
|
||||||
_cachedUserProfileResponse = null;
|
userProfile.value = null;
|
||||||
|
|
||||||
final client = ServiceFinder.configureClient('auth');
|
final client = ServiceFinder.configureClient('auth');
|
||||||
|
|
||||||
@ -172,6 +175,8 @@ class AuthProvider extends GetConnect {
|
|||||||
value: jsonEncode(credentials!.toJson()),
|
value: jsonEncode(credentials!.toJson()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await refreshUserProfile();
|
||||||
|
|
||||||
Get.find<WebSocketProvider>().connect();
|
Get.find<WebSocketProvider>().connect();
|
||||||
Get.find<WebSocketProvider>().notifyPrefetch();
|
Get.find<WebSocketProvider>().notifyPrefetch();
|
||||||
|
|
||||||
@ -179,7 +184,8 @@ class AuthProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void signout() {
|
void signout() {
|
||||||
_cachedUserProfileResponse = null;
|
isAuthorized.value = false;
|
||||||
|
userProfile.value = null;
|
||||||
|
|
||||||
Get.find<WebSocketProvider>().disconnect();
|
Get.find<WebSocketProvider>().disconnect();
|
||||||
Get.find<WebSocketProvider>().notifications.clear();
|
Get.find<WebSocketProvider>().notifications.clear();
|
||||||
@ -195,30 +201,21 @@ class AuthProvider extends GetConnect {
|
|||||||
|
|
||||||
// Data Layer
|
// Data Layer
|
||||||
|
|
||||||
Response? _cachedUserProfileResponse;
|
RxBool isAuthorized = false.obs;
|
||||||
|
Rx<Map<String, dynamic>?> userProfile = Rx(null);
|
||||||
|
|
||||||
Future<bool> get isAuthorized => storage.containsKey(key: 'auth_credentials');
|
Future<void> refreshAuthorizeStatus() async {
|
||||||
|
isAuthorized.value = await storage.containsKey(key: 'auth_credentials');
|
||||||
Future<Response> getProfile({noCache = false}) async {
|
}
|
||||||
if (!noCache && _cachedUserProfileResponse != null) {
|
|
||||||
return _cachedUserProfileResponse!;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Future<void> refreshUserProfile() async {
|
||||||
final client = configureClient('auth');
|
final client = configureClient('auth');
|
||||||
|
|
||||||
final resp = await client.get('/users/me');
|
final resp = await client.get('/users/me');
|
||||||
if (resp.statusCode != 200) {
|
if (resp.statusCode != 200) {
|
||||||
throw Exception(resp.bodyString);
|
throw Exception(resp.bodyString);
|
||||||
} else {
|
|
||||||
_cachedUserProfileResponse = resp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp;
|
userProfile.value = resp.body;
|
||||||
}
|
|
||||||
|
|
||||||
Future<Response?> getProfileWithCheck({noCache = false}) async {
|
|
||||||
if (!await isAuthorized) return null;
|
|
||||||
|
|
||||||
return await getProfile(noCache: noCache);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class ChatCallProvider extends GetxController {
|
|||||||
|
|
||||||
Future<(String, String)> getRoomToken() async {
|
Future<(String, String)> getRoomToken() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ class AttachmentProvider extends GetConnect {
|
|||||||
Map<String, dynamic>? metadata,
|
Map<String, dynamic>? metadata,
|
||||||
) async {
|
) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient(
|
final client = auth.configureClient(
|
||||||
'files',
|
'files',
|
||||||
@ -130,7 +130,7 @@ class AttachmentProvider extends GetConnect {
|
|||||||
bool isMature = false,
|
bool isMature = false,
|
||||||
}) async {
|
}) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('files');
|
final client = auth.configureClient('files');
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ class AttachmentProvider extends GetConnect {
|
|||||||
|
|
||||||
Future<Response> deleteAttachment(int id) async {
|
Future<Response> deleteAttachment(int id) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('files');
|
final client = auth.configureClient('files');
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class ChannelProvider extends GetxController {
|
|||||||
|
|
||||||
Future<void> refreshAvailableChannel() async {
|
Future<void> refreshAvailableChannel() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
final resp = await listAvailableChannel();
|
final resp = await listAvailableChannel();
|
||||||
@ -29,7 +29,7 @@ class ChannelProvider extends GetxController {
|
|||||||
|
|
||||||
Future<Response> getChannel(String alias, {String realm = 'global'}) async {
|
Future<Response> getChannel(String alias, {String realm = 'global'}) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class ChannelProvider extends GetxController {
|
|||||||
Future<Response> getMyChannelProfile(String alias,
|
Future<Response> getMyChannelProfile(String alias,
|
||||||
{String realm = 'global'}) async {
|
{String realm = 'global'}) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class ChannelProvider extends GetxController {
|
|||||||
Future<Response?> getChannelOngoingCall(String alias,
|
Future<Response?> getChannelOngoingCall(String alias,
|
||||||
{String realm = 'global'}) async {
|
{String realm = 'global'}) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class ChannelProvider extends GetxController {
|
|||||||
|
|
||||||
Future<Response> listChannel({String scope = 'global'}) async {
|
Future<Response> listChannel({String scope = 'global'}) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class ChannelProvider extends GetxController {
|
|||||||
|
|
||||||
Future<Response> listAvailableChannel({String realm = 'global'}) async {
|
Future<Response> listAvailableChannel({String realm = 'global'}) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ class ChannelProvider extends GetxController {
|
|||||||
|
|
||||||
Future<Response> createChannel(String scope, dynamic payload) async {
|
Future<Response> createChannel(String scope, dynamic payload) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ class ChannelProvider extends GetxController {
|
|||||||
Future<Response?> createDirectChannel(
|
Future<Response?> createDirectChannel(
|
||||||
BuildContext context, String scope) async {
|
BuildContext context, String scope) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final related = await showModalBottomSheet(
|
final related = await showModalBottomSheet(
|
||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
@ -129,14 +129,14 @@ class ChannelProvider extends GetxController {
|
|||||||
);
|
);
|
||||||
if (related == null) return null;
|
if (related == null) return null;
|
||||||
|
|
||||||
final prof = await auth.getProfile();
|
final prof = auth.userProfile.value!;
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
final resp = await client.post('/channels/$scope/dm', {
|
final resp = await client.post('/channels/$scope/dm', {
|
||||||
'alias': const Uuid().v4().replaceAll('-', '').substring(0, 12),
|
'alias': const Uuid().v4().replaceAll('-', '').substring(0, 12),
|
||||||
'name': 'DM',
|
'name': 'DM',
|
||||||
'description':
|
'description':
|
||||||
'A direct message channel between @${prof.body['name']} and @${related.name}',
|
'A direct message channel between @${prof['name']} and @${related.name}',
|
||||||
'related_user': related.id,
|
'related_user': related.id,
|
||||||
'is_encrypted': false,
|
'is_encrypted': false,
|
||||||
});
|
});
|
||||||
@ -149,7 +149,7 @@ class ChannelProvider extends GetxController {
|
|||||||
|
|
||||||
Future<Response> updateChannel(String scope, int id, dynamic payload) async {
|
Future<Response> updateChannel(String scope, int id, dynamic payload) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class PostProvider extends GetConnect {
|
|||||||
|
|
||||||
Future<Response> listDraft(int page) async {
|
Future<Response> listDraft(int page) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final queries = [
|
final queries = [
|
||||||
'take=${10}',
|
'take=${10}',
|
||||||
|
@ -4,7 +4,7 @@ import 'package:solian/providers/auth.dart';
|
|||||||
class RealmProvider extends GetxController {
|
class RealmProvider extends GetxController {
|
||||||
Future<Response> getRealm(String alias) async {
|
Future<Response> getRealm(String alias) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('auth');
|
final client = auth.configureClient('auth');
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ class RealmProvider extends GetxController {
|
|||||||
|
|
||||||
Future<Response> listAvailableRealm() async {
|
Future<Response> listAvailableRealm() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
final client = auth.configureClient('auth');
|
final client = auth.configureClient('auth');
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ Future<MessageHistoryDb> createHistoryDb() async {
|
|||||||
|
|
||||||
Future<Event?> getRemoteEvent(int id, Channel channel, String scope) async {
|
Future<Event?> getRemoteEvent(int id, Channel channel, String scope) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return null;
|
if (auth.isAuthorized.isFalse) return null;
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ Future<(List<Event>, int)?> getRemoteEvents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return null;
|
if (auth.isAuthorized.isFalse) return null;
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class WebSocketProvider extends GetxController {
|
|||||||
|
|
||||||
Future<void> notifyPrefetch() async {
|
Future<void> notifyPrefetch() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final client = auth.configureClient('auth');
|
final client = auth.configureClient('auth');
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ class WebSocketProvider extends GetxController {
|
|||||||
|
|
||||||
Future<void> registerPushNotifications() async {
|
Future<void> registerPushNotifications() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
late final String? token;
|
late final String? token;
|
||||||
late final String provider;
|
late final String provider;
|
||||||
|
@ -29,93 +29,85 @@ class _AccountScreenState extends State<AccountScreen> {
|
|||||||
(const Icon(Icons.info_outline), 'about'.tr, 'about'),
|
(const Icon(Icons.info_outline), 'about'.tr, 'about'),
|
||||||
];
|
];
|
||||||
|
|
||||||
final AuthProvider provider = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: FutureBuilder(
|
child: Obx(() {
|
||||||
future: provider.isAuthorized,
|
if (auth.isAuthorized.isFalse) {
|
||||||
builder: (context, snapshot) {
|
return Center(
|
||||||
if (!snapshot.hasData) {
|
child: Column(
|
||||||
return const Center(child: CircularProgressIndicator());
|
mainAxisSize: MainAxisSize.min,
|
||||||
}
|
|
||||||
|
|
||||||
if (snapshot.hasData && snapshot.data == false) {
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
ActionCard(
|
|
||||||
icon: const Icon(Icons.login, color: Colors.white),
|
|
||||||
title: 'signin'.tr,
|
|
||||||
caption: 'signinCaption'.tr,
|
|
||||||
onTap: () {
|
|
||||||
showModalBottomSheet(
|
|
||||||
useRootNavigator: true,
|
|
||||||
isDismissible: false,
|
|
||||||
isScrollControlled: true,
|
|
||||||
context: context,
|
|
||||||
builder: (context) => const SignInPopup(),
|
|
||||||
).then((val) async {
|
|
||||||
if (val == true) {
|
|
||||||
await provider.getProfile(noCache: true);
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ActionCard(
|
|
||||||
icon: const Icon(Icons.add, color: Colors.white),
|
|
||||||
title: 'signup'.tr,
|
|
||||||
caption: 'signupCaption'.tr,
|
|
||||||
onTap: () {
|
|
||||||
showModalBottomSheet(
|
|
||||||
useRootNavigator: true,
|
|
||||||
isDismissible: false,
|
|
||||||
isScrollControlled: true,
|
|
||||||
context: context,
|
|
||||||
builder: (context) => const SignUpPopup(),
|
|
||||||
).then((_) {
|
|
||||||
setState(() {});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return CenteredContainer(
|
|
||||||
child: ListView(
|
|
||||||
children: [
|
children: [
|
||||||
const AccountHeading().paddingOnly(bottom: 8, top: 8),
|
ActionCard(
|
||||||
...(actionItems.map(
|
icon: const Icon(Icons.login, color: Colors.white),
|
||||||
(x) => ListTile(
|
title: 'signin'.tr,
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
caption: 'signinCaption'.tr,
|
||||||
leading: x.$1,
|
|
||||||
title: Text(x.$2),
|
|
||||||
onTap: () {
|
|
||||||
AppRouter.instance
|
|
||||||
.pushNamed(x.$3)
|
|
||||||
.then((_) => setState(() {}));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
ListTile(
|
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
|
||||||
leading: const Icon(Icons.logout),
|
|
||||||
title: Text('signout'.tr),
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
provider.signout();
|
showModalBottomSheet(
|
||||||
setState(() {});
|
useRootNavigator: true,
|
||||||
|
isDismissible: false,
|
||||||
|
isScrollControlled: true,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => const SignInPopup(),
|
||||||
|
).then((val) async {
|
||||||
|
if (val == true) {
|
||||||
|
await auth.refreshUserProfile();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ActionCard(
|
||||||
|
icon: const Icon(Icons.add, color: Colors.white),
|
||||||
|
title: 'signup'.tr,
|
||||||
|
caption: 'signupCaption'.tr,
|
||||||
|
onTap: () {
|
||||||
|
showModalBottomSheet(
|
||||||
|
useRootNavigator: true,
|
||||||
|
isDismissible: false,
|
||||||
|
isScrollControlled: true,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => const SignUpPopup(),
|
||||||
|
).then((_) {
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
),
|
|
||||||
|
return CenteredContainer(
|
||||||
|
child: ListView(
|
||||||
|
children: [
|
||||||
|
const AccountHeading().paddingOnly(bottom: 8, top: 8),
|
||||||
|
...(actionItems.map(
|
||||||
|
(x) => ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
||||||
|
leading: x.$1,
|
||||||
|
title: Text(x.$2),
|
||||||
|
onTap: () {
|
||||||
|
AppRouter.instance
|
||||||
|
.pushNamed(x.$3)
|
||||||
|
.then((_) => setState(() {}));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
||||||
|
leading: const Icon(Icons.logout),
|
||||||
|
title: Text('signout'.tr),
|
||||||
|
onTap: () {
|
||||||
|
auth.signout();
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -139,33 +131,25 @@ class _AccountHeadingState extends State<AccountHeading> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final AuthProvider provider = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
|
|
||||||
return FutureBuilder(
|
final prof = auth.userProfile.value!;
|
||||||
future: provider.getProfile(),
|
|
||||||
builder: (context, snapshot) {
|
return AccountHeadingWidget(
|
||||||
if (!snapshot.hasData) {
|
avatar: prof['avatar'],
|
||||||
return const LinearProgressIndicator();
|
banner: prof['banner'],
|
||||||
}
|
name: prof['name'],
|
||||||
|
nick: prof['nick'],
|
||||||
final prof = snapshot.data!;
|
desc: prof['description'],
|
||||||
return AccountHeadingWidget(
|
status: _status,
|
||||||
avatar: prof.body['avatar'],
|
badges: prof['badges']
|
||||||
banner: prof.body['banner'],
|
?.map((e) => AccountBadge.fromJson(e))
|
||||||
name: prof.body['name'],
|
.toList()
|
||||||
nick: prof.body['nick'],
|
.cast<AccountBadge>(),
|
||||||
desc: prof.body['description'],
|
onEditStatus: () {
|
||||||
status: _status,
|
setState(() {
|
||||||
badges: prof.body['badges']
|
_status = Get.find<StatusProvider>().getCurrentStatus();
|
||||||
?.map((e) => AccountBadge.fromJson(e))
|
});
|
||||||
.toList()
|
|
||||||
.cast<AccountBadge>(),
|
|
||||||
onEditStatus: () {
|
|
||||||
setState(() {
|
|
||||||
_status = Get.find<StatusProvider>().getCurrentStatus();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
|
|||||||
|
|
||||||
Future<void> markAllRead() async {
|
Future<void> markAllRead() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
|
|||||||
|
|
||||||
Future<void> markOneRead(notify.Notification element, int index) async {
|
Future<void> markOneRead(notify.Notification element, int index) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final WebSocketProvider provider = Get.find();
|
final WebSocketProvider provider = Get.find();
|
||||||
|
|
||||||
|
@ -53,17 +53,17 @@ class _PersonalizeScreenState extends State<PersonalizeScreen> {
|
|||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
final prof = await auth.getProfile(noCache: true);
|
final prof = auth.userProfile.value!;
|
||||||
setState(() {
|
setState(() {
|
||||||
_usernameController.text = prof.body['name'];
|
_usernameController.text = prof['name'];
|
||||||
_nicknameController.text = prof.body['nick'];
|
_nicknameController.text = prof['nick'];
|
||||||
_descriptionController.text = prof.body['description'];
|
_descriptionController.text = prof['description'];
|
||||||
_firstNameController.text = prof.body['profile']['first_name'];
|
_firstNameController.text = prof['profile']['first_name'];
|
||||||
_lastNameController.text = prof.body['profile']['last_name'];
|
_lastNameController.text = prof['profile']['last_name'];
|
||||||
_avatar = prof.body['avatar'];
|
_avatar = prof['avatar'];
|
||||||
_banner = prof.body['banner'];
|
_banner = prof['banner'];
|
||||||
if (prof.body['profile']['birthday'] != null) {
|
if (prof['profile']['birthday'] != null) {
|
||||||
_birthday = DateTime.parse(prof.body['profile']['birthday']);
|
_birthday = DateTime.parse(prof['profile']['birthday']);
|
||||||
_birthdayController.text =
|
_birthdayController.text =
|
||||||
DateFormat('yyyy-MM-dd').format(_birthday!.toLocal());
|
DateFormat('yyyy-MM-dd').format(_birthday!.toLocal());
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ class _PersonalizeScreenState extends State<PersonalizeScreen> {
|
|||||||
|
|
||||||
Future<void> updateImage(String position) async {
|
Future<void> updateImage(String position) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final image = await _imagePicker.pickImage(source: ImageSource.gallery);
|
final image = await _imagePicker.pickImage(source: ImageSource.gallery);
|
||||||
if (image == null) return;
|
if (image == null) return;
|
||||||
@ -120,7 +120,7 @@ class _PersonalizeScreenState extends State<PersonalizeScreen> {
|
|||||||
|
|
||||||
void updatePersonalize() async {
|
void updatePersonalize() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
bool _isBusy = false;
|
bool _isBusy = false;
|
||||||
int? _accountId;
|
int? _accountId;
|
||||||
|
|
||||||
String? _overrideAlias;
|
String? _newAlias;
|
||||||
|
|
||||||
Channel? _channel;
|
Channel? _channel;
|
||||||
Call? _ongoingCall;
|
Call? _ongoingCall;
|
||||||
@ -53,26 +53,20 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
|
|
||||||
late final ChatEventController _chatController;
|
late final ChatEventController _chatController;
|
||||||
|
|
||||||
getProfile() async {
|
getChannel({String? alias}) async {
|
||||||
final AuthProvider auth = Get.find();
|
|
||||||
final prof = await auth.getProfile();
|
|
||||||
_accountId = prof.body['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
getChannel({String? overrideAlias}) async {
|
|
||||||
final ChannelProvider provider = Get.find();
|
final ChannelProvider provider = Get.find();
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
if (overrideAlias != null) _overrideAlias = overrideAlias;
|
if (alias != null) _newAlias = alias;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final resp = await provider.getChannel(
|
final resp = await provider.getChannel(
|
||||||
_overrideAlias ?? widget.alias,
|
_newAlias ?? widget.alias,
|
||||||
realm: widget.realm,
|
realm: widget.realm,
|
||||||
);
|
);
|
||||||
final respProfile = await provider.getMyChannelProfile(
|
final respProfile = await provider.getMyChannelProfile(
|
||||||
_overrideAlias ?? widget.alias,
|
_newAlias ?? widget.alias,
|
||||||
realm: widget.realm,
|
realm: widget.realm,
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -93,7 +87,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final resp = await provider.getChannelOngoingCall(
|
final resp = await provider.getChannelOngoingCall(
|
||||||
_overrideAlias ?? widget.alias,
|
_newAlias ?? widget.alias,
|
||||||
realm: widget.realm,
|
realm: widget.realm,
|
||||||
);
|
);
|
||||||
if (resp != null) {
|
if (resp != null) {
|
||||||
@ -150,16 +144,16 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
_accountId = Get.find<AuthProvider>().userProfile.value!['id'];
|
||||||
|
|
||||||
_chatController = ChatEventController();
|
_chatController = ChatEventController();
|
||||||
_chatController.initialize();
|
_chatController.initialize();
|
||||||
|
|
||||||
getChannel().then((_) {
|
getChannel().then((_) {
|
||||||
_chatController.getEvents(_channel!, widget.realm);
|
_chatController.getEvents(_channel!, widget.realm);
|
||||||
|
|
||||||
listenMessages();
|
listenMessages();
|
||||||
});
|
});
|
||||||
|
|
||||||
getProfile();
|
|
||||||
getOngoingCall();
|
getOngoingCall();
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -225,7 +219,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
if (value == false) AppRouter.instance.pop();
|
if (value == false) AppRouter.instance.pop();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
final resp = Channel.fromJson(value as Map<String, dynamic>);
|
final resp = Channel.fromJson(value as Map<String, dynamic>);
|
||||||
getChannel(overrideAlias: resp.alias);
|
getChannel(alias: resp.alias);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -41,9 +41,9 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
|
|||||||
|
|
||||||
void checkOwner() async {
|
void checkOwner() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
final prof = await auth.getProfile();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isOwned = prof.body['id'] == widget.channel.account.externalId;
|
_isOwned =
|
||||||
|
auth.userProfile.value!['id'] == widget.channel.account.externalId;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,14 +75,14 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
|
|||||||
|
|
||||||
void applyProfileChanges() async {
|
void applyProfileChanges() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
final resp = await client.put(
|
final resp = await client
|
||||||
'/channels/${widget.realm}/${widget.channel.alias}/members/me', {
|
.put('/channels/${widget.realm}/${widget.channel.alias}/members/me', {
|
||||||
'nick': null,
|
'nick': null,
|
||||||
'notify_level': _notifyLevel,
|
'notify_level': _notifyLevel,
|
||||||
});
|
});
|
||||||
|
@ -39,7 +39,7 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
|
|||||||
|
|
||||||
void applyChannel() async {
|
void applyChannel() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
if (_aliasController.value.text.isEmpty) randomizeAlias();
|
if (_aliasController.value.text.isEmpty) randomizeAlias();
|
||||||
|
|
||||||
|
@ -97,49 +97,42 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: FutureBuilder(
|
body: Obx(() {
|
||||||
future: auth.getProfileWithCheck(),
|
if (auth.isAuthorized.isFalse) {
|
||||||
builder: (context, snapshot) {
|
return SigninRequiredOverlay(
|
||||||
if (!snapshot.hasData) {
|
onSignedIn: () => _channels.refreshAvailableChannel(),
|
||||||
return const Center(
|
);
|
||||||
child: CircularProgressIndicator(),
|
}
|
||||||
);
|
|
||||||
} else if (snapshot.data == null) {
|
|
||||||
return SigninRequiredOverlay(
|
|
||||||
onSignedIn: () => _channels.refreshAvailableChannel(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final selfId = snapshot.data!.body['id'];
|
final selfId = auth.userProfile.value!['id'];
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Obx(() {
|
Obx(() {
|
||||||
if (_channels.isLoading.isFalse) {
|
if (_channels.isLoading.isFalse) {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
} else {
|
} else {
|
||||||
return const LinearProgressIndicator();
|
return const LinearProgressIndicator();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
const ChatCallCurrentIndicator(),
|
const ChatCallCurrentIndicator(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: CenteredContainer(
|
child: CenteredContainer(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: _channels.refreshAvailableChannel,
|
onRefresh: _channels.refreshAvailableChannel,
|
||||||
child: Obx(
|
child: Obx(
|
||||||
() => ChannelListWidget(
|
() => ChannelListWidget(
|
||||||
noCategory: true,
|
noCategory: true,
|
||||||
channels: _channels.directChannels,
|
channels: _channels.directChannels,
|
||||||
selfId: selfId,
|
selfId: selfId,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
);
|
],
|
||||||
},
|
);
|
||||||
),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -107,42 +107,39 @@ class FeedCreationButton extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
|
|
||||||
return FutureBuilder(
|
if (auth.isAuthorized.isFalse) {
|
||||||
future: auth.isAuthorized,
|
return const SizedBox();
|
||||||
builder: (context, snapshot) {
|
}
|
||||||
if (snapshot.hasData && snapshot.data == true) {
|
|
||||||
return PopupMenuButton(
|
return PopupMenuButton(
|
||||||
icon: const Icon(Icons.edit_square),
|
icon: const Icon(Icons.edit_square),
|
||||||
itemBuilder: (BuildContext context) => [
|
itemBuilder: (BuildContext context) => [
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text('postEditor'.tr),
|
title: Text('postEditor'.tr),
|
||||||
leading: const Icon(Icons.article),
|
leading: const Icon(Icons.article),
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AppRouter.instance.pushNamed('postEditor').then((val) {
|
AppRouter.instance.pushNamed('postEditor').then((val) {
|
||||||
if (val != null && onCreated != null) {
|
if (val != null && onCreated != null) {
|
||||||
onCreated!();
|
onCreated!();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (!hideDraftBox)
|
if (!hideDraftBox)
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text('draftBoxOpen'.tr),
|
title: Text('draftBoxOpen'.tr),
|
||||||
leading: const Icon(Icons.drafts),
|
leading: const Icon(Icons.drafts),
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AppRouter.instance.pushNamed('draftBox');
|
AppRouter.instance.pushNamed('draftBox');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
|
||||||
return const SizedBox();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
|
|||||||
|
|
||||||
void applyPost() async {
|
void applyPost() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
if (_contentController.value.text.isEmpty) return;
|
if (_contentController.value.text.isEmpty) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
@ -28,7 +28,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
|||||||
|
|
||||||
getRealms() async {
|
getRealms() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
@ -81,42 +81,33 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: FutureBuilder(
|
body: Obx(() {
|
||||||
future: auth.isAuthorized,
|
if (auth.isAuthorized.isFalse) {
|
||||||
builder: (context, snapshot) {
|
return SigninRequiredOverlay(
|
||||||
if (!snapshot.hasData) {
|
onSignedIn: () => getRealms(),
|
||||||
return const Center(
|
);
|
||||||
child: CircularProgressIndicator(),
|
}
|
||||||
);
|
|
||||||
} else if (snapshot.data == false) {
|
|
||||||
return SigninRequiredOverlay(
|
|
||||||
onSignedIn: () {
|
|
||||||
getRealms();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (_isBusy) const LinearProgressIndicator().animate().scaleX(),
|
if (_isBusy) const LinearProgressIndicator().animate().scaleX(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: CenteredContainer(
|
child: CenteredContainer(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () => getRealms(),
|
onRefresh: () => getRealms(),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: _realms.length,
|
itemCount: _realms.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final element = _realms[index];
|
final element = _realms[index];
|
||||||
return buildRealm(element);
|
return buildRealm(element);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
);
|
],
|
||||||
},
|
);
|
||||||
),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,8 @@ class _RealmDetailScreenState extends State<RealmDetailScreen> {
|
|||||||
|
|
||||||
void checkOwner() async {
|
void checkOwner() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
final prof = await auth.getProfile();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isOwned = prof.body['id'] == widget.realm.accountId;
|
_isOwned = auth.userProfile.value!['id'] == widget.realm.accountId;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class _RealmOrganizeScreenState extends State<RealmOrganizeScreen> {
|
|||||||
|
|
||||||
void applyRealm() async {
|
void applyRealm() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
if (_aliasController.value.text.isEmpty) randomizeAlias();
|
if (_aliasController.value.text.isEmpty) randomizeAlias();
|
||||||
|
|
||||||
|
@ -244,44 +244,38 @@ class RealmChannelListWidget extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
|
|
||||||
return FutureBuilder(
|
return RefreshIndicator(
|
||||||
future: auth.getProfile(),
|
onRefresh: onRefresh,
|
||||||
builder: (context, snapshot) {
|
child: Column(
|
||||||
return RefreshIndicator(
|
children: [
|
||||||
onRefresh: onRefresh,
|
ListTile(
|
||||||
child: Column(
|
leading: const Icon(Icons.add_box),
|
||||||
children: [
|
contentPadding: const EdgeInsets.only(left: 32, right: 8),
|
||||||
ListTile(
|
tileColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||||
leading: const Icon(Icons.add_box),
|
title: Text('channelNew'.tr),
|
||||||
contentPadding: const EdgeInsets.only(left: 32, right: 8),
|
subtitle: Text(
|
||||||
tileColor: Theme.of(context).colorScheme.surfaceContainer,
|
'channelNewInRealmHint'.trParams({'realm': '#${realm.alias}'}),
|
||||||
title: Text('channelNew'.tr),
|
),
|
||||||
subtitle: Text(
|
onTap: () {
|
||||||
'channelNewInRealmHint'
|
AppRouter.instance
|
||||||
.trParams({'realm': '#${realm.alias}'}),
|
.pushNamed(
|
||||||
),
|
'channelOrganizing',
|
||||||
onTap: () {
|
extra: ChannelOrganizeArguments(realm: realm),
|
||||||
AppRouter.instance
|
|
||||||
.pushNamed(
|
|
||||||
'channelOrganizing',
|
|
||||||
extra: ChannelOrganizeArguments(realm: realm),
|
|
||||||
)
|
|
||||||
.then((value) {
|
|
||||||
if (value != null) onRefresh();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: ChannelListWidget(
|
|
||||||
channels: channels,
|
|
||||||
selfId: snapshot.data?.body['id'] ?? 0,
|
|
||||||
noCategory: true,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
],
|
.then((value) {
|
||||||
|
if (value != null) onRefresh();
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
Expanded(
|
||||||
},
|
child: ChannelListWidget(
|
||||||
|
channels: channels,
|
||||||
|
selfId: auth.userProfile.value!['id'],
|
||||||
|
noCategory: true,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ class _RelativeSelectorState extends State<RelativeSelector> {
|
|||||||
|
|
||||||
getFriends() async {
|
getFriends() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
final prof = await auth.getProfile();
|
_accountId = auth.userProfile.value!['id'];
|
||||||
_accountId = prof.body['id'];
|
|
||||||
|
|
||||||
final RelationshipProvider provider = Get.find();
|
final RelationshipProvider provider = Get.find();
|
||||||
final resp = await provider.listRelationWithStatus(1);
|
final resp = await provider.listRelationWithStatus(1);
|
||||||
|
@ -44,7 +44,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
|||||||
|
|
||||||
Future<void> pickPhotoToUpload() async {
|
Future<void> pickPhotoToUpload() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final medias = await _imagePicker.pickMultiImage();
|
final medias = await _imagePicker.pickMultiImage();
|
||||||
if (medias.isEmpty) return;
|
if (medias.isEmpty) return;
|
||||||
@ -73,7 +73,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
|||||||
|
|
||||||
Future<void> pickVideoToUpload() async {
|
Future<void> pickVideoToUpload() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final media = await _imagePicker.pickVideo(source: ImageSource.gallery);
|
final media = await _imagePicker.pickVideo(source: ImageSource.gallery);
|
||||||
if (media == null) return;
|
if (media == null) return;
|
||||||
@ -96,7 +96,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
|||||||
|
|
||||||
Future<void> pickFileToUpload() async {
|
Future<void> pickFileToUpload() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||||
allowMultiple: true,
|
allowMultiple: true,
|
||||||
@ -121,7 +121,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
|||||||
|
|
||||||
Future<void> takeMediaToUpload(bool isVideo) async {
|
Future<void> takeMediaToUpload(bool isVideo) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
XFile? media;
|
XFile? media;
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
|
@ -25,7 +25,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
|
|||||||
|
|
||||||
Future<void> deleteChannel() async {
|
Future<void> deleteChannel() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
|
|||||||
|
|
||||||
Future<void> leaveChannel() async {
|
Future<void> leaveChannel() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
|
@ -31,10 +31,9 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
|
|||||||
|
|
||||||
void getProfile() async {
|
void getProfile() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final prof = await auth.getProfile();
|
setState(() => _accountId = auth.userProfile.value!['id']);
|
||||||
setState(() => _accountId = prof.body['id']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void getMembers() async {
|
void getMembers() async {
|
||||||
@ -72,7 +71,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
|
|||||||
|
|
||||||
void addMember(String username) async {
|
void addMember(String username) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
@ -93,7 +92,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
|
|||||||
|
|
||||||
void removeMember(ChannelMember item) async {
|
void removeMember(ChannelMember item) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class _ChatCallPrejoinPopupState extends State<ChatCallPrejoinPopup> {
|
|||||||
void performJoin() async {
|
void performJoin() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
final ChatCallProvider provider = Get.find();
|
final ChatCallProvider provider = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
|
|||||||
|
|
||||||
Future<void> makeCall() async {
|
Future<void> makeCall() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
|
|||||||
|
|
||||||
Future<void> endsCall() async {
|
Future<void> endsCall() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
|
@ -35,15 +35,14 @@ class _ChatEventActionState extends State<ChatEventAction> {
|
|||||||
void checkAbleToModifyContent() async {
|
void checkAbleToModifyContent() async {
|
||||||
if (!['messages.new'].contains(widget.item.type)) return;
|
if (!['messages.new'].contains(widget.item.type)) return;
|
||||||
|
|
||||||
final AuthProvider provider = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await provider.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
final prof = await provider.getProfile();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_canModifyContent =
|
_canModifyContent = auth.userProfile.value!['id'] ==
|
||||||
prof.body?['id'] == widget.item.sender.account.externalId;
|
widget.item.sender.account.externalId;
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class _ChatEventDeletionDialogState extends State<ChatEventDeletionDialog> {
|
|||||||
|
|
||||||
void performAction() async {
|
void performAction() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
|||||||
_focusNode.requestFocus();
|
_focusNode.requestFocus();
|
||||||
|
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
final prof = await auth.getProfile();
|
final prof = auth.userProfile.value!;
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final client = auth.configureClient('messaging');
|
final client = auth.configureClient('messaging');
|
||||||
|
|
||||||
@ -87,9 +87,9 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
|||||||
id: 0,
|
id: 0,
|
||||||
createdAt: DateTime.now(),
|
createdAt: DateTime.now(),
|
||||||
updatedAt: DateTime.now(),
|
updatedAt: DateTime.now(),
|
||||||
account: Account.fromJson(prof.body),
|
account: Account.fromJson(prof),
|
||||||
channelId: widget.channel.id,
|
channelId: widget.channel.id,
|
||||||
accountId: prof.body['id'],
|
accountId: prof['id'],
|
||||||
notify: 0,
|
notify: 0,
|
||||||
);
|
);
|
||||||
final message = Event(
|
final message = Event(
|
||||||
|
@ -17,47 +17,30 @@ class BackgroundStateWidget extends StatelessWidget {
|
|||||||
final connecting = ws.isConnecting.isTrue;
|
final connecting = ws.isConnecting.isTrue;
|
||||||
|
|
||||||
return Row(children: [
|
return Row(children: [
|
||||||
if (disconnected && !connecting)
|
if (auth.isAuthorized.isTrue && disconnected && !connecting)
|
||||||
FutureBuilder(
|
IconButton(
|
||||||
future: auth.isAuthorized,
|
tooltip: [
|
||||||
builder: (context, snapshot) {
|
if (ws.isConnected.isFalse)
|
||||||
if (!snapshot.hasData || snapshot.data == false) {
|
'Lost Connection with Solar Network...',
|
||||||
return const SizedBox();
|
].join('\n'),
|
||||||
}
|
icon: const Icon(Icons.wifi_off)
|
||||||
return IconButton(
|
.animate(onPlay: (c) => c.repeat())
|
||||||
tooltip: [
|
.fadeIn(duration: 800.ms)
|
||||||
if (ws.isConnected.isFalse)
|
.then()
|
||||||
'Lost Connection with Solar Network...',
|
.fadeOut(duration: 800.ms),
|
||||||
].join('\n'),
|
onPressed: () {
|
||||||
icon: const Icon(Icons.wifi_off)
|
if (ws.isConnected.isFalse) ws.connect();
|
||||||
.animate(onPlay: (c) => c.repeat())
|
|
||||||
.fadeIn(duration: 800.ms)
|
|
||||||
.then()
|
|
||||||
.fadeOut(duration: 800.ms),
|
|
||||||
onPressed: () {
|
|
||||||
if (ws.isConnected.isFalse) ws.connect();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (connecting)
|
if (auth.isAuthorized.isTrue && connecting)
|
||||||
FutureBuilder(
|
IconButton(
|
||||||
future: auth.isAuthorized,
|
tooltip: [
|
||||||
builder: (context, snapshot) {
|
if (ws.isConnecting.isTrue) 'Waiting Solar Network Connection...',
|
||||||
if (!snapshot.hasData || snapshot.data == false) {
|
].join('\n'),
|
||||||
return const SizedBox();
|
icon: const Icon(Icons.sync)
|
||||||
}
|
.animate(onPlay: (c) => c.repeat())
|
||||||
return IconButton(
|
.rotate(duration: 1850.ms, begin: 1, end: 0),
|
||||||
tooltip: [
|
onPressed: () {},
|
||||||
if (ws.isConnecting.isTrue)
|
|
||||||
'Waiting Solar Network Connection...',
|
|
||||||
].join('\n'),
|
|
||||||
icon: const Icon(Icons.sync)
|
|
||||||
.animate(onPlay: (c) => c.repeat())
|
|
||||||
.rotate(duration: 1850.ms, begin: 1, end: 0),
|
|
||||||
onPressed: () {},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -27,7 +27,6 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
|||||||
|
|
||||||
AccountStatus? _accountStatus;
|
AccountStatus? _accountStatus;
|
||||||
|
|
||||||
late final AuthProvider _auth;
|
|
||||||
late final ChannelProvider _channels;
|
late final ChannelProvider _channels;
|
||||||
|
|
||||||
void getStatus() async {
|
void getStatus() async {
|
||||||
@ -57,7 +56,6 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_auth = Get.find();
|
|
||||||
_channels = Get.find();
|
_channels = Get.find();
|
||||||
detectSelectedIndex();
|
detectSelectedIndex();
|
||||||
getStatus();
|
getStatus();
|
||||||
@ -83,86 +81,83 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
|||||||
closeDrawer();
|
closeDrawer();
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
FutureBuilder(
|
Obx(() {
|
||||||
future: auth.getProfileWithCheck(),
|
if (auth.isAuthorized.isFalse) {
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.data == null) {
|
|
||||||
return ListTile(
|
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 28),
|
|
||||||
leading: const Icon(Icons.account_circle),
|
|
||||||
title: Text('guest'.tr),
|
|
||||||
subtitle: Text('unsignedIn'.tr),
|
|
||||||
onTap: () {
|
|
||||||
AppRouter.instance.goNamed('account');
|
|
||||||
setState(() => _selectedIndex = null);
|
|
||||||
closeDrawer();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 28),
|
||||||
title: Text(
|
leading: const Icon(Icons.account_circle),
|
||||||
snapshot.data!.body['nick'],
|
title: Text('guest'.tr),
|
||||||
maxLines: 1,
|
subtitle: Text('unsignedIn'.tr),
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
),
|
|
||||||
subtitle: Builder(
|
|
||||||
builder: (context) {
|
|
||||||
if (_accountStatus == null) {
|
|
||||||
return Text('loading'.tr);
|
|
||||||
}
|
|
||||||
final info = StatusProvider.determineStatus(
|
|
||||||
_accountStatus!,
|
|
||||||
);
|
|
||||||
return Text(
|
|
||||||
info.$3,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
leading: Builder(builder: (context) {
|
|
||||||
final badgeColor = _accountStatus != null
|
|
||||||
? StatusProvider.determineStatus(
|
|
||||||
_accountStatus!,
|
|
||||||
).$2
|
|
||||||
: Colors.grey;
|
|
||||||
|
|
||||||
return badges.Badge(
|
|
||||||
showBadge: _accountStatus != null,
|
|
||||||
badgeStyle: badges.BadgeStyle(badgeColor: badgeColor),
|
|
||||||
position: badges.BadgePosition.bottomEnd(
|
|
||||||
bottom: 0,
|
|
||||||
end: -2,
|
|
||||||
),
|
|
||||||
child: AccountAvatar(
|
|
||||||
content: snapshot.data!.body['avatar'],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
trailing: IconButton(
|
|
||||||
icon: const Icon(Icons.face_retouching_natural),
|
|
||||||
onPressed: () {
|
|
||||||
showModalBottomSheet(
|
|
||||||
useRootNavigator: true,
|
|
||||||
context: context,
|
|
||||||
builder: (context) => AccountStatusAction(
|
|
||||||
currentStatus: _accountStatus!.status,
|
|
||||||
),
|
|
||||||
).then((val) {
|
|
||||||
if (val == true) getStatus();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AppRouter.instance.goNamed('account');
|
AppRouter.instance.goNamed('account');
|
||||||
setState(() => _selectedIndex = null);
|
setState(() => _selectedIndex = null);
|
||||||
closeDrawer();
|
closeDrawer();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
).paddingOnly(top: 8),
|
|
||||||
|
return ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
title: Text(
|
||||||
|
auth.userProfile.value!['nick'],
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
),
|
||||||
|
subtitle: Builder(
|
||||||
|
builder: (context) {
|
||||||
|
if (_accountStatus == null) {
|
||||||
|
return Text('loading'.tr);
|
||||||
|
}
|
||||||
|
final info = StatusProvider.determineStatus(
|
||||||
|
_accountStatus!,
|
||||||
|
);
|
||||||
|
return Text(
|
||||||
|
info.$3,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
leading: Builder(builder: (context) {
|
||||||
|
final badgeColor = _accountStatus != null
|
||||||
|
? StatusProvider.determineStatus(
|
||||||
|
_accountStatus!,
|
||||||
|
).$2
|
||||||
|
: Colors.grey;
|
||||||
|
|
||||||
|
return badges.Badge(
|
||||||
|
showBadge: _accountStatus != null,
|
||||||
|
badgeStyle: badges.BadgeStyle(badgeColor: badgeColor),
|
||||||
|
position: badges.BadgePosition.bottomEnd(
|
||||||
|
bottom: 0,
|
||||||
|
end: -2,
|
||||||
|
),
|
||||||
|
child: AccountAvatar(
|
||||||
|
content: auth.userProfile.value!['avatar'],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: const Icon(Icons.face_retouching_natural),
|
||||||
|
onPressed: () {
|
||||||
|
showModalBottomSheet(
|
||||||
|
useRootNavigator: true,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AccountStatusAction(
|
||||||
|
currentStatus: _accountStatus!.status,
|
||||||
|
),
|
||||||
|
).then((val) {
|
||||||
|
if (val == true) getStatus();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
AppRouter.instance.goNamed('account');
|
||||||
|
setState(() => _selectedIndex = null);
|
||||||
|
closeDrawer();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}).paddingOnly(top: 8),
|
||||||
const Divider(thickness: 0.3, height: 1).paddingOnly(
|
const Divider(thickness: 0.3, height: 1).paddingOnly(
|
||||||
bottom: 12,
|
bottom: 12,
|
||||||
top: 8,
|
top: 8,
|
||||||
@ -176,49 +171,46 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
|||||||
const Divider(thickness: 0.3, height: 1).paddingOnly(
|
const Divider(thickness: 0.3, height: 1).paddingOnly(
|
||||||
top: 12,
|
top: 12,
|
||||||
),
|
),
|
||||||
FutureBuilder(
|
Obx(() {
|
||||||
future: _auth.getProfileWithCheck(),
|
if (auth.isAuthorized.isFalse) {
|
||||||
builder: (context, snapshot) {
|
return const SizedBox();
|
||||||
if (!snapshot.hasData || snapshot.data == null) {
|
}
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
final selfId = snapshot.data!.body['id'];
|
final selfId = auth.userProfile.value!['id'];
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Theme(
|
Theme(
|
||||||
data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
|
data: Theme.of(context)
|
||||||
child: ExpansionTile(
|
.copyWith(dividerColor: Colors.transparent),
|
||||||
title: Text('channels'.tr),
|
child: ExpansionTile(
|
||||||
tilePadding: const EdgeInsets.symmetric(horizontal: 24),
|
title: Text('channels'.tr),
|
||||||
children: [
|
tilePadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
Obx(
|
children: [
|
||||||
() => SizedBox(
|
Obx(
|
||||||
height: 360,
|
() => SizedBox(
|
||||||
child: RefreshIndicator(
|
height: 360,
|
||||||
onRefresh: () =>
|
child: RefreshIndicator(
|
||||||
_channels.refreshAvailableChannel(),
|
onRefresh: () => _channels.refreshAvailableChannel(),
|
||||||
child: ChannelListWidget(
|
child: ChannelListWidget(
|
||||||
channels: _channels.groupChannels,
|
channels: _channels.groupChannels,
|
||||||
selfId: selfId,
|
selfId: selfId,
|
||||||
isDense: true,
|
isDense: true,
|
||||||
useReplace: true,
|
useReplace: true,
|
||||||
onSelected: (_) {
|
onSelected: (_) {
|
||||||
setState(() => _selectedIndex = null);
|
setState(() => _selectedIndex = null);
|
||||||
closeDrawer();
|
closeDrawer();
|
||||||
},
|
},
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
);
|
],
|
||||||
},
|
);
|
||||||
),
|
}),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,13 @@ class _PostActionState extends State<PostAction> {
|
|||||||
bool _canModifyContent = false;
|
bool _canModifyContent = false;
|
||||||
|
|
||||||
void checkAbleToModifyContent() async {
|
void checkAbleToModifyContent() async {
|
||||||
final AuthProvider provider = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await provider.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
final prof = await provider.getProfile();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_canModifyContent = prof.body?['id'] == widget.item.author.externalId;
|
_canModifyContent = auth.userProfile.value!['id'] == widget.item.author.externalId;
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -153,7 +152,7 @@ class _PostDeletionDialogState extends State<PostDeletionDialog> {
|
|||||||
|
|
||||||
void performAction() async {
|
void performAction() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final client = auth.configureClient('interactive');
|
final client = auth.configureClient('interactive');
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class _PostQuickActionState extends State<PostQuickAction> {
|
|||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
|
|
||||||
if (_isSubmitting) return;
|
if (_isSubmitting) return;
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final client = auth.configureClient('interactive');
|
final client = auth.configureClient('interactive');
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
|
|||||||
|
|
||||||
Future<void> deleteRealm() async {
|
Future<void> deleteRealm() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
|
|||||||
|
|
||||||
Future<void> leaveRealm() async {
|
Future<void> leaveRealm() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
|
@ -29,10 +29,9 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
|
|||||||
|
|
||||||
void getProfile() async {
|
void getProfile() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final prof = await auth.getProfile();
|
setState(() => _accountId = auth.userProfile.value!['id']);
|
||||||
setState(() => _accountId = prof.body['id']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void getMembers() async {
|
void getMembers() async {
|
||||||
@ -69,7 +68,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
|
|||||||
|
|
||||||
void addMember(String username) async {
|
void addMember(String username) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
|
|||||||
|
|
||||||
void removeMember(RealmMember item) async {
|
void removeMember(RealmMember item) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (!await auth.isAuthorized) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user