Skip to content

Commit

Permalink
chore: improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Jan 29, 2024
1 parent 5f68782 commit 4fed245
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 189 deletions.
48 changes: 0 additions & 48 deletions lib/app_styles.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/location/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class _LocationScreenState extends State<LocationScreen> {

void _onScaleUpdate(ScaleUpdateDetails details, MapTransformer transformer) {
final scaleDiff = details.scale - _scaleStart;
//print('on scale update: scaleDiff=$scaleDiff focal=${details.focalPoint}');
_scaleStart = details.scale;

if (scaleDiff > 0) {
Expand Down
34 changes: 22 additions & 12 deletions lib/models/async_mime_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ abstract class AsyncMimeSource {
Duration? responseTimeout,
});

/// Informs this source about a new incoming [message] at the optional [index].
/// Informs this source about a new incoming [message]
/// at the optional [index].
///
/// Note this message does not necessarily match to this sources.
Future<void> onMessageArrived(MimeMessage message, {int? index});

/// Informs this source about the [sequence] having been removed on the server.
/// Informs this source about the [sequence] having been removed
/// on the server.
Future<void> onMessagesVanished(MessageSequence sequence);

/// Is called when message flags have been updated on the server.
Expand Down Expand Up @@ -381,11 +383,14 @@ abstract class CachedMimeSource extends AsyncMimeSource {
// fetch and compare the 20 latest messages:

// For each message check for the following cases:
// - message can be new (it will have a higher UID that the known first message)
// - message can be new (it will have a higher UID that the known
// first message)
// - message can have updated flags (GUID will still be the same)
// - a previously cached message can now be deleted (sequence ID will match, but not the UID/GUID)
// - a previously cached message can now be deleted (sequence ID will match,
// but not the UID/GUID)
//
// Additional complications occur when not the same number of first messages are cached,
// Additional complications occur when not the same number of first messages
// are cached,
// in that case the GUID/UID cannot be compared.
//
// Also, previously there might have been less messages in this
Expand All @@ -395,7 +400,8 @@ abstract class CachedMimeSource extends AsyncMimeSource {
final firstCachedUid = firstCached?.uid;
if (firstCachedUid == null) {
// When the latest message is not known, better reload all.
// TODO(RV): Should a reload also be triggered when other messages are not cached?
// TODO(RV): Should a reload also be triggered when other messages are
// not cached?
cache.clear();
notifySubscribersOnCacheInvalidated();

Expand Down Expand Up @@ -930,11 +936,11 @@ class AsyncSearchMimeSource extends AsyncMimeSource {
@override
Future<void> onMessagesVanished(MessageSequence sequence) {
if (sequence.isUidSequence == searchResult.pagedSequence.isUidSequence) {
final removedMessages = searchResult.removeMessageSequence(sequence);
for (final removed in removedMessages) {
notifySubscribersOnMessageVanished(removed);
}
searchResult
.removeMessageSequence(sequence)
.forEach(notifySubscribersOnMessageVanished);
}

return Future.value();
}

Expand Down Expand Up @@ -976,14 +982,18 @@ class AsyncSearchMimeSource extends AsyncMimeSource {

@override
Future<MoveResult> moveMessages(
List<MimeMessage> messages, Mailbox targetMailbox) {
List<MimeMessage> messages,
Mailbox targetMailbox,
) {
// TODO(RV): implement moveMessages
throw UnimplementedError();
}

@override
Future<MoveResult> moveMessagesToFlag(
List<MimeMessage> messages, MailboxFlag targetMailboxFlag) {
List<MimeMessage> messages,
MailboxFlag targetMailboxFlag,
) {
// TODO(RV): implement moveMessagesToFlag
throw UnimplementedError();
}
Expand Down
5 changes: 4 additions & 1 deletion lib/models/date_sectioned_message_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class DateSectionedMessageSource extends ChangeNotifier {
if (message != null) {
return SectionElement(null, message);
}

return null;
}

Expand All @@ -148,11 +149,13 @@ class DateSectionedMessageSource extends ChangeNotifier {
}
}
final message = await messageSource.getMessageAt(messageIndex);

return SectionElement(null, message);
}

Future<List<Message>> getMessagesForSection(
MessageDateSection section) async {
MessageDateSection section,
) async {
final index = _sections.indexOf(section);
if (index == -1) {
return [];
Expand Down
8 changes: 5 additions & 3 deletions lib/models/hive/hive_mime_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ part 'hive_mime_storage.g.dart';
/// 1) list of SequenceId-UID-GUID elements - to be loaded when mailbox is
/// opened, possibly along with envelope data of first page to speed up
/// loading
/// 2) possibly envelope data by GUID (contains flags, subject, senders, recipients, date, has-attachment, possibly message preview)
/// 2) possibly envelope data by GUID (contains flags, subject, senders,
/// recipients, date, has-attachment, possibly message preview)
/// 3) downloaded message data by GUID - this may not (yet) contain attachments
///
/// new message:
Expand Down Expand Up @@ -144,8 +145,8 @@ class HiveMailboxMimeStorage extends OfflineMimeStorage {
if (guid != null) {
final existingMessageId =
allMessageIds.firstWhereOrNull((id) => id.guid == guid);
final sequenceId = message.sequenceId!;
final uid = message.uid!;
final sequenceId = message.sequenceId ?? 0;
final uid = message.uid ?? 0;
if (existingMessageId == null) {
addedMessageIds++;
final messageId =
Expand Down Expand Up @@ -338,6 +339,7 @@ class StorageMessageEnvelope {
flags: message.flags,
);
}

return StorageMessageEnvelope(
uid: uid,
guid: guid,
Expand Down
5 changes: 3 additions & 2 deletions lib/models/mail_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ class _QueuedMailOperation {
operation = StoreFlagsOperation.fromJson(data);
break;
// case MailOperationType.moveToFlag:
// // TODO: Handle this case.
// TODO(RV): Handle this case.
// break;
// case MailOperationType.moveToFolder:
// // TODO: Handle this case.
// TODO(RV): Handle this case.
// break;
default:
throw FormatException('Unsupported type $type');
}

return _QueuedMailOperation(operation, email);
}

Expand Down
8 changes: 6 additions & 2 deletions lib/models/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ class Message extends ChangeNotifier {
bool get hasAttachment {
final mime = mimeMessage;
final size = mime.size;
// when only the envelope is downloaded, the content-type header ergo mediaType is not yet available
// when only the envelope is downloaded, the content-type header ergo
// mediaType is not yet available

return mime.hasAttachments() ||
(mime.mimeData == null &&
mime.body == null &&
Expand Down Expand Up @@ -172,7 +174,8 @@ extension NewsLetter on MimeMessage {
String? decodeListName() {
final listPost = decodeHeaderValue('list-post');
if (listPost != null) {
// typically only mailing lists that allow posting have a human understandable List-ID header:
// typically only mailing lists that allow posting have a
// human understandable List-ID header:
final id = decodeHeaderValue('list-id');
if (id != null && id.isNotEmpty) {
return id;
Expand All @@ -189,6 +192,7 @@ extension NewsLetter on MimeMessage {
if (sender.isNotEmpty) {
return sender.first.toString();
}

return null;
}

Expand Down
41 changes: 4 additions & 37 deletions lib/models/message_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ abstract class MessageSource extends ChangeNotifier
/// Only available when [supportsDeleteAll] is `true`
Future<List<DeleteResult>> deleteAllMessages({bool expunge = false});

/// Marks all messages as seen (read) `true` or unseen (unread) when `false` is given
/// Marks all messages as seen (read) `true` or unseen (unread)
/// when `false` is given
///
/// Only available when [supportsDeleteAll] is `true`
Future<void> markAllMessagesSeen(bool seen);
Expand Down Expand Up @@ -546,19 +547,6 @@ abstract class MessageSource extends ChangeNotifier
return mimesBySource;
}

// Map<MailClient, MessageSequence> orderByClient(List<Message?> messages) {
// final sequenceByClient = <MailClient, MessageSequence>{};
// for (final msg in messages) {
// final client = msg!.mailClient;
// if (sequenceByClient.containsKey(client)) {
// sequenceByClient[client]!.addMessage(msg.mimeMessage);
// } else {
// sequenceByClient[client] = MessageSequence.fromMessage(msg.mimeMessage);
// }
// }
// return sequenceByClient;
// }

Future<void> storeMessageFlags(
List<Message> messages,
List<String> flags, {
Expand Down Expand Up @@ -936,8 +924,6 @@ class MultipleMessageSource extends MessageSource {

return _UnifiedMessage(mime, this, index, id.source);
}
// print(
// 'get uncached $index with lastUncachedIndex=$_lastUncachedIndex and size $size');
int diff = index - _indicesCache.length;
while (diff > 0) {
final sourceIndex = index - diff;
Expand Down Expand Up @@ -1115,22 +1101,6 @@ class MultipleMessageSource extends MessageSource {
multipleSource.clear();
}
}

// @override
// Future<Message> loadSingleMessage(MailNotificationPayload payload) async {
// final mimeSource = mimeSources.firstWhereOrNull(
// (source) => source.mailClient.account.email == payload.accountEmail,
// );
// if (mimeSource == null) {
// throw Exception('Unable to find mime source for ${payload.accountEmail}');
// }
// final payloadMime = MimeMessage()
// ..sequenceId = payload.sequenceId
// ..uid = payload.uid;
// final mime = await mimeSource.fetchMessageContents(payloadMime);

// return createMessage(mime, mimeSource, 0);
// }
}

class _UnifiedMessage extends Message {
Expand All @@ -1157,11 +1127,8 @@ class _MultipleMimeSource {
int _currentIndex = 0;
_MultipleMimeSourceMessage? _currentMessage;

Future<_MultipleMimeSourceMessage?> peek() async {
_currentMessage ??= await _next();

return _currentMessage;
}
Future<_MultipleMimeSourceMessage?> peek() async =>
_currentMessage ??= await _next();

void pop() {
_currentMessage = null;
Expand Down
4 changes: 3 additions & 1 deletion lib/notification/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class NotificationService {
// print(
// 'got notification launched details: $launchDetails
// with payload ${response.payload}');
_selectNotification(response, context: context);
if (context != null && context.mounted) {
_selectNotification(response, context: context);
}

return NotificationServiceInitResult.appLaunchedByNotification;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/screens/compose_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ class _ComposeScreenState extends ConsumerState<ComposeScreen> {
final currentAccount = ref.read(currentRealAccountProvider)!;
_realAccount = currentAccount;
final defaultSender = ref.read(settingsProvider).defaultSender;
mb.from ??= [defaultSender ?? currentAccount.fromAddress];
final mbFrom = mb.from ?? [defaultSender ?? currentAccount.fromAddress];
mb.from ??= mbFrom;
Sender? from;
if (mb.from?.first == defaultSender) {
if (mbFrom.first == defaultSender) {
from = _senders
.firstWhereOrNull((sender) => sender.address == defaultSender);
} else {
Expand All @@ -189,7 +190,7 @@ class _ComposeScreenState extends ConsumerState<ComposeScreen> {
);
}
if (from == null) {
from = Sender(mb.from!.first, currentAccount);
from = Sender(mbFrom.first, currentAccount);
_senders = [from, ..._senders];
}
_from = from;
Expand Down
Loading

0 comments on commit 4fed245

Please sign in to comment.