lot of work in message sending thing
This commit is contained in:
parent
adc8deffa9
commit
f4a6a0ceb0
@ -34,7 +34,8 @@ Future<void> syncAll(BuildContext context) {
|
|||||||
print("INFO Syncing all");
|
print("INFO Syncing all");
|
||||||
|
|
||||||
UserProvider user = Provider.of<UserProvider>(context, listen: false);
|
UserProvider user = Provider.of<UserProvider>(context, listen: false);
|
||||||
StatusProvider statusProvider = Provider.of<StatusProvider>(context, listen: false);
|
StatusProvider statusProvider =
|
||||||
|
Provider.of<StatusProvider>(context, listen: false);
|
||||||
|
|
||||||
List<Future<void>> tasks = [];
|
List<Future<void>> tasks = [];
|
||||||
int taski = 0;
|
int taski = 0;
|
||||||
@ -47,10 +48,14 @@ Future<void> syncAll(BuildContext context) {
|
|||||||
|
|
||||||
tasks = [
|
tasks = [
|
||||||
syncStatus(Provider.of<GradeProvider>(context, listen: false).fetch()),
|
syncStatus(Provider.of<GradeProvider>(context, listen: false).fetch()),
|
||||||
syncStatus(Provider.of<TimetableProvider>(context, listen: false).fetch(week: Week.current())),
|
syncStatus(Provider.of<TimetableProvider>(context, listen: false)
|
||||||
|
.fetch(week: Week.current())),
|
||||||
syncStatus(Provider.of<ExamProvider>(context, listen: false).fetch()),
|
syncStatus(Provider.of<ExamProvider>(context, listen: false).fetch()),
|
||||||
syncStatus(Provider.of<HomeworkProvider>(context, listen: false).fetch(from: DateTime.now().subtract(const Duration(days: 30)))),
|
syncStatus(Provider.of<HomeworkProvider>(context, listen: false)
|
||||||
|
.fetch(from: DateTime.now().subtract(const Duration(days: 30)))),
|
||||||
syncStatus(Provider.of<MessageProvider>(context, listen: false).fetchAll()),
|
syncStatus(Provider.of<MessageProvider>(context, listen: false).fetchAll()),
|
||||||
|
syncStatus(
|
||||||
|
Provider.of<MessageProvider>(context, listen: false).fetchRecipients()),
|
||||||
syncStatus(Provider.of<NoteProvider>(context, listen: false).fetch()),
|
syncStatus(Provider.of<NoteProvider>(context, listen: false).fetch()),
|
||||||
syncStatus(Provider.of<EventProvider>(context, listen: false).fetch()),
|
syncStatus(Provider.of<EventProvider>(context, listen: false).fetch()),
|
||||||
syncStatus(Provider.of<AbsenceProvider>(context, listen: false).fetch()),
|
syncStatus(Provider.of<AbsenceProvider>(context, listen: false).fetch()),
|
||||||
@ -58,14 +63,17 @@ Future<void> syncAll(BuildContext context) {
|
|||||||
// Sync student
|
// Sync student
|
||||||
syncStatus(() async {
|
syncStatus(() async {
|
||||||
if (user.user == null) return;
|
if (user.user == null) return;
|
||||||
Map? studentJson = await Provider.of<KretaClient>(context, listen: false).getAPI(KretaAPI.student(user.instituteCode!));
|
Map? studentJson = await Provider.of<KretaClient>(context, listen: false)
|
||||||
|
.getAPI(KretaAPI.student(user.instituteCode!));
|
||||||
if (studentJson == null) return;
|
if (studentJson == null) return;
|
||||||
Student student = Student.fromJson(studentJson);
|
Student student = Student.fromJson(studentJson);
|
||||||
|
|
||||||
user.user?.name = student.name;
|
user.user?.name = student.name;
|
||||||
|
|
||||||
// Store user
|
// Store user
|
||||||
await Provider.of<DatabaseProvider>(context, listen: false).store.storeUser(user.user!);
|
await Provider.of<DatabaseProvider>(context, listen: false)
|
||||||
|
.store
|
||||||
|
.storeUser(user.user!);
|
||||||
}()),
|
}()),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -79,8 +79,10 @@ class KretaAPI {
|
|||||||
BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientCategories;
|
BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientCategories;
|
||||||
static const availableCategories =
|
static const availableCategories =
|
||||||
BaseKreta.kretaAdmin + KretaAdminEndpoints.availableCategories;
|
BaseKreta.kretaAdmin + KretaAdminEndpoints.availableCategories;
|
||||||
static const recipientsTeacher =
|
static const recipientTeachers =
|
||||||
BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientsTeacher;
|
BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientTeachers;
|
||||||
|
static const recipientDirectorate =
|
||||||
|
BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientDirectorate;
|
||||||
static const uploadAttachment =
|
static const uploadAttachment =
|
||||||
BaseKreta.kretaAdmin + KretaAdminEndpoints.uploadAttachment;
|
BaseKreta.kretaAdmin + KretaAdminEndpoints.uploadAttachment;
|
||||||
static String downloadAttachment(String id) =>
|
static String downloadAttachment(String id) =>
|
||||||
@ -131,7 +133,8 @@ class KretaAdminEndpoints {
|
|||||||
"/api/v1/kommunikacio/postaladaelemek/$id";
|
"/api/v1/kommunikacio/postaladaelemek/$id";
|
||||||
static const recipientCategories = "/api/v1/adatszotarak/cimzetttipusok";
|
static const recipientCategories = "/api/v1/adatszotarak/cimzetttipusok";
|
||||||
static const availableCategories = "/api/v1/kommunikacio/cimezhetotipusok";
|
static const availableCategories = "/api/v1/kommunikacio/cimezhetotipusok";
|
||||||
static const recipientsTeacher = "/api/v1/kreta/alkalmazottak/tanar";
|
static const recipientTeachers = "/api/v1/kreta/alkalmazottak/tanar";
|
||||||
|
static const recipientDirectorate = "/api/v1/kreta/alkalmazottak/igazgatosag";
|
||||||
static const uploadAttachment = "/ideiglenesfajlok";
|
static const uploadAttachment = "/ideiglenesfajlok";
|
||||||
static String downloadAttachment(String id) =>
|
static String downloadAttachment(String id) =>
|
||||||
"/api/v1/dokumentumok/uzenetek/$id";
|
"/api/v1/dokumentumok/uzenetek/$id";
|
||||||
|
@ -68,13 +68,21 @@ class Message {
|
|||||||
messageId: message["azonosito"],
|
messageId: message["azonosito"],
|
||||||
seen: json["isElolvasva"] ?? false,
|
seen: json["isElolvasva"] ?? false,
|
||||||
deleted: json["isToroltElem"] ?? false,
|
deleted: json["isToroltElem"] ?? false,
|
||||||
date: message["kuldesDatum"] != null ? DateTime.parse(message["kuldesDatum"]).toLocal() : DateTime(0),
|
date: message["kuldesDatum"] != null
|
||||||
|
? DateTime.parse(message["kuldesDatum"]).toLocal()
|
||||||
|
: DateTime(0),
|
||||||
author: (message["feladoNev"] ?? "").trim(),
|
author: (message["feladoNev"] ?? "").trim(),
|
||||||
content: message["szoveg"].replaceAll("\r", "") ?? "",
|
content: message["szoveg"].replaceAll("\r", "") ?? "",
|
||||||
subject: message["targy"] ?? "",
|
subject: message["targy"] ?? "",
|
||||||
type: type,
|
type: type,
|
||||||
recipients: (message["cimzettLista"] as List).cast<Map>().map((Map recipient) => Recipient.fromJson(recipient)).toList(),
|
recipients: (message["cimzettLista"] as List)
|
||||||
attachments: (message["csatolmanyok"] as List).cast<Map>().map((Map attachment) => Attachment.fromJson(attachment)).toList(),
|
.cast<Map>()
|
||||||
|
.map((Map recipient) => Recipient.fromJson(recipient))
|
||||||
|
.toList(),
|
||||||
|
attachments: (message["csatolmanyok"] as List)
|
||||||
|
.cast<Map>()
|
||||||
|
.map((Map attachment) => Attachment.fromJson(attachment))
|
||||||
|
.toList(),
|
||||||
replyId: message["elozoUzenetAzonosito"],
|
replyId: message["elozoUzenetAzonosito"],
|
||||||
conversationId: message["beszelgetesAzonosito"],
|
conversationId: message["beszelgetesAzonosito"],
|
||||||
json: json,
|
json: json,
|
||||||
@ -105,3 +113,89 @@ class Conversation {
|
|||||||
|
|
||||||
Message get newest => _messages.first;
|
Message get newest => _messages.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sendable message object and it's things
|
||||||
|
class SendMessage {
|
||||||
|
Map? json;
|
||||||
|
int id;
|
||||||
|
int lastMessageId;
|
||||||
|
String? subject;
|
||||||
|
String text;
|
||||||
|
|
||||||
|
SendMessage({
|
||||||
|
required this.id,
|
||||||
|
required this.lastMessageId,
|
||||||
|
this.subject,
|
||||||
|
required this.text,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class SendRecipient {
|
||||||
|
Map? json;
|
||||||
|
int? id;
|
||||||
|
int? kretaId;
|
||||||
|
String? name;
|
||||||
|
SendRecipientType type;
|
||||||
|
|
||||||
|
SendRecipient({
|
||||||
|
required this.id,
|
||||||
|
required this.kretaId,
|
||||||
|
required this.name,
|
||||||
|
required this.type,
|
||||||
|
this.json,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SendRecipient.fromJson(Map json, SendRecipientType type) {
|
||||||
|
return SendRecipient(
|
||||||
|
id: json['azonosito'],
|
||||||
|
kretaId: json['kretaAzonosito'],
|
||||||
|
name: json['name'],
|
||||||
|
type: type,
|
||||||
|
json: json,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object get kretaJson => {
|
||||||
|
'azonosito': id,
|
||||||
|
'kretaAzonosito': kretaId,
|
||||||
|
'nev': name,
|
||||||
|
'tipus': {
|
||||||
|
'azonosito': type.id,
|
||||||
|
'kod': type.code,
|
||||||
|
'leiras': type.description,
|
||||||
|
'nev': type.name,
|
||||||
|
'rovidNev': type.shortName,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class SendRecipientType {
|
||||||
|
Map? json;
|
||||||
|
int id;
|
||||||
|
String code;
|
||||||
|
String description;
|
||||||
|
String name;
|
||||||
|
String shortName;
|
||||||
|
|
||||||
|
SendRecipientType({
|
||||||
|
required this.id,
|
||||||
|
required this.code,
|
||||||
|
required this.description,
|
||||||
|
required this.name,
|
||||||
|
required this.shortName,
|
||||||
|
this.json,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SendRecipientType.fromJson(Map json) {
|
||||||
|
return SendRecipientType(
|
||||||
|
id: json['azonosito'],
|
||||||
|
code: json['kod'],
|
||||||
|
description: json['leiras'],
|
||||||
|
name: json['nev'],
|
||||||
|
shortName: json['rovidNev'],
|
||||||
|
json: json,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum AddresseeType { teachers, directorate }
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
|
||||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||||
import 'package:filcnaplo/models/user.dart';
|
import 'package:filcnaplo/models/user.dart';
|
||||||
@ -92,19 +94,64 @@ class MessageProvider with ChangeNotifier {
|
|||||||
|
|
||||||
// fetch recipients
|
// fetch recipients
|
||||||
Future<void> fetchRecipients() async {
|
Future<void> fetchRecipients() async {
|
||||||
|
Map<AddresseeType, SendRecipientType> addressable = {};
|
||||||
|
|
||||||
// check user
|
// check user
|
||||||
User? user = Provider.of<UserProvider>(_context, listen: false).user;
|
User? user = Provider.of<UserProvider>(_context, listen: false).user;
|
||||||
if (user == null) throw "Cannot fetch Messages for User null";
|
if (user == null) throw "Cannot fetch Messages for User null";
|
||||||
|
|
||||||
// get recipients
|
// get categories
|
||||||
List? recipientsJson =
|
List? availableCategoriesJson =
|
||||||
await Provider.of<KretaClient>(_context, listen: false)
|
await Provider.of<KretaClient>(_context, listen: false)
|
||||||
.getAPI(KretaAPI.recipientsTeacher);
|
.getAPI(KretaAPI.recipientCategories);
|
||||||
if (recipientsJson == null) {
|
|
||||||
|
// print(availableCategoriesJson);
|
||||||
|
|
||||||
|
// get recipients
|
||||||
|
List? recipientTeachersJson =
|
||||||
|
await Provider.of<KretaClient>(_context, listen: false)
|
||||||
|
.getAPI(KretaAPI.recipientTeachers);
|
||||||
|
List? recipientDirectorateJson =
|
||||||
|
await Provider.of<KretaClient>(_context, listen: false)
|
||||||
|
.getAPI(KretaAPI.recipientDirectorate);
|
||||||
|
|
||||||
|
if (availableCategoriesJson == null ||
|
||||||
|
recipientTeachersJson == null ||
|
||||||
|
recipientDirectorateJson == null) {
|
||||||
throw "Cannot fetch Recipients for User ${user.id}";
|
throw "Cannot fetch Recipients for User ${user.id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
print(recipientsJson);
|
for (var e in availableCategoriesJson) {
|
||||||
|
// print(e);
|
||||||
|
switch (e['kod']) {
|
||||||
|
case 'TANAR':
|
||||||
|
addressable
|
||||||
|
.addAll({AddresseeType.teachers: SendRecipientType.fromJson(e)});
|
||||||
|
break;
|
||||||
|
case 'IGAZGATOSAG':
|
||||||
|
addressable.addAll(
|
||||||
|
{AddresseeType.directorate: SendRecipientType.fromJson(e)});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse recipients
|
||||||
|
List<SendRecipient> recipients = [];
|
||||||
|
|
||||||
|
if (addressable.containsKey(AddresseeType.teachers)) {
|
||||||
|
recipients.addAll(recipientTeachersJson.map((e) =>
|
||||||
|
SendRecipient.fromJson(e, addressable[AddresseeType.teachers]!)));
|
||||||
|
}
|
||||||
|
if (addressable.containsKey(AddresseeType.directorate)) {
|
||||||
|
recipients.addAll(recipientDirectorateJson.map((e) =>
|
||||||
|
SendRecipient.fromJson(e, addressable[AddresseeType.directorate]!)));
|
||||||
|
}
|
||||||
|
|
||||||
|
print(addressable);
|
||||||
|
print(recipients);
|
||||||
|
print(recipients.first.json);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send message
|
// send message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user