Skip to content

Commit

Permalink
🚀 5.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemilla committed Nov 19, 2024
1 parent 4fd26e9 commit 53aec39
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Courier_iOS.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'Courier_iOS'
s.version = '5.2.6'
s.version = '5.2.7'
s.summary = 'Courier makes it easy to add notifications to your app'

s.homepage = 'https://github.com/trycourier/courier-ios'
Expand Down
2 changes: 1 addition & 1 deletion Sources/Courier_iOS/Courier_iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import UIKit
/**
* Versioning
*/
internal static let version = "5.2.6"
internal static let version = "5.2.7"
@objc public static var agent = CourierAgent.nativeIOS(version)

/**
Expand Down
59 changes: 40 additions & 19 deletions Sources/Courier_iOS/Models/CourierInboxData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public class CourierInboxData {
let original = copy()

// Change the local data
await mutateLocalData(with: &messages![index], event: event, inboxFeed: inboxFeed!, index: index, handler: handler)
let canUpdateServerData = await mutateLocalData(with: &messages![index], event: event, inboxFeed: inboxFeed!, index: index, handler: handler)

if !canUpdateServerData {
return
}

// Perform server update
// If fails, reset the change to the original copy
Expand All @@ -124,17 +128,17 @@ public class CourierInboxData {

}

private func mutateLocalData(with message: inout InboxMessage, event: InboxEventType, inboxFeed: InboxMessageFeed, index: Int, handler: InboxMutationHandler) async {
private func mutateLocalData(with message: inout InboxMessage, event: InboxEventType, inboxFeed: InboxMessageFeed, index: Int, handler: InboxMutationHandler) async -> Bool {
switch event {
case .read: await read(&message, index, inboxFeed, handler)
case .unread: await unread(&message, index, inboxFeed, handler)
case .opened: await open(&message, index, inboxFeed, handler)
case .unopened: await unopen(&message, index, inboxFeed, handler)
case .archive: await archive(&message, index, inboxFeed, handler)
case .unarchive: break
case .click: break
case .unclick: break
case .markAllRead: break
case .read: return await read(&message, index, inboxFeed, handler)
case .unread: return await unread(&message, index, inboxFeed, handler)
case .opened: return await open(&message, index, inboxFeed, handler)
case .unopened: return await unopen(&message, index, inboxFeed, handler)
case .archive: return await archive(&message, index, inboxFeed, handler)
case .unarchive: return false
case .click: return false
case .unclick: return false
case .markAllRead: return false
}
}

Expand Down Expand Up @@ -170,10 +174,10 @@ public class CourierInboxData {
await handler.onUnreadCountChange(count: 0)
}

private func read(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async {
private func read(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async -> Bool {

if message.isArchived {
return
return false
}

if !message.isRead {
Expand All @@ -183,14 +187,19 @@ public class CourierInboxData {

unreadCount = max(unreadCount - 1, 0)
await handler.onUnreadCountChange(count: unreadCount)

return true

}

return false

}

private func unread(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async {
private func unread(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async -> Bool {

if message.isArchived {
return
return false
}

if message.isRead {
Expand All @@ -200,29 +209,38 @@ public class CourierInboxData {

unreadCount += 1
await handler.onUnreadCountChange(count: unreadCount)

return true

}

return false

}

private func open(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async {
private func open(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async -> Bool {
if !message.isOpened {
message.setOpened()
await handler.onInboxItemUpdated(at: index, in: inboxFeed, with: message)
return true
}
return false
}

private func unopen(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async {
private func unopen(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async -> Bool {
if message.isOpened {
message.setUnopened()
await handler.onInboxItemUpdated(at: index, in: inboxFeed, with: message)
return true
}
return false
}

private func archive(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async {
private func archive(_ message: inout InboxMessage, _ index: Int, _ inboxFeed: InboxMessageFeed, _ handler: InboxMutationHandler) async -> Bool {
if !message.isArchived {

// Read the message
await read(&message, index, inboxFeed, handler)
let _ = await read(&message, index, inboxFeed, handler)

// Change archived status
message.setArchived()
Expand All @@ -241,7 +259,10 @@ public class CourierInboxData {
await handler.onInboxItemAdded(at: insertIndex, in: .archived, with: message)
}

return true

}
return false
}

private func findInsertIndex(for newMessage: InboxMessage, in messages: [InboxMessage]) -> Int? {
Expand Down

0 comments on commit 53aec39

Please sign in to comment.