♻️ Refactored auth system

This commit is contained in:
2024-07-25 01:18:47 +08:00
parent ef58430060
commit 6d92a16a62
38 changed files with 444 additions and 523 deletions

View File

@ -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);

View File

@ -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');

View File

@ -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;
});
}

View File

@ -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');

View File

@ -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(