Skip to content

Commit

Permalink
fixed mark read being slow
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews committed Nov 2, 2023
1 parent 4095e7b commit e484c8e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Mlem/Models/Content/Inbox/MentionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,16 @@ extension MentionModel {

// state fake
await setPersonMention(APIPersonMention(from: personMention, read: !personMention.read))
await unreadTracker.toggleMentionRead(originalState: originalPersonMention.read)

// call API and either update with latest info or revert state fake on fail
do {
let newMessage = try await inboxRepository.markMentionRead(id: personMention.id, isRead: personMention.read)
await unreadTracker.toggleMentionRead(originalState: originalPersonMention.read)
await reinit(from: newMessage)
} catch {
hapticManager.play(haptic: .failure, priority: .high)
errorHandler.handle(error)
await setPersonMention(originalPersonMention)
await unreadTracker.toggleMentionRead(originalState: !originalPersonMention.read)
}
}

Expand Down
3 changes: 1 addition & 2 deletions Mlem/Models/Content/Inbox/MessageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ class MessageModel: ContentIdentifiable, ObservableObject {

// state fake
await setPrivateMessage(APIPrivateMessage(from: privateMessage, read: !privateMessage.read))
await unreadTracker.toggleMessageRead(originalState: originalPrivateMessage.read)

// call API and either update with latest info or revert state fake on fail
do {
let newMessage = try await inboxRepository.markMessageRead(id: privateMessage.id, isRead: privateMessage.read)
await unreadTracker.toggleMessageRead(originalState: originalPrivateMessage.read)
await reinit(from: newMessage)
} catch {
hapticManager.play(haptic: .failure, priority: .high)
errorHandler.handle(error)
await setPrivateMessage(originalPrivateMessage)
await unreadTracker.toggleMessageRead(originalState: !originalPrivateMessage.read)
}
}

Expand Down
3 changes: 1 addition & 2 deletions Mlem/Models/Content/Inbox/ReplyModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,16 @@ extension ReplyModel {

// state fake
await setCommentReply(APICommentReply(from: commentReply, read: !commentReply.read))
await unreadTracker.toggleReplyRead(originalState: originalCommentReply.read)

// call API and either update with latest info or revert state fake on fail
do {
let newReply = try await inboxRepository.markReplyRead(id: commentReply.id, isRead: commentReply.read)
await unreadTracker.toggleReplyRead(originalState: originalCommentReply.read)
await reinit(from: newReply)
} catch {
hapticManager.play(haptic: .failure, priority: .high)
errorHandler.handle(error)
await setCommentReply(originalCommentReply)
await unreadTracker.toggleReplyRead(originalState: !originalCommentReply.read)
}
}

Expand Down

0 comments on commit e484c8e

Please sign in to comment.