♻️ Refactored auth system
This commit is contained in:
@ -23,8 +23,7 @@ class _RelativeSelectorState extends State<RelativeSelector> {
|
||||
|
||||
getFriends() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
final prof = await auth.getProfile();
|
||||
_accountId = prof.body['id'];
|
||||
_accountId = auth.userProfile.value!['id'];
|
||||
|
||||
final RelationshipProvider provider = Get.find();
|
||||
final resp = await provider.listRelationWithStatus(1);
|
||||
|
@ -44,7 +44,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
||||
|
||||
Future<void> pickPhotoToUpload() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final medias = await _imagePicker.pickMultiImage();
|
||||
if (medias.isEmpty) return;
|
||||
@ -73,7 +73,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
||||
|
||||
Future<void> pickVideoToUpload() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final media = await _imagePicker.pickVideo(source: ImageSource.gallery);
|
||||
if (media == null) return;
|
||||
@ -96,7 +96,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
||||
|
||||
Future<void> pickFileToUpload() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
allowMultiple: true,
|
||||
@ -121,7 +121,7 @@ class _AttachmentPublishPopupState extends State<AttachmentPublishPopup> {
|
||||
|
||||
Future<void> takeMediaToUpload(bool isVideo) async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
XFile? media;
|
||||
if (isVideo) {
|
||||
|
@ -25,7 +25,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
|
||||
|
||||
Future<void> deleteChannel() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
@ -44,7 +44,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
|
||||
|
||||
Future<void> leaveChannel() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
|
@ -31,10 +31,9 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
|
||||
|
||||
void getProfile() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final prof = await auth.getProfile();
|
||||
setState(() => _accountId = prof.body['id']);
|
||||
setState(() => _accountId = auth.userProfile.value!['id']);
|
||||
}
|
||||
|
||||
void getMembers() async {
|
||||
@ -72,7 +71,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
|
||||
|
||||
void addMember(String username) async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
@ -93,7 +92,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
|
||||
|
||||
void removeMember(ChannelMember item) async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
|
@ -28,7 +28,7 @@ class _ChatCallPrejoinPopupState extends State<ChatCallPrejoinPopup> {
|
||||
void performJoin() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
final ChatCallProvider provider = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
|
@ -31,7 +31,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
|
||||
|
||||
Future<void> makeCall() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final client = auth.configureClient('messaging');
|
||||
|
||||
@ -55,7 +55,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
|
||||
|
||||
Future<void> endsCall() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final client = auth.configureClient('messaging');
|
||||
|
||||
|
@ -35,15 +35,14 @@ class _ChatEventActionState extends State<ChatEventAction> {
|
||||
void checkAbleToModifyContent() async {
|
||||
if (!['messages.new'].contains(widget.item.type)) return;
|
||||
|
||||
final AuthProvider provider = Get.find();
|
||||
if (!await provider.isAuthorized) return;
|
||||
final AuthProvider auth = Get.find();
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
final prof = await provider.getProfile();
|
||||
setState(() {
|
||||
_canModifyContent =
|
||||
prof.body?['id'] == widget.item.sender.account.externalId;
|
||||
_canModifyContent = auth.userProfile.value!['id'] ==
|
||||
widget.item.sender.account.externalId;
|
||||
_isBusy = false;
|
||||
});
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class _ChatEventDeletionDialogState extends State<ChatEventDeletionDialog> {
|
||||
|
||||
void performAction() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final client = auth.configureClient('messaging');
|
||||
|
||||
|
@ -59,8 +59,8 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
||||
_focusNode.requestFocus();
|
||||
|
||||
final AuthProvider auth = Get.find();
|
||||
final prof = await auth.getProfile();
|
||||
if (!await auth.isAuthorized) return;
|
||||
final prof = auth.userProfile.value!;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final client = auth.configureClient('messaging');
|
||||
|
||||
@ -87,9 +87,9 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
||||
id: 0,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
account: Account.fromJson(prof.body),
|
||||
account: Account.fromJson(prof),
|
||||
channelId: widget.channel.id,
|
||||
accountId: prof.body['id'],
|
||||
accountId: prof['id'],
|
||||
notify: 0,
|
||||
);
|
||||
final message = Event(
|
||||
|
@ -17,47 +17,30 @@ class BackgroundStateWidget extends StatelessWidget {
|
||||
final connecting = ws.isConnecting.isTrue;
|
||||
|
||||
return Row(children: [
|
||||
if (disconnected && !connecting)
|
||||
FutureBuilder(
|
||||
future: auth.isAuthorized,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data == false) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return IconButton(
|
||||
tooltip: [
|
||||
if (ws.isConnected.isFalse)
|
||||
'Lost Connection with Solar Network...',
|
||||
].join('\n'),
|
||||
icon: const Icon(Icons.wifi_off)
|
||||
.animate(onPlay: (c) => c.repeat())
|
||||
.fadeIn(duration: 800.ms)
|
||||
.then()
|
||||
.fadeOut(duration: 800.ms),
|
||||
onPressed: () {
|
||||
if (ws.isConnected.isFalse) ws.connect();
|
||||
},
|
||||
);
|
||||
if (auth.isAuthorized.isTrue && disconnected && !connecting)
|
||||
IconButton(
|
||||
tooltip: [
|
||||
if (ws.isConnected.isFalse)
|
||||
'Lost Connection with Solar Network...',
|
||||
].join('\n'),
|
||||
icon: const Icon(Icons.wifi_off)
|
||||
.animate(onPlay: (c) => c.repeat())
|
||||
.fadeIn(duration: 800.ms)
|
||||
.then()
|
||||
.fadeOut(duration: 800.ms),
|
||||
onPressed: () {
|
||||
if (ws.isConnected.isFalse) ws.connect();
|
||||
},
|
||||
),
|
||||
if (connecting)
|
||||
FutureBuilder(
|
||||
future: auth.isAuthorized,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data == false) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return IconButton(
|
||||
tooltip: [
|
||||
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: () {},
|
||||
);
|
||||
},
|
||||
if (auth.isAuthorized.isTrue && connecting)
|
||||
IconButton(
|
||||
tooltip: [
|
||||
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;
|
||||
|
||||
late final AuthProvider _auth;
|
||||
late final ChannelProvider _channels;
|
||||
|
||||
void getStatus() async {
|
||||
@ -57,7 +56,6 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_auth = Get.find();
|
||||
_channels = Get.find();
|
||||
detectSelectedIndex();
|
||||
getStatus();
|
||||
@ -83,86 +81,83 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
||||
closeDrawer();
|
||||
},
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: auth.getProfileWithCheck(),
|
||||
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();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Obx(() {
|
||||
if (auth.isAuthorized.isFalse) {
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
title: Text(
|
||||
snapshot.data!.body['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: 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();
|
||||
});
|
||||
},
|
||||
),
|
||||
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();
|
||||
},
|
||||
);
|
||||
},
|
||||
).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(
|
||||
bottom: 12,
|
||||
top: 8,
|
||||
@ -176,49 +171,46 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
||||
const Divider(thickness: 0.3, height: 1).paddingOnly(
|
||||
top: 12,
|
||||
),
|
||||
FutureBuilder(
|
||||
future: _auth.getProfileWithCheck(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
Obx(() {
|
||||
if (auth.isAuthorized.isFalse) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
final selfId = snapshot.data!.body['id'];
|
||||
final selfId = auth.userProfile.value!['id'];
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Theme(
|
||||
data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
title: Text('channels'.tr),
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
children: [
|
||||
Obx(
|
||||
() => SizedBox(
|
||||
height: 360,
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () =>
|
||||
_channels.refreshAvailableChannel(),
|
||||
child: ChannelListWidget(
|
||||
channels: _channels.groupChannels,
|
||||
selfId: selfId,
|
||||
isDense: true,
|
||||
useReplace: true,
|
||||
onSelected: (_) {
|
||||
setState(() => _selectedIndex = null);
|
||||
closeDrawer();
|
||||
},
|
||||
),
|
||||
return Column(
|
||||
children: [
|
||||
Theme(
|
||||
data: Theme.of(context)
|
||||
.copyWith(dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
title: Text('channels'.tr),
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
children: [
|
||||
Obx(
|
||||
() => SizedBox(
|
||||
height: 360,
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => _channels.refreshAvailableChannel(),
|
||||
child: ChannelListWidget(
|
||||
channels: _channels.groupChannels,
|
||||
selfId: selfId,
|
||||
isDense: true,
|
||||
useReplace: true,
|
||||
onSelected: (_) {
|
||||
setState(() => _selectedIndex = null);
|
||||
closeDrawer();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -25,14 +25,13 @@ class _PostActionState extends State<PostAction> {
|
||||
bool _canModifyContent = false;
|
||||
|
||||
void checkAbleToModifyContent() async {
|
||||
final AuthProvider provider = Get.find();
|
||||
if (!await provider.isAuthorized) return;
|
||||
final AuthProvider auth = Get.find();
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
final prof = await provider.getProfile();
|
||||
setState(() {
|
||||
_canModifyContent = prof.body?['id'] == widget.item.author.externalId;
|
||||
_canModifyContent = auth.userProfile.value!['id'] == widget.item.author.externalId;
|
||||
_isBusy = false;
|
||||
});
|
||||
}
|
||||
@ -153,7 +152,7 @@ class _PostDeletionDialogState extends State<PostDeletionDialog> {
|
||||
|
||||
void performAction() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final client = auth.configureClient('interactive');
|
||||
|
||||
|
@ -47,7 +47,7 @@ class _PostQuickActionState extends State<PostQuickAction> {
|
||||
final AuthProvider auth = Get.find();
|
||||
|
||||
if (_isSubmitting) return;
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final client = auth.configureClient('interactive');
|
||||
|
||||
|
@ -23,7 +23,7 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
|
||||
|
||||
Future<void> deleteRealm() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
@ -41,7 +41,7 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
|
||||
|
||||
Future<void> leaveRealm() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
|
@ -29,10 +29,9 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
|
||||
|
||||
void getProfile() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
final prof = await auth.getProfile();
|
||||
setState(() => _accountId = prof.body['id']);
|
||||
setState(() => _accountId = auth.userProfile.value!['id']);
|
||||
}
|
||||
|
||||
void getMembers() async {
|
||||
@ -69,7 +68,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
|
||||
|
||||
void addMember(String username) async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
@ -90,7 +89,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
|
||||
|
||||
void removeMember(RealmMember item) async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
|
Reference in New Issue
Block a user