forked from firka/student-legacy
calendar sync fixes
This commit is contained in:
parent
010867260c
commit
7ebc470a7b
@ -136,7 +136,7 @@ Future<Database> initDB(DatabaseProvider database) async {
|
||||
// v5 shit
|
||||
"roundings": "{}",
|
||||
"grade_rarities": "{}",
|
||||
"linked_accounts": "{}",
|
||||
"linked_accounts": "[]",
|
||||
});
|
||||
} catch (error) {
|
||||
print("ERROR: migrateDB: $error");
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'package:refilc/models/linked_account.dart';
|
||||
import 'package:refilc/models/self_note.dart';
|
||||
import 'package:refilc/models/subject_lesson_count.dart';
|
||||
import 'package:refilc_kreta_api/models/week.dart';
|
||||
@ -208,4 +209,11 @@ class UserDatabaseStore {
|
||||
await db.update("user_data", {"grade_rarities": raritiesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeLinkedAccounts(List<LinkedAccount> accounts,
|
||||
{required String userId}) async {
|
||||
String accountsJson = jsonEncode(accounts.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"linked_accounts": accountsJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,14 @@ class LinkedAccount {
|
||||
String username;
|
||||
String displayName;
|
||||
String id;
|
||||
Map? json;
|
||||
|
||||
LinkedAccount({
|
||||
required this.type,
|
||||
required this.username,
|
||||
required this.displayName,
|
||||
required this.id,
|
||||
required this.json,
|
||||
});
|
||||
|
||||
factory LinkedAccount.fromJson(Map json) {
|
||||
@ -30,6 +32,7 @@ class LinkedAccount {
|
||||
username: json['username'],
|
||||
displayName: json['display_name'],
|
||||
id: json['id'],
|
||||
json: json,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ class ThirdPartyProvider with ChangeNotifier {
|
||||
}) {
|
||||
_context = context;
|
||||
_linkedAccounts = initialLinkedAccounts ?? [];
|
||||
|
||||
if (_linkedAccounts.isEmpty) restore();
|
||||
}
|
||||
|
||||
Future<void> restore() async {
|
||||
@ -56,12 +58,12 @@ class ThirdPartyProvider with ChangeNotifier {
|
||||
if (!await _googleSignIn.isSignedIn()) {
|
||||
GoogleSignInAccount? account = await _googleSignIn.signIn();
|
||||
|
||||
LinkedAccount linked = LinkedAccount(
|
||||
type: AccountType.google,
|
||||
username: account?.email ?? '',
|
||||
displayName: account?.displayName ?? '',
|
||||
id: account?.id ?? '',
|
||||
);
|
||||
LinkedAccount linked = LinkedAccount.fromJson({
|
||||
'type': 'google',
|
||||
'username': account?.email ?? '',
|
||||
'display_name': account?.displayName ?? '',
|
||||
'id': account?.id ?? ''
|
||||
});
|
||||
_linkedAccounts.add(linked);
|
||||
|
||||
return account;
|
||||
|
Loading…
x
Reference in New Issue
Block a user