mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 16:04:20 +00:00
TF-4473 Fix double WebView fetch and hash race in _periodicSaveTask
This commit is contained in:
1 parent
3e3be57880
commit
290fb01cf9
2 files changed
+15
-6
No files matched your search
@@ -1260,8 +1260,8 @@ class ComposerController extends BaseController
|
||||
return _savedEmailDraftHash != newDraftHash;
|
||||
}
|
||||
|
||||
Future<int> _hashComposingEmail() async {
|
||||
String emailContent = await getContentInEditor();
|
||||
Future<int> _hashComposingEmail({String? htmlContent}) async {
|
||||
String emailContent = htmlContent ?? await getContentInEditor();
|
||||
|
||||
emailContent = await _composerRepository.removeCollapsedExpandedSignatureEffect(
|
||||
emailContent: emailContent,
|
||||
@@ -1288,7 +1288,7 @@ class ComposerController extends BaseController
|
||||
);
|
||||
final draftAsString = savedEmailDraft.asString();
|
||||
final draftAsHasCode = draftAsString.hashCode;
|
||||
log('ComposerController::_hashDraftEmail:draftAsString = $draftAsString | draftAsHasCode = $draftAsHasCode');
|
||||
log('ComposerController::_hashDraftEmail:draftAsHasCode = $draftAsHasCode');
|
||||
return draftAsHasCode;
|
||||
}
|
||||
|
||||
@@ -1296,7 +1296,8 @@ class ComposerController extends BaseController
|
||||
_savedEmailDraftHash = await _hashComposingEmail();
|
||||
}
|
||||
|
||||
Future<int> hashComposerStateForAutoSave() => _hashComposingEmail();
|
||||
Future<int> hashComposerStateForAutoSave({String? htmlContent}) =>
|
||||
_hashComposingEmail(htmlContent: htmlContent);
|
||||
|
||||
Future<void> initEmailDraftHash() async {
|
||||
final currentDraftHash = await _hashComposingEmail();
|
||||
|
||||
+10
-2
@@ -99,18 +99,26 @@ extension HandleMobileAutoSaveExtension on ComposerController {
|
||||
|
||||
final int currentHash;
|
||||
try {
|
||||
currentHash = await hashComposerStateForAutoSave().timeout(_getContentTimeout);
|
||||
// Reuse already-fetched content to avoid a second WebView getText() call.
|
||||
currentHash = await hashComposerStateForAutoSave(htmlContent: content).timeout(_getContentTimeout);
|
||||
} on TimeoutException {
|
||||
log('HandleMobileAutoSaveExtension::_periodicSaveTask: hash timeout, skip');
|
||||
return;
|
||||
}
|
||||
if (currentHash == lastAutoSavedToServerHash) return;
|
||||
|
||||
// Don't consume the hash while a save is in flight: the in-flight save will
|
||||
// finish with older content, and the next tick must retry with the new hash.
|
||||
if (notifier.isSavingToDraftInProgress) return;
|
||||
|
||||
final effectiveContent = content ?? notifier.lastKnownHtmlContent;
|
||||
final createEmailRequest = await buildCreateEmailRequestForAutoSave(
|
||||
htmlContent: effectiveContent,
|
||||
);
|
||||
if (createEmailRequest == null) return;
|
||||
if (createEmailRequest == null) {
|
||||
log('HandleMobileAutoSaveExtension::_periodicSaveTask: request is null, skip');
|
||||
return;
|
||||
}
|
||||
|
||||
// Optimistic: on failure, retry is deferred until content changes.
|
||||
lastAutoSavedToServerHash = currentHash;
|
||||
|
||||
Reference in new issue
Block a user