added db shit to recipient storing
This commit is contained in:
parent
c06e9bc807
commit
7f9c22bdcd
@ -45,7 +45,7 @@ const usersDB = DatabaseStruct("users", {
|
|||||||
});
|
});
|
||||||
const userDataDB = DatabaseStruct("user_data", {
|
const userDataDB = DatabaseStruct("user_data", {
|
||||||
"id": String, "grades": String, "timetable": String, "exams": String,
|
"id": String, "grades": String, "timetable": String, "exams": String,
|
||||||
"homework": String, "messages": String, "notes": String,
|
"homework": String, "messages": String, "recipients": String, "notes": String,
|
||||||
"events": String, "absences": String, "group_averages": String,
|
"events": String, "absences": String, "group_averages": String,
|
||||||
// renamed subjects // non kreta data
|
// renamed subjects // non kreta data
|
||||||
"renamed_subjects": String,
|
"renamed_subjects": String,
|
||||||
@ -101,7 +101,8 @@ Future<Database> initDB(DatabaseProvider database) async {
|
|||||||
);
|
);
|
||||||
await migrateDB(db, struct: userDataDB, defaultValues: {
|
await migrateDB(db, struct: userDataDB, defaultValues: {
|
||||||
"grades": "[]", "timetable": "[]", "exams": "[]", "homework": "[]",
|
"grades": "[]", "timetable": "[]", "exams": "[]", "homework": "[]",
|
||||||
"messages": "[]", "notes": "[]", "events": "[]", "absences": "[]",
|
"messages": "[]", "recipients": "[]", "notes": "[]", "events": "[]",
|
||||||
|
"absences": "[]",
|
||||||
"group_averages": "[]",
|
"group_averages": "[]",
|
||||||
// renamed subjects // non kreta data
|
// renamed subjects // non kreta data
|
||||||
"renamed_subjects": "{}",
|
"renamed_subjects": "{}",
|
||||||
|
@ -122,6 +122,19 @@ class UserDatabaseQuery {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<SendRecipient>> getRecipients({required String userId}) async {
|
||||||
|
List<Map> userData =
|
||||||
|
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||||
|
if (userData.isEmpty) return [];
|
||||||
|
String? recipientsJson = userData.elementAt(0)["recipients"] as String?;
|
||||||
|
if (recipientsJson == null) return [];
|
||||||
|
List<SendRecipient> recipients = (jsonDecode(recipientsJson) as List)
|
||||||
|
.map((e) =>
|
||||||
|
SendRecipient.fromJson(e, SendRecipientType.fromJson(e['tipus'])))
|
||||||
|
.toList();
|
||||||
|
return recipients;
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<Note>> getNotes({required String userId}) async {
|
Future<List<Note>> getNotes({required String userId}) async {
|
||||||
List<Map> userData =
|
List<Map> userData =
|
||||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||||
|
@ -86,6 +86,13 @@ class UserDatabaseStore {
|
|||||||
where: "id = ?", whereArgs: [userId]);
|
where: "id = ?", whereArgs: [userId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> storeRecipients(List<SendRecipient> recipients,
|
||||||
|
{required String userId}) async {
|
||||||
|
String recipientsJson = jsonEncode(recipients.map((e) => e.json).toList());
|
||||||
|
await db.update("user_data", {"recipients": recipientsJson},
|
||||||
|
where: "id = ?", whereArgs: [userId]);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> storeNotes(List<Note> notes, {required String userId}) async {
|
Future<void> storeNotes(List<Note> notes, {required String userId}) async {
|
||||||
String notesJson = jsonEncode(notes.map((e) => e.json).toList());
|
String notesJson = jsonEncode(notes.map((e) => e.json).toList());
|
||||||
await db.update("user_data", {"notes": notesJson},
|
await db.update("user_data", {"notes": notesJson},
|
||||||
|
@ -155,6 +155,21 @@ class MessageProvider with ChangeNotifier {
|
|||||||
print(recipients);
|
print(recipients);
|
||||||
print(recipients.first.json);
|
print(recipients.first.json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storeRecipients(recipients);
|
||||||
|
}
|
||||||
|
|
||||||
|
// store recipients
|
||||||
|
Future<void> storeRecipients(List<SendRecipient> recipients) async {
|
||||||
|
User? user = Provider.of<UserProvider>(_context, listen: false).user;
|
||||||
|
if (user == null) throw "Cannot store Recipients for User null";
|
||||||
|
|
||||||
|
String userId = user.id;
|
||||||
|
await Provider.of<DatabaseProvider>(_context, listen: false)
|
||||||
|
.userStore
|
||||||
|
.storeMessages(_messages, userId: userId);
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
// send message
|
// send message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user