Skip to content

Commit

Permalink
fix: classes renamed to avoid incompatibility issues (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlsCorrea authored Jul 28, 2022
1 parent 9ccea5b commit 55bc04b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository.

## [Released]

## 28-07-2022
- Renamed classes to avoid incompatibility. (https://outsystemsrd.atlassian.net/browse/RMET-1743)

## 26-07-2022
- Added dependency on external libs. Changed methods to sync. (https://outsystemsrd.atlassian.net/browse/RMET-1480)

Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
<source-file src="src/ios/Managers/MessagingManager.swift" />
<source-file src="src/ios/Managers/NotificationManager.swift" />

<source-file src="src/ios/Model/OSExtraData.swift" />
<source-file src="src/ios/Model/OSNotification.swift" />
<source-file src="src/ios/Model/OSFCMExtraData.swift" />
<source-file src="src/ios/Model/OSFCMNotification.swift" />

<source-file src="src/ios/Protocols/FirebaseMessagingProtocol.swift" />
<source-file src="src/ios/Protocols/MessagingProtocol.swift" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>NotificationsModel 2.xcdatamodel</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="20086" systemVersion="21F79" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="NotificationsModel">
<entity name="OSFCMExtraData" representedClassName="OSFCMExtraData" syncable="YES" codeGenerationType="category">
<attribute name="key" optional="YES" attributeType="String"/>
<attribute name="value" optional="YES" attributeType="String"/>
<relationship name="notification" maxCount="1" deletionRule="Nullify" destinationEntity="OSFCMNotification" inverseName="extraDataList" inverseEntity="OSFCMNotification"/>
</entity>
<entity name="OSFCMNotification" representedClassName="OSFCMNotification" syncable="YES" codeGenerationType="category">
<attribute name="messageID" attributeType="String"/>
<attribute name="timeStamp" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="timeToLive" attributeType="String"/>
<relationship name="extraDataList" toMany="YES" deletionRule="Cascade" destinationEntity="OSFCMExtraData" inverseName="notification" inverseEntity="OSFCMExtraData"/>
</entity>
<elements>
<element name="OSFCMExtraData" positionX="-63" positionY="9" width="128" height="74"/>
<element name="OSFCMNotification" positionX="-63" positionY="-18" width="128" height="89"/>
</elements>
</model>
8 changes: 4 additions & 4 deletions src/ios/FirebaseMessagingApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ extension FirebaseMessagingApplicationDelegate {
let extraData = userInfo[JSONKeys.extraDataList] as? [NotificationDictionary] {

let notificationDict: [String: Any] = [
OSNotification.CodingKeys.messageID.rawValue: messageID,
OSNotification.CodingKeys.timeToLive.rawValue: timeToLive,
OSNotification.CodingKeys.extraDataList.rawValue: extraData,
OSNotification.CodingKeys.timeStamp.rawValue: Date().millisecondsSince1970
OSFCMNotification.CodingKeys.messageID.rawValue: messageID,
OSFCMNotification.CodingKeys.timeToLive.rawValue: timeToLive,
OSFCMNotification.CodingKeys.extraDataList.rawValue: extraData,
OSFCMNotification.CodingKeys.timeStamp.rawValue: Date().millisecondsSince1970
]
_ = notificationManager.insertNotification(notificationDict: notificationDict)
}
Expand Down
12 changes: 6 additions & 6 deletions src/ios/Managers/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public protocol NotificationManagerProtocol {

/// Fetches the store notifications on Core Data.
/// - Returns: An array of notifications or an error, in case of failure.
func fetchNotifications() -> Result<[OSNotification], Error>
func fetchNotifications() -> Result<[OSFCMNotification], Error>

/// Sends a local notification on to the Notification Center.
/// - Parameters:
Expand Down Expand Up @@ -65,8 +65,8 @@ public final class NotificationManager: NSObject {
/// Deletes all notifications provided by input from Core Data manager.
/// - Parameter notifications: Notifications to remove.
/// - Returns: A boolean indicating the success of the operation or an error, in case of failure.
public func deletePendingNotifications(_ notifications: [OSNotification]) -> Result<Bool, Error> {
let fetchRequest: NSFetchRequest<OSNotification> = OSNotification.fetchRequest()
public func deletePendingNotifications(_ notifications: [OSFCMNotification]) -> Result<Bool, Error> {
let fetchRequest: NSFetchRequest<OSFCMNotification> = OSFCMNotification.fetchRequest()
do {
let fetchRequestResults = try self.coreDataManager.fetch(fetchRequest)
let filtered = fetchRequestResults.filter({ notifications.contains($0) })
Expand Down Expand Up @@ -119,7 +119,7 @@ extension NotificationManager: NotificationManagerProtocol {
decoder.userInfo[CodingUserInfoKey.managedObjectContext] = self.coreDataManager.context()
do {
let notificationData = try JSONSerialization.data(withJSONObject: notificationDict)
_ = try decoder.decode(OSNotification.self, from: notificationData)
_ = try decoder.decode(OSFCMNotification.self, from: notificationData)

try self.coreDataManager.saveContext()
} catch {
Expand All @@ -131,8 +131,8 @@ extension NotificationManager: NotificationManagerProtocol {

/// Fetches the store notifications on Core Data.
/// - Returns: An array of notifications or an error, in case of failure.
public func fetchNotifications() -> Result<[OSNotification], Error> {
let fetchRequest: NSFetchRequest<OSNotification> = OSNotification.fetchRequest()
public func fetchNotifications() -> Result<[OSFCMNotification], Error> {
let fetchRequest: NSFetchRequest<OSFCMNotification> = OSFCMNotification.fetchRequest()
do {
let notifications = try self.coreDataManager.fetch(fetchRequest)
return .success(notifications)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import CoreData

/// Core Data Model that stores the dynamic properties associated with a specific Notification.
@objc(OSExtraData)
public class OSExtraData: NSManagedObject, Codable {
@objc(OSFCMExtraData)
public class OSFCMExtraData: NSManagedObject, Codable {

/// Constructor method inherited from `NSManagedObject`.
/// - Parameters:
Expand All @@ -20,7 +20,7 @@ public class OSExtraData: NSManagedObject, Codable {
init(key: String,
value: String,
context: NSManagedObjectContext) {
super.init(entity: NSEntityDescription.entity(forEntityName: "OSExtraData", in: context)!, insertInto: context)
super.init(entity: NSEntityDescription.entity(forEntityName: "OSFCMExtraData", in: context)!, insertInto: context)
self.key = key
self.value = value
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import CoreData

/// Core Data Model that stores the properties associated with a Notification.
@objc(OSNotification)
public class OSNotification: NSManagedObject, Codable {
@objc(OSFCMNotification)
public class OSFCMNotification: NSManagedObject, Codable {

/// Constructor method inherited from `NSManagedObject`.
/// - Parameters:
Expand All @@ -20,11 +20,11 @@ public class OSNotification: NSManagedObject, Codable {
/// - timeStamp: Numeric representation of the creation datetime,
/// - context: An object space to manipulate and track changes to managed objects.
init(messageID: String,
extraDataList: [OSExtraData],
extraDataList: [OSFCMExtraData],
timeToLive: String,
timeStamp: Double,
context: NSManagedObjectContext) {
super.init(entity: NSEntityDescription.entity(forEntityName: "OSNotification", in: context)!, insertInto: context)
super.init(entity: NSEntityDescription.entity(forEntityName: "OSFCMNotification", in: context)!, insertInto: context)
self.messageID = messageID
self.extraDataList = NSSet(array: extraDataList)
self.timeToLive = timeToLive
Expand All @@ -41,7 +41,7 @@ public class OSNotification: NSManagedObject, Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(messageID, forKey: .messageID)
try container.encode(extraDataList?.allObjects as? [OSExtraData], forKey: .extraDataList)
try container.encode(extraDataList?.allObjects as? [OSFCMExtraData], forKey: .extraDataList)
try container.encode(timeToLive, forKey: .timeToLive)
try container.encode(timeStamp, forKey: .timeStamp)
}
Expand All @@ -55,7 +55,7 @@ public class OSNotification: NSManagedObject, Codable {

let container = try decoder.container(keyedBy: CodingKeys.self)
let messageID = try container.decode(String.self, forKey: .messageID)
let extraDataList = try container.decode([OSExtraData].self, forKey: .extraDataList)
let extraDataList = try container.decode([OSFCMExtraData].self, forKey: .extraDataList)
let timeToLive = try container.decode(String.self, forKey: .timeToLive)
let timeStamp = try container.decode(Double.self, forKey: .timeStamp)
self.init(messageID: messageID, extraDataList: extraDataList, timeToLive: timeToLive, timeStamp: timeStamp, context: context)
Expand Down

0 comments on commit 55bc04b

Please sign in to comment.