Merge branch 'main' of https://github.com/pangeachat/client into toolbar-selection
This commit is contained in:
commit
4e7ac79527
7 changed files with 68 additions and 17 deletions
|
|
@ -486,12 +486,6 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
|
||||
final timeline = this.timeline;
|
||||
if (timeline == null || timeline.events.isEmpty) {
|
||||
// #Pangea
|
||||
ErrorHandler.logError(
|
||||
e: PangeaWarningError("Timeline is null or empty"),
|
||||
s: StackTrace.current,
|
||||
);
|
||||
// Pangea#
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -233,11 +233,11 @@ class MyAnalyticsController {
|
|||
if (userL2 == null || _client.userID == null) return;
|
||||
|
||||
// analytics room for the user and current target language
|
||||
final Room analyticsRoom = await _client.getMyAnalyticsRoom(userL2!);
|
||||
final Room? analyticsRoom = await _client.getMyAnalyticsRoom(userL2!);
|
||||
|
||||
// get the last time analytics were updated for this room
|
||||
final DateTime? l2AnalyticsLastUpdated =
|
||||
await analyticsRoom.analyticsLastUpdated(
|
||||
await analyticsRoom?.analyticsLastUpdated(
|
||||
PangeaEventTypes.summaryAnalytics,
|
||||
_client.userID!,
|
||||
);
|
||||
|
|
@ -307,7 +307,7 @@ class MyAnalyticsController {
|
|||
// if there's new content to be sent, or if lastUpdated hasn't been
|
||||
// set yet for this room, send the analytics events
|
||||
if (summaryContent.isNotEmpty || l2AnalyticsLastUpdated == null) {
|
||||
await analyticsRoom.sendSummaryAnalyticsEvent(
|
||||
await analyticsRoom?.sendSummaryAnalyticsEvent(
|
||||
summaryContent,
|
||||
);
|
||||
}
|
||||
|
|
@ -347,7 +347,7 @@ class MyAnalyticsController {
|
|||
// );
|
||||
|
||||
if (recentConstructUses.isNotEmpty) {
|
||||
await analyticsRoom.sendConstructsEvent(
|
||||
await analyticsRoom?.sendConstructsEvent(
|
||||
recentConstructUses,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ part of "client_extension.dart";
|
|||
extension AnalyticsClientExtension on Client {
|
||||
/// Get the logged in user's analytics room matching
|
||||
/// a given langCode. If not present, create it.
|
||||
Future<Room> _getMyAnalyticsRoom(String langCode) async {
|
||||
Future<Room?> _getMyAnalyticsRoom(String langCode) async {
|
||||
final Room? analyticsRoom = _analyticsRoomLocal(langCode);
|
||||
if (analyticsRoom != null) return analyticsRoom;
|
||||
return _makeAnalyticsRoom(langCode);
|
||||
|
|
@ -35,7 +35,11 @@ extension AnalyticsClientExtension on Client {
|
|||
///
|
||||
/// If the room does not appear immediately after creation, this method waits for it to appear in sync.
|
||||
/// Returns the created [Room] object.
|
||||
Future<Room> _makeAnalyticsRoom(String langCode) async {
|
||||
Future<Room?> _makeAnalyticsRoom(String langCode) async {
|
||||
if (userID == null || userID == BotName.byEnvironment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String roomID = await createRoom(
|
||||
creationContent: {
|
||||
'type': PangeaRoomTypes.analytics,
|
||||
|
|
@ -74,6 +78,7 @@ extension AnalyticsClientExtension on Client {
|
|||
// migration function to change analytics rooms' vsibility to public
|
||||
// so they will appear in the space hierarchy
|
||||
Future<void> _updateAnalyticsRoomVisibility() async {
|
||||
if (userID == null || userID == BotName.byEnvironment) return;
|
||||
await Future.wait(
|
||||
allMyAnalyticsRooms.map((room) async {
|
||||
final visability = await getRoomVisibilityOnDirectory(room.id);
|
||||
|
|
@ -91,6 +96,7 @@ extension AnalyticsClientExtension on Client {
|
|||
/// so teachers can join them via space hierarchy.
|
||||
/// Allows teachers to join analytics rooms without being invited.
|
||||
void _addAnalyticsRoomsToAllSpaces() {
|
||||
if (userID == null || userID == BotName.byEnvironment) return;
|
||||
for (final Room room in allMyAnalyticsRooms) {
|
||||
room.addAnalyticsRoomToSpaces();
|
||||
}
|
||||
|
|
@ -100,6 +106,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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ extension PangeaClient on Client {
|
|||
|
||||
/// Get the logged in user's analytics room matching
|
||||
/// a given langCode. If not present, create it.
|
||||
Future<Room> getMyAnalyticsRoom(String langCode) async =>
|
||||
Future<Room?> getMyAnalyticsRoom(String langCode) async =>
|
||||
await _getMyAnalyticsRoom(langCode);
|
||||
|
||||
/// Get local analytics room for a given langCode and
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ description: Learn a language while texting your friends.
|
|||
# Pangea#
|
||||
publish_to: none
|
||||
# On version bump also increase the build number for F-Droid
|
||||
version: 1.21.1+3533
|
||||
version: 1.21.2+3534
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue