Not update the email in cache if cache not hit
This commit is contained in:
committed by
Dat H. Pham
parent
a66b33472d
commit
b4721a3a07
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:dartz/dartz.dart' as dartz;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/filter/filter.dart';
|
import 'package:jmap_dart_client/jmap/core/filter/filter.dart';
|
||||||
@@ -143,24 +144,29 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
|||||||
List<Email>? emailCacheList
|
List<Email>? emailCacheList
|
||||||
}) async {
|
}) async {
|
||||||
if (emailUpdated != null && emailUpdated.isNotEmpty) {
|
if (emailUpdated != null && emailUpdated.isNotEmpty) {
|
||||||
final newEmailUpdated = emailUpdated.map((email) {
|
if (updatedProperties == null) {
|
||||||
if (updatedProperties == null) {
|
return null;
|
||||||
return email;
|
}
|
||||||
} else {
|
final newEmailUpdated = emailUpdated
|
||||||
final emailOld = emailCacheList?.findEmailById(email.id);
|
.map((updatedEmail) => _combineUpdatedWithEmailInCache(updatedEmail, emailCacheList))
|
||||||
if (emailOld != null) {
|
.where((tuple) => tuple.value2 != null)
|
||||||
return emailOld.combineEmail(email, updatedProperties);
|
.map((tuple) => tuple.value2!.combineEmail(tuple.value1, updatedProperties))
|
||||||
} else {
|
.toList();
|
||||||
return email;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
return newEmailUpdated;
|
return newEmailUpdated;
|
||||||
}
|
}
|
||||||
return emailUpdated;
|
return emailUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dartz.Tuple2<Email, Email?> _combineUpdatedWithEmailInCache(Email updatedEmail, List<Email>? emailCacheList) {
|
||||||
|
final emailOld = emailCacheList?.findEmailById(updatedEmail.id);
|
||||||
|
if (emailOld != null) {
|
||||||
|
return dartz.Tuple2(updatedEmail, emailOld);
|
||||||
|
} else {
|
||||||
|
return dartz.Tuple2(updatedEmail, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _updateEmailCache({
|
Future<void> _updateEmailCache({
|
||||||
List<Email>? newUpdated,
|
List<Email>? newUpdated,
|
||||||
List<Email>? newCreated,
|
List<Email>? newCreated,
|
||||||
|
|||||||
Reference in New Issue
Block a user