Skip to content

Commit

Permalink
fix: Rebase master
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambrdctr committed Aug 10, 2023
1 parent 2bf34f5 commit 12d07f9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 43 deletions.
66 changes: 43 additions & 23 deletions MailCore/Cache/MailboxManager/MailboxManager+Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public extension MailboxManager {

await backgroundRealm.execute { [self] realm in
if let folder = folder.fresh(using: realm) {
createMultiMessagesThreads(messageByUids: messageByUidsResult, folder: folder, using: realm)
createThreads(messageByUids: messageByUidsResult, folder: folder, using: realm)
}
SentryDebug.sendMissingMessagesSentry(
sentUids: uniqueUids,
Expand All @@ -343,7 +343,7 @@ public extension MailboxManager {
}
}

private func createMultiMessagesThreads(messageByUids: MessageByUidsResult, folder: Folder, using realm: Realm) {
private func createThreads(messageByUids: MessageByUidsResult, folder: Folder, using realm: Realm) {
var threadsToUpdate = Set<Thread>()
try? realm.safeWrite {
for message in messageByUids.messages {
Expand All @@ -360,28 +360,12 @@ public extension MailboxManager {
}
message.inTrash = folder.role == .trash
message.computeReference()
let existingThreads = Array(realm.objects(Thread.self)
.where { $0.messageIds.containsAny(in: message.linkedUids) })

if let newThread = createNewThreadIfRequired(
for: message,
folder: folder,
existingThreads: existingThreads
) {
threadsToUpdate.insert(newThread)
}

var allExistingMessages = Set(existingThreads.flatMap(\.messages))
allExistingMessages.insert(message)

for thread in existingThreads {
for existingMessage in allExistingMessages {
if !thread.messages.map(\.uid).contains(existingMessage.uid) {
thread.addMessageIfNeeded(newMessage: message.fresh(using: realm) ?? message)
}
}

threadsToUpdate.insert(thread)
let isThreadMode = UserDefaults.shared.threadMode == .conversation
if isThreadMode {
createConversationThread(message: message, folder: folder, threadsToUpdate: &threadsToUpdate, using: realm)
} else {
createSingleMessageThread(message: message, folder: folder) // threadsToUpdate ?
}

if let message = realm.objects(Message.self).first(where: { $0.uid == message.uid }) {
Expand All @@ -392,6 +376,42 @@ public extension MailboxManager {
}
}

private func createConversationThread(
message: Message,
folder: Folder,
threadsToUpdate: inout Set<Thread>,
using realm: Realm
) {
let existingThreads = Array(realm.objects(Thread.self)
.where { $0.messageIds.containsAny(in: message.linkedUids) /* && $0.isConversationThread == true */ })

if let newThread = createNewThreadIfRequired(
for: message,
folder: folder,
existingThreads: existingThreads
) {
threadsToUpdate.insert(newThread)
}

var allExistingMessages = Set(existingThreads.flatMap(\.messages))
allExistingMessages.insert(message)

for thread in existingThreads {
for existingMessage in allExistingMessages {
if !thread.messages.map(\.uid).contains(existingMessage.uid) {
thread.addMessageIfNeeded(newMessage: message.fresh(using: realm) ?? message)
}
}

threadsToUpdate.insert(thread)
}
}

private func createSingleMessageThread(message: Message, folder: Folder) {
let thread = message.toThread().detached()
folder.threads.insert(thread)
}

private func createNewThreadIfRequired(for message: Message, folder: Folder, existingThreads: [Thread]) -> Thread? {
guard !existingThreads.contains(where: { $0.folder == folder }) else { return nil }

Expand Down
21 changes: 21 additions & 0 deletions MailCore/Cache/MailboxManager/MailboxManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,27 @@ public final class MailboxManager: ObservableObject, MailboxManageable {
let realm = getRealm()
return realm.objects(Folder.self).contains { $0.unreadCount > 0 }
}

public func cleanRealm() {
Task {
await backgroundRealm.execute { realm in

let folders = realm.objects(Folder.self)
let threads = realm.objects(Thread.self)
let messages = realm.objects(Message.self)

try? realm.safeWrite {
realm.delete(threads)
realm.delete(messages)
for folder in folders {
folder.cursor = nil
folder.resetHistoryInfo()
folder.computeUnreadCount()
}
}
}
}
}
}

// MARK: - Equatable conformance
Expand Down
8 changes: 4 additions & 4 deletions MailResources/Localizable/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Locale: de, German
* Tagged: ios
* Exported by: Ambroise Decouttere
* Exported at: Wed, 09 Aug 2023 18:11:40 +0200
* Exported at: Thu, 10 Aug 2023 14:44:55 +0200
*/

/* loco:6256793050618f7416758a32 */
Expand Down Expand Up @@ -1223,12 +1223,12 @@
/* loco:64c21f7b8b1932323c047792 */
"newAccountStorageDrive" = "15 GB kDrive-Speicher";

/* loco:64ca16484dbf65eb9b0ea862 */
"pleaseLogInFirst" = "Bitte melden Sie sich zuerst in der ikMail-App an.";

/* loco:64cca81829e8aeaec602e1c2 */
"settingsThreadModeTitle" = "Modus der Nachrichtenanzeige";

/* loco:64ccb58ceef1939fc6061fa2 */
"contentDescriptionButtonDeleteSearch" = "Suche löschen";

/* loco:64d209e0b3606abecd06b622 */
"errorNewFolderInvalidCharacter" = "Der Ordnername enthält ungültige Zeichen";

Expand Down
8 changes: 4 additions & 4 deletions MailResources/Localizable/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Locale: en, English
* Tagged: ios
* Exported by: Ambroise Decouttere
* Exported at: Wed, 09 Aug 2023 18:11:40 +0200
* Exported at: Thu, 10 Aug 2023 14:44:54 +0200
*/

/* loco:6256793050618f7416758a32 */
Expand Down Expand Up @@ -1223,12 +1223,12 @@
/* loco:64c21f7b8b1932323c047792 */
"newAccountStorageDrive" = "15 GB of kDrive storage";

/* loco:64ca16484dbf65eb9b0ea862 */
"pleaseLogInFirst" = "Please login in the ikMail app first.";

/* loco:64cca81829e8aeaec602e1c2 */
"settingsThreadModeTitle" = "Message display mode";

/* loco:64ccb58ceef1939fc6061fa2 */
"contentDescriptionButtonDeleteSearch" = "Clear search";

/* loco:64d209e0b3606abecd06b622 */
"errorNewFolderInvalidCharacter" = "The folder name contains invalid characters";

Expand Down
8 changes: 4 additions & 4 deletions MailResources/Localizable/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Locale: es, Spanish
* Tagged: ios
* Exported by: Ambroise Decouttere
* Exported at: Wed, 09 Aug 2023 18:11:40 +0200
* Exported at: Thu, 10 Aug 2023 14:44:55 +0200
*/

/* loco:6256793050618f7416758a32 */
Expand Down Expand Up @@ -1223,12 +1223,12 @@
/* loco:64c21f7b8b1932323c047792 */
"newAccountStorageDrive" = "15 GB de almacenamiento kDrive";

/* loco:64ca16484dbf65eb9b0ea862 */
"pleaseLogInFirst" = "Inicia sesión primero en la aplicación ikMail.";

/* loco:64cca81829e8aeaec602e1c2 */
"settingsThreadModeTitle" = "Modo de visualización de mensajes";

/* loco:64ccb58ceef1939fc6061fa2 */
"contentDescriptionButtonDeleteSearch" = "Borrar búsqueda";

/* loco:64d209e0b3606abecd06b622 */
"errorNewFolderInvalidCharacter" = "El nombre de la carpeta contiene caracteres no válidos";

Expand Down
8 changes: 4 additions & 4 deletions MailResources/Localizable/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Locale: fr, French
* Tagged: ios
* Exported by: Ambroise Decouttere
* Exported at: Wed, 09 Aug 2023 18:11:40 +0200
* Exported at: Thu, 10 Aug 2023 14:44:55 +0200
*/

/* loco:6256793050618f7416758a32 */
Expand Down Expand Up @@ -1223,12 +1223,12 @@
/* loco:64c21f7b8b1932323c047792 */
"newAccountStorageDrive" = "15 Go de stockage kDrive";

/* loco:64ca16484dbf65eb9b0ea862 */
"pleaseLogInFirst" = "Veuillez d'abord vous connecter à l'application ikMail.";

/* loco:64cca81829e8aeaec602e1c2 */
"settingsThreadModeTitle" = "Mode d’affichage des messages";

/* loco:64ccb58ceef1939fc6061fa2 */
"contentDescriptionButtonDeleteSearch" = "Effacer la recherche";

/* loco:64d209e0b3606abecd06b622 */
"errorNewFolderInvalidCharacter" = "Le nom du dossier comporte des caractères invalides";

Expand Down
8 changes: 4 additions & 4 deletions MailResources/Localizable/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Locale: it, Italian
* Tagged: ios
* Exported by: Ambroise Decouttere
* Exported at: Wed, 09 Aug 2023 18:11:40 +0200
* Exported at: Thu, 10 Aug 2023 14:44:55 +0200
*/

/* loco:6256793050618f7416758a32 */
Expand Down Expand Up @@ -1223,12 +1223,12 @@
/* loco:64c21f7b8b1932323c047792 */
"newAccountStorageDrive" = "15 GB di memoria kDrive";

/* loco:64ca16484dbf65eb9b0ea862 */
"pleaseLogInFirst" = "Effettuare prima il login nell'app ikMail.";

/* loco:64cca81829e8aeaec602e1c2 */
"settingsThreadModeTitle" = "Modalità di visualizzazione dei messaggi";

/* loco:64ccb58ceef1939fc6061fa2 */
"contentDescriptionButtonDeleteSearch" = "Cancellare la ricerca";

/* loco:64d209e0b3606abecd06b622 */
"errorNewFolderInvalidCharacter" = "Il nome della cartella contiene caratteri non validi";

Expand Down

0 comments on commit 12d07f9

Please sign in to comment.