switched accessToken back to be non-nullable

This commit is contained in:
ggurdin 2024-07-11 13:11:20 -04:00
parent 91e2aa2dfd
commit 303d2b1e17
15 changed files with 47 additions and 121 deletions

View file

@ -406,8 +406,7 @@ class Choreographer {
PangeaTextController get textController => _textController;
Future<String?> get accessToken =>
pangeaController.userController.accessToken;
Future<String> get accessToken => pangeaController.userController.accessToken;
clear() {
choreoMode = ChoreoMode.igc;

View file

@ -73,15 +73,7 @@ class ITFeedbackCardController extends State<ITFeedbackCard> {
isTranslating = true;
});
final String? accessToken = await controller.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
m: "Cannot translate feedback because accessToken is null",
);
error = "Cannot translate feedback because accessToken is null";
return;
}
final String accessToken = await controller.userController.accessToken;
FullTextTranslationRepo.translate(
accessToken: accessToken,
request: FullTextTranslationRequestModel(

View file

@ -50,13 +50,6 @@ class ContextualDefinitionController {
) async {
try {
final accessToken = await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in contextual definition controller",
s: StackTrace.current,
);
return null;
}
final ContextualDefinitionResponseModel res =
await _ContextualDefinitionRepo.define(
accessToken,

View file

@ -51,15 +51,8 @@ class ITFeedbackController {
ITFeedbackRequestModel request,
) async {
try {
final String? accessToken =
final String accessToken =
await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in it feedback controller",
s: StackTrace.current,
);
return null;
}
final ITFeedbackResponseModel res = await _ITFeedbackRepo.get(
accessToken,
request,

View file

@ -6,7 +6,6 @@ import 'package:fluffychat/pangea/constants/language_constants.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/models/language_detection_model.dart';
import 'package:fluffychat/pangea/network/urls.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:http/http.dart' as http;
import '../network/requests.dart';
@ -145,15 +144,8 @@ class LanguageDetectionController {
if (_cache.containsKey(params)) {
return _cache[params]!.data;
} else {
final String? accessToken =
final String accessToken =
await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in language detection controller",
s: StackTrace.current,
);
return null;
}
final Future<LanguageDetectionResponse> response = _fetchResponse(
accessToken,
params,

View file

@ -43,15 +43,6 @@ class MessageDataController extends BaseController {
TokensRequestModel req,
) async {
final accessToken = await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in _getTokens",
s: StackTrace.current,
);
return null;
}
final TokensResponseModel igcTextData =
await TokensRepo.tokenize(accessToken, req);
@ -201,15 +192,8 @@ class MessageDataController extends BaseController {
);
try {
final String? accessToken =
final String accessToken =
await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in _getPangeaRepresentation",
s: StackTrace.current,
);
return null;
}
final FullTextTranslationResponseModel res =
await FullTextTranslationRepo.translate(

View file

@ -52,15 +52,8 @@ class SpeechToTextController {
if (_cache.containsKey(cacheKey)) {
return _cache[cacheKey]!.data;
} else {
final String? accessToken =
final String accessToken =
await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: 'null accessToken in speech to text controller',
s: StackTrace.current,
);
return null;
}
final Future<SpeechToTextModel> response = _fetchResponse(
accessToken: accessToken,

View file

@ -6,7 +6,6 @@ import 'package:fluffychat/pangea/config/environment.dart';
import 'package:fluffychat/pangea/constants/model_keys.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/network/urls.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:http/http.dart';
import '../network/requests.dart';
@ -100,15 +99,8 @@ class TextToSpeechController {
if (_cache.containsKey(params)) {
return _cache[params]!.data;
} else {
final String? accessToken =
final String accessToken =
await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in text to speech controller",
s: StackTrace.current,
);
return null;
}
final Future<TextToSpeechResponse> response = _fetchResponse(
accessToken,
params,

View file

@ -222,8 +222,6 @@ class UserController extends BaseController {
/// The [interests] parameter is a list of new interests for the user.
/// The [speaks] parameter is a list of new languages the user speaks.
/// The [publicProfile] parameter indicates whether the user's profile should be public or not.
///
/// Throws an error if [userModel] or [accessToken] is null.
Future<void> updateUserProfile({
String? dateOfBirth,
String? targetLanguage,
@ -233,10 +231,9 @@ class UserController extends BaseController {
List<String>? speaks,
bool? publicProfile,
}) async {
final String? accessToken = await this.accessToken;
if (userModel == null || accessToken == null) {
if (userModel == null) {
ErrorHandler.logError(
e: "calling updateUserProfile with userModel == null or accessToken == null",
e: "calling updateUserProfile with userModel == null",
);
return;
}
@ -267,11 +264,11 @@ class UserController extends BaseController {
final Profile updatedUserProfile = await PUserRepo.updateUserProfile(
Profile.fromJson(profileJson),
accessToken,
await accessToken,
);
PUserModel(
access: accessToken,
access: await accessToken,
refresh: userModel!.refresh,
profile: updatedUserProfile,
).save(_pangeaController);
@ -295,19 +292,17 @@ class UserController extends BaseController {
///
/// If the locally stored user model is null or the access token has
/// expired, it fetches the user model.
/// If the user model is still null after fetching, an error is logged.
/// If the user model is still null after fetching, an error thrown.
///
/// Returns the access token as a string, or null if the user model is null.
Future<String?> get accessToken async {
Future<String> get accessToken async {
final PUserModel? useThisOne =
needNewJWT ? await fetchUserModel() : userModel;
if (useThisOne == null) {
ErrorHandler.logError(
e: "trying to get accessToken with userModel = null",
);
throw ("Trying to get accessToken with null userModel");
}
return useThisOne?.access;
return useThisOne.access;
}
/// Returns the full name of the user.

View file

@ -1,7 +1,6 @@
import 'package:collection/collection.dart';
import 'package:fluffychat/pangea/constants/language_constants.dart';
import 'package:fluffychat/pangea/repo/word_repo.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:http/http.dart' as http;
import '../models/word_data_model.dart';
@ -54,16 +53,8 @@ class WordController extends BaseController {
if (local != null) return local;
final String? accessToken =
final String accessToken =
await _pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in word controller",
s: StackTrace.current,
);
return null;
}
final WordData remote = await WordRepo.getWordNetData(
accessToken: accessToken,
fullText: fullText,

View file

@ -5,6 +5,7 @@ import 'package:fluffychat/pangea/models/language_model.dart';
import 'package:fluffychat/pangea/models/user_model.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../../../widgets/matrix.dart';
import '../../controllers/pangea_controller.dart';
@ -39,6 +40,7 @@ class FindPartnerController extends State<FindPartner> {
final List<Profile> _userProfilesCache = [];
final scrollController = ScrollController();
String? error;
@override
void initState() {
@ -67,6 +69,17 @@ class FindPartnerController extends State<FindPartner> {
@override
Widget build(BuildContext context) {
if (error != null && error!.isNotEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(L10n.of(context)!.oopsSomethingWentWrong),
Text(L10n.of(context)!.errorPleaseRefresh),
],
),
);
}
return FindPartnerView(this);
}
@ -92,26 +105,25 @@ class FindPartnerController extends State<FindPartner> {
if (loading || nextUrl == null) return;
setState(() => loading = true);
final String? accessToken =
await pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in find partner controller",
s: StackTrace.current,
UserProfileSearchResponse response;
try {
final String accessToken =
await pangeaController.userController.accessToken;
response = await PUserRepo.searchUserProfiles(
accessToken: accessToken,
targetLanguage: targetLanguageSearch.langCode,
sourceLanguage: sourceLanguageSearch.langCode,
country: countrySearch,
limit: 15,
pageNumber: nextPage.toString(),
);
} catch (err, s) {
error = err.toString();
setState(() => loading = false);
ErrorHandler.logError(e: err, s: s);
return;
}
final UserProfileSearchResponse response =
await PUserRepo.searchUserProfiles(
accessToken: accessToken,
targetLanguage: targetLanguageSearch.langCode,
sourceLanguage: sourceLanguageSearch.langCode,
country: countrySearch,
limit: 15,
pageNumber: nextPage.toString(),
);
nextUrl = response.next;
nextPage++;

View file

@ -13,7 +13,7 @@ import '../network/urls.dart';
class SpanDataRepo {
static Future<SpanDetailsRepoReqAndRes> getSpanDetails(
String? accessToken, {
String accessToken, {
required SpanDetailsRepoReqAndRes request,
}) async {
final Requests req = Requests(

View file

@ -1,7 +1,6 @@
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:http/http.dart';
import '../config/environment.dart';
@ -12,7 +11,7 @@ import '../network/urls.dart';
/// accepts ChatTopic and calls an API for a list of Lemma
class TopicDataRepo {
static Future<ChatTopic> generate(
String? accessToken, {
String accessToken, {
required TopicDataRequest request,
}) async {
final Requests req = Requests(

View file

@ -46,7 +46,6 @@ class MessageAudioCardState extends State<MessageAudioCard> {
await widget.messageEvent.getMatrixAudioFile(langCode, context);
if (mounted) setState(() => _isLoading = false);
} catch (e, _) {
debugPrint(StackTrace.current.toString());
if (!mounted) return;
setState(() => _isLoading = false);
ScaffoldMessenger.of(context).showSnackBar(

View file

@ -58,17 +58,9 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
}
oldSelectedText = widget.selection.selectedText;
final String? accessToken =
final String accessToken =
await MatrixState.pangeaController.userController.accessToken;
if (accessToken == null) {
ErrorHandler.logError(
e: "null accessToken in translateSelection",
s: StackTrace.current,
);
return;
}
final resp = await FullTextTranslationRepo.translate(
accessToken: accessToken,
request: FullTextTranslationRequestModel(