TF-1068 Implement make recent list for input of URL
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:tmail_ui_user/features/caching/recent_login_url_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/login_url_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/recent_login_url_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/list_recent_login_url_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_url.dart';
|
||||
|
||||
class LoginUrlDataSourceImpl implements LoginUrlDataSource {
|
||||
@@ -25,4 +26,34 @@ class LoginUrlDataSourceImpl implements LoginUrlDataSource {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<RecentLoginUrl>> getAllRecentLoginUrlLatest({int? limit, String? pattern}) {
|
||||
return Future.sync(() async {
|
||||
final listRecentUrlCache = await _recentLoginUrlCacheClient.getAll();
|
||||
final listRecentUrl = listRecentUrlCache
|
||||
.where((recentCache) => _filterRecentUrlCache(recentCache, pattern))
|
||||
.map((recentCache) => recentCache.toRecentLoginUrl())
|
||||
.toList();
|
||||
listRecentUrl.sortByCreationDate();
|
||||
|
||||
final newLimit = limit ?? 5;
|
||||
|
||||
final newListRecentSUrl = listRecentUrl.length > newLimit
|
||||
? listRecentUrl.sublist(0, newLimit)
|
||||
: listRecentUrl;
|
||||
|
||||
return newListRecentSUrl;
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
bool _filterRecentUrlCache(RecentLoginUrlCache recentLoginUrlCache, String? pattern) {
|
||||
if (pattern == null || pattern.trim().isEmpty) {
|
||||
return true;
|
||||
} else {
|
||||
return recentLoginUrlCache.matchUrl(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user