Skip to content

Commit

Permalink
chore(notifications): resolve swiftformat errors and warnings (#3853)
Browse files Browse the repository at this point in the history
* chore(notifications): resolve swiftformat errors and warnings

* updated swiftformat rules
  • Loading branch information
phantumcode authored Sep 16, 2024
1 parent 47601cd commit fe989b5
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@ import UIKit
import AppKit
#endif

extension AWSPinpointPushNotificationsPlugin {
public func identifyUser(userId: String, userProfile: UserProfile?) async throws {
public extension AWSPinpointPushNotificationsPlugin {
func identifyUser(userId: String, userProfile: UserProfile?) async throws {
var currentEndpointProfile = await pinpoint.currentEndpointProfile()
currentEndpointProfile.addUserId(userId)
if let userProfile = userProfile {
if let userProfile {
currentEndpointProfile.addUserProfile(userProfile)
}
try await pinpoint.updateEndpoint(with: currentEndpointProfile,
source: .pushNotifications)
try await pinpoint.updateEndpoint(
with: currentEndpointProfile,
source: .pushNotifications
)
}

public func registerDevice(apnsToken: Data) async throws {
func registerDevice(apnsToken: Data) async throws {
var currentEndpointProfile = await pinpoint.currentEndpointProfile()
currentEndpointProfile.setAPNsToken(apnsToken)
do {
try await pinpoint.updateEndpoint(with: currentEndpointProfile,
source: .pushNotifications)
try await pinpoint.updateEndpoint(
with: currentEndpointProfile,
source: .pushNotifications
)
} catch {
throw error.pushNotificationsError
}
}

public func recordNotificationReceived(_ userInfo: Notifications.Push.UserInfo) async throws {
let applicationState = await self.applicationState
func recordNotificationReceived(_ userInfo: Notifications.Push.UserInfo) async throws {
let applicationState = await applicationState
await recordNotification(
userInfo,
applicationState: applicationState,
Expand All @@ -50,8 +54,8 @@ extension AWSPinpointPushNotificationsPlugin {
}

#if !os(tvOS)
public func recordNotificationOpened(_ response: UNNotificationResponse) async throws {
let applicationState = await self.applicationState
func recordNotificationOpened(_ response: UNNotificationResponse) async throws {
let applicationState = await applicationState
await recordNotification(
response.notification.request.content.userInfo,
applicationState: applicationState,
Expand All @@ -63,24 +67,28 @@ extension AWSPinpointPushNotificationsPlugin {
/// Retrieves the escape hatch to perform actions directly on PinpointClient.
///
/// - Returns: PinpointClientProtocol instance
public func getEscapeHatch() -> PinpointClientProtocol {
func getEscapeHatch() -> PinpointClientProtocol {
pinpoint.pinpointClient
}

private func recordNotification(_ userInfo: [String: Any],
applicationState: ApplicationState,
action: PushNotification.Action) async {
let userInfo: PushNotification.UserInfo = Dictionary(uniqueKeysWithValues: userInfo.map({($0, $1)}))
private func recordNotification(
_ userInfo: [String: Any],
applicationState: ApplicationState,
action: PushNotification.Action
) async {
let userInfo: PushNotification.UserInfo = Dictionary(uniqueKeysWithValues: userInfo.map {($0, $1)})
await recordNotification(
userInfo,
applicationState: applicationState,
action: action
)
}

private func recordNotification(_ userInfo: PushNotification.UserInfo,
applicationState: ApplicationState,
action: PushNotification.Action) async {
private func recordNotification(
_ userInfo: PushNotification.UserInfo,
applicationState: ApplicationState,
action: PushNotification.Action
) async {
// Retrieve the payload from the notification
guard let payload = userInfo.payload else {
log.error(
Expand All @@ -99,8 +107,10 @@ extension AWSPinpointPushNotificationsPlugin {

// Add application state
let applicationStateAttribute = applicationState.pinpointAttribute
pushNotificationEvent.addAttribute(applicationStateAttribute.value,
forKey: applicationStateAttribute.key)
pushNotificationEvent.addAttribute(
applicationStateAttribute.value,
forKey: applicationStateAttribute.key
)

// Set global remote attributes
await pinpoint.setRemoteGlobalAttributes(payload.attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ extension AWSPinpointPushNotificationsPlugin {

pluginConfiguration = AWSPinpointPluginConfiguration(
appId: notifications.amazonPinpointAppId,
region: notifications.awsRegion)
region: notifications.awsRegion
)
} else if let config = configuration as? JSONValue {
pluginConfiguration = try AWSPinpointPluginConfiguration(config)
} else {
Expand All @@ -51,8 +52,10 @@ extension AWSPinpointPushNotificationsPlugin {
region: configuration.region
)

configure(pinpoint: pinpoint,
remoteNotificationsHelper: .default)
configure(
pinpoint: pinpoint,
remoteNotificationsHelper: .default
)
}

private func requestNotificationsPermissions(using helper: RemoteNotificationsBehaviour) async {
Expand All @@ -70,8 +73,10 @@ extension AWSPinpointPushNotificationsPlugin {

// MARK: Internal
/// Internal configure method to set the properties of the plugin
func configure(pinpoint: AWSPinpointBehavior,
remoteNotificationsHelper: RemoteNotificationsBehaviour) {
func configure(
pinpoint: AWSPinpointBehavior,
remoteNotificationsHelper: RemoteNotificationsBehaviour
) {
self.pinpoint = pinpoint
Task {
await remoteNotificationsHelper.registerForRemoteNotifications()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import Foundation

extension AWSPinpointPushNotificationsPlugin {
public func reset() async {
public extension AWSPinpointPushNotificationsPlugin {
func reset() async {
if pinpoint != nil {
pinpoint = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import AmplifyUtilsNotifications
import Foundation

extension AWSPinpointPushNotificationsPlugin {
public extension AWSPinpointPushNotificationsPlugin {

#if !os(tvOS)
/// Service Extension that can handle AWS Pinpoint rich notifications.
public typealias ServiceExtension = AUNotificationService
typealias ServiceExtension = AUNotificationService
#endif

/// A protocol that can be used to customize the expeded payload that the ServiceExtension can handle.
public typealias NotificationPayload = AUNotificationPayload
typealias NotificationPayload = AUNotificationPayload
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import AwsCommonRuntimeKit
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint

extension CommonRunTimeError: PushNotificationsErrorConvertible {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import AWSClientRuntime
import AWSPinpoint
import ClientRuntime
import AWSClientRuntime
import Foundation

private func recoverySuggestion(for error: ClientRuntime.ModeledError) -> String {
type(of: error).isRetryable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

protocol PushNotificationsErrorConvertible {
var pushNotificationsError: PushNotificationsError { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import Foundation
extension PushNotification.UserInfo {
private var root: [String: Any]? {
guard let data = self[Constants.Keys.data] as? [String: Any],
let root = data[Constants.Keys.pinpoint] as? [String: Any] else {
let root = data[Constants.Keys.pinpoint] as? [String: Any]
else {
return nil
}

return root
}

var payload: PushNotification.Payload? {
guard let root = root else {
guard let root else {
return nil
}

Expand All @@ -42,8 +43,8 @@ extension PushNotification.UserInfo {
}

extension PushNotification.UserInfo {
private struct Constants {
struct Keys {
private enum Constants {
enum Keys {
static let data = "data"
static let pinpoint = "pinpoint"
static let campaing = "campaign"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

typealias PushNotificationsPluginErrorString = (errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion)

struct PushNotificationsPluginErrorConstants {
enum PushNotificationsPluginErrorConstants {
static let decodeConfigurationError: PushNotificationsPluginErrorString = (
"Unable to decode configuration",
"Make sure the plugin configuration is JSONValue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
import AWSPinpointPushNotificationsPlugin
import XCTest

class AWSPinpointPushNotificationsPluginAmplifyVersionableTests: AWSPinpointPushNotificationsPluginTestBase {
func testVersion_shouldReturnNotNil() {
Expand Down
Loading

0 comments on commit fe989b5

Please sign in to comment.