Merge branch 'main' into dont-name-bot-analytics-rooms
This commit is contained in:
commit
b68faab251
3 changed files with 54 additions and 3 deletions
|
|
@ -83,6 +83,15 @@ class UserController extends BaseController {
|
|||
createdAt: DateTime.now(),
|
||||
);
|
||||
final newProfile = Profile(userSettings: userSettings);
|
||||
|
||||
// we don't use the pangea profile anymore, but we still need
|
||||
// it to get access token for the choreographer, so create one
|
||||
await PUserRepo.repoCreatePangeaUser(
|
||||
userID: userId!,
|
||||
dob: dob.toIso8601String(),
|
||||
fullName: fullname!,
|
||||
matrixAccessToken: _matrixAccessToken!,
|
||||
);
|
||||
await newProfile.saveProfileData(waitForDataInSync: true);
|
||||
}
|
||||
|
||||
|
|
@ -155,13 +164,25 @@ class UserController extends BaseController {
|
|||
_pangeaController.pStoreService.read(PLocalKey.access);
|
||||
|
||||
if (localAccessToken == null || needNewJWT(localAccessToken)) {
|
||||
final PangeaProfileResponse? userModel =
|
||||
await PUserRepo.fetchPangeaUserInfo(
|
||||
PangeaProfileResponse? userModel = await PUserRepo.fetchPangeaUserInfo(
|
||||
userID: userId!,
|
||||
matrixAccessToken: _matrixAccessToken!,
|
||||
);
|
||||
// Oops, some accounts were made without creating pangea profiles, so they
|
||||
// don't have access to an access token yet. In that case, create a pangea profile.
|
||||
if (userModel?.access == null) {
|
||||
throw ("Trying to get accessToken with null userModel");
|
||||
final dob = profile.userSettings.dateOfBirth;
|
||||
if (dob != null) {
|
||||
userModel = await PUserRepo.repoCreatePangeaUser(
|
||||
userID: userId!,
|
||||
dob: dob.toIso8601String(),
|
||||
fullName: fullname!,
|
||||
matrixAccessToken: _matrixAccessToken!,
|
||||
);
|
||||
if (userModel?.access == null) {
|
||||
throw ("Trying to get accessToken with null userModel");
|
||||
}
|
||||
}
|
||||
}
|
||||
_pangeaController.pStoreService.save(
|
||||
PLocalKey.access,
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ extension AnalyticsClientExtension on Client {
|
|||
/// Handles case when students cannot add analytics room to space(s)
|
||||
/// so teacher is still able to get analytics data for this student
|
||||
void _inviteAllTeachersToAllAnalyticsRooms() {
|
||||
if (userID == null || userID == BotName.byEnvironment) return;
|
||||
for (final Room room in allMyAnalyticsRooms) {
|
||||
room.inviteTeachersToAnalyticsRoom();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../models/user_model.dart';
|
||||
|
|
@ -10,6 +11,34 @@ import '../network/requests.dart';
|
|||
import '../network/urls.dart';
|
||||
|
||||
class PUserRepo {
|
||||
static Future<PangeaProfileResponse?> repoCreatePangeaUser({
|
||||
required String userID,
|
||||
required String dob,
|
||||
required fullName,
|
||||
required String matrixAccessToken,
|
||||
}) async {
|
||||
try {
|
||||
final Requests req = Requests(
|
||||
baseUrl: PApiUrls.baseAPI,
|
||||
matrixAccessToken: matrixAccessToken,
|
||||
);
|
||||
|
||||
final Map<String, dynamic> body = {
|
||||
ModelKey.userFullName: fullName,
|
||||
ModelKey.userPangeaUserId: userID,
|
||||
ModelKey.userDateOfBirth: dob,
|
||||
};
|
||||
final resp = await req.post(
|
||||
url: PApiUrls.createUser,
|
||||
body: body,
|
||||
);
|
||||
return PangeaProfileResponse.fromJson(jsonDecode(resp.body));
|
||||
} catch (err, s) {
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<PangeaProfileResponse?> fetchPangeaUserInfo({
|
||||
required String userID,
|
||||
required String matrixAccessToken,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue