Skip to content

Commit

Permalink
Apply code style
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyuehyang committed Mar 15, 2022
1 parent a1ca2d0 commit 391bbd3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
14 changes: 1 addition & 13 deletions Mixin/Service/Work/AttachmentCleaningWork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import MixinServices

final class AttachmentCleaningWork: Work {

private let finishedCategoriesLock = NSRecursiveLock()

private var finishedCategories: Set<AttachmentContainer.Category>

convenience init() {
Expand All @@ -20,13 +18,9 @@ final class AttachmentCleaningWork: Work {
guard -AppGroupUserDefaults.User.lastAttachmentCleanUpDate.timeIntervalSinceNow >= 7 * .oneDay else {
return
}

finishedCategoriesLock.lock()
let categories: [AttachmentContainer.Category] = [.photos, .audios, .files, .videos].filter { category in
!finishedCategories.contains(category)
}
finishedCategoriesLock.unlock()

for category in categories {
Logger.general.debug(category: "AttachmentCleaningWork", message: "Cleaning \(category)")
let path = AttachmentContainer.url(for: category, filename: nil).path
Expand All @@ -48,13 +42,10 @@ final class AttachmentCleaningWork: Work {
try? FileManager.default.removeItem(at: url)
}
}
finishedCategoriesLock.lock()
finishedCategories.insert(category)
updatePersistedContext()
finishedCategoriesLock.unlock()
Logger.general.debug(category: "AttachmentCleaningWork", message: "\(category) cleaned up")
}

AppGroupUserDefaults.User.lastAttachmentCleanUpDate = Date()
}

Expand All @@ -65,10 +56,7 @@ extension AttachmentCleaningWork: PersistableWork {
static let typeIdentifier: String = "attachment_clean"

var context: Data? {
finishedCategoriesLock.lock()
let categories = finishedCategories
finishedCategoriesLock.unlock()
return try? JSONEncoder.default.encode(categories)
try? JSONEncoder.default.encode(finishedCategories)
}

var priority: PersistedWork.Priority {
Expand Down
17 changes: 17 additions & 0 deletions MixinServices/MixinServices/Services/Work/DeleteMessageWork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ extension MessageItem: DeletableMessage {

}

/*
Straight execute
┌───────────────┐ ┌───────────┐Completed┌────────────────┐
│Init(preparing)├─►│Persistence├────────►│Delete DB Record│
└───────────────┘ └───────────┘ └────┬───────────┘
┌───────────┐Execute┌─────┐ │Completed
│Delete file│◄──────┤Ready│◄──┘
└───────────┘ └─────┘
Awake from persistence
┌────────────┐ ┌────────────────┐Completed┌───────────┐
│Awake(ready)├─►│Delete DB Record├────────►│Delete file│
└────────────┘ └────────────────┘ └───────────┘
*/

public final class DeleteMessageWork: Work {

public enum Attachment: Codable {
Expand Down Expand Up @@ -64,6 +80,7 @@ public final class DeleteMessageWork: Work {
state = .finished(.success)
} else {
MessageDAO.shared.delete(id: messageId, conversationId: conversationId) {
Logger.general.debug(category: "DeleteMessageWork", message: "\(self.messageId) Message deleted from database")
self.deleteFile()
self.state = .finished(.success)
}
Expand Down

0 comments on commit 391bbd3

Please sign in to comment.