TF-3697 Open specific thread detail email
This commit is contained in:
+38
-20
@@ -2,7 +2,6 @@ import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
|
||||
class ThreadDetailPresentationUtils {
|
||||
const ThreadDetailPresentationUtils._();
|
||||
@@ -11,29 +10,48 @@ class ThreadDetailPresentationUtils {
|
||||
static const _defaultLoadSize = 20;
|
||||
|
||||
@visibleForTesting
|
||||
static get initialLoadSize => _initialLoadSize;
|
||||
@visibleForTesting
|
||||
static get defaultLoadSize => _defaultLoadSize;
|
||||
static int get defaultLoadSize => _defaultLoadSize;
|
||||
|
||||
static List<EmailId> getEmailIdsToLoad(
|
||||
Map<EmailId, PresentationEmail?> emailIdsPresentation,
|
||||
) {
|
||||
final validEmailIdsToLoad = emailIdsPresentation.entries
|
||||
.where((entry) => entry.value == null)
|
||||
.map((entry) => entry.key)
|
||||
.toList();
|
||||
static List<EmailId> getFirstLoadEmailIds(
|
||||
List<EmailId> emailIds, {
|
||||
EmailId? selectedEmailId,
|
||||
}) {
|
||||
// Default first, second and last email
|
||||
if (emailIds.length <= 3) return emailIds;
|
||||
|
||||
if (validEmailIdsToLoad.length == emailIdsPresentation.length) {
|
||||
// No email loaded yet
|
||||
return validEmailIdsToLoad.sublist(
|
||||
0,
|
||||
min(validEmailIdsToLoad.length, _initialLoadSize),
|
||||
);
|
||||
if (selectedEmailId == null ||
|
||||
!emailIds.contains(selectedEmailId) ||
|
||||
selectedEmailId == emailIds.first ||
|
||||
selectedEmailId == emailIds.last ||
|
||||
selectedEmailId == emailIds.elementAt(1)) {
|
||||
|
||||
return [
|
||||
...emailIds.sublist(
|
||||
0,
|
||||
min(emailIds.length, _initialLoadSize),
|
||||
),
|
||||
emailIds.last,
|
||||
];
|
||||
}
|
||||
|
||||
return validEmailIdsToLoad.sublist(
|
||||
validEmailIdsToLoad.length - min(validEmailIdsToLoad.length, _defaultLoadSize),
|
||||
validEmailIdsToLoad.length,
|
||||
return [
|
||||
emailIds.first,
|
||||
selectedEmailId,
|
||||
emailIds.last,
|
||||
];
|
||||
}
|
||||
|
||||
static getLoadMoreEmailIds(
|
||||
List<EmailId> emailIds, {
|
||||
bool loadEmailsAfterSelectedEmail = false,
|
||||
}) {
|
||||
if (loadEmailsAfterSelectedEmail) {
|
||||
return emailIds.sublist(0, min(emailIds.length, _defaultLoadSize));
|
||||
}
|
||||
|
||||
return emailIds.sublist(
|
||||
emailIds.length - min(_defaultLoadSize, emailIds.length),
|
||||
emailIds.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user