From 8009b2fdfb43260035f118e293f8528571514d9a Mon Sep 17 00:00:00 2001 From: Egor Kitselyuk Date: Fri, 29 Nov 2024 17:15:08 +0300 Subject: [PATCH 1/2] WMRUSTORE-6: Change token format for MobileApplicationInfoUpdated and MobileApplicationInstalled events --- Mindbox.xcodeproj/project.pbxproj | 4 ++++ .../Bodies/MobileApplicationInfoUpdated.swift | 19 ++++++++++--------- .../Bodies/MobileApplicationInstalled.swift | 18 +++++++++--------- Mindbox/Model/Bodies/TokenData.swift | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 Mindbox/Model/Bodies/TokenData.swift diff --git a/Mindbox.xcodeproj/project.pbxproj b/Mindbox.xcodeproj/project.pbxproj index 1bb83cc3..50f484d5 100644 --- a/Mindbox.xcodeproj/project.pbxproj +++ b/Mindbox.xcodeproj/project.pbxproj @@ -349,6 +349,7 @@ B3F4F982268EEAC90092EC3C /* AmountBenefitsResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3F4F980268EEAC90092EC3C /* AmountBenefitsResponse.swift */; }; B3F4F98A268EEB360092EC3C /* PeriodTypeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3F4F989268EEB360092EC3C /* PeriodTypeResponse.swift */; }; B3F4F98E268EEB4B0092EC3C /* LimitBenefitsResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3F4F98D268EEB4B0092EC3C /* LimitBenefitsResponse.swift */; }; + B4547ECA2CFA0EC6001478AD /* TokenData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4547EC92CFA0EC6001478AD /* TokenData.swift */; }; BB4D7CC72BDEC51D008E3AB8 /* Notification+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB4D7CC62BDEC51D008E3AB8 /* Notification+Extensions.swift */; }; BB6563102BE3BA430090C473 /* UIApplication+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB65630F2BE3BA430090C473 /* UIApplication+Extensions.swift */; }; BBAAC17C2BB2FC9100E1E25E /* MockEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBAAC17B2BB2FC9100E1E25E /* MockEvent.swift */; }; @@ -943,6 +944,7 @@ B3F4F985268EEADE0092EC3C /* LimitBenefitsResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LimitBenefitsResponse.swift; sourceTree = ""; }; B3F4F989268EEB360092EC3C /* PeriodTypeResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeriodTypeResponse.swift; sourceTree = ""; }; B3F4F98D268EEB4B0092EC3C /* LimitBenefitsResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LimitBenefitsResponse.swift; sourceTree = ""; }; + B4547EC92CFA0EC6001478AD /* TokenData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenData.swift; sourceTree = ""; }; BB4D7CC62BDEC51D008E3AB8 /* Notification+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+Extensions.swift"; sourceTree = ""; }; BB65630F2BE3BA430090C473 /* UIApplication+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Extensions.swift"; sourceTree = ""; }; BBAAC17B2BB2FC9100E1E25E /* MockEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockEvent.swift; sourceTree = ""; }; @@ -1923,6 +1925,7 @@ 84C65E5B25D4FB71008996FA /* Bodies */ = { isa = PBXGroup; children = ( + B4547EC92CFA0EC6001478AD /* TokenData.swift */, 84F565202628304A00269FD6 /* TrackVisit.swift */, 84C65E5D25D4FBA3008996FA /* MobileApplicationInstalled.swift */, 84C65E6325D4FBBB008996FA /* MobileApplicationInfoUpdated.swift */, @@ -3547,6 +3550,7 @@ B3F4F982268EEAC90092EC3C /* AmountBenefitsResponse.swift in Sources */, 31A20D4C25B6E0D700AAA0A3 /* MindboxErrors.swift in Sources */, 334F3ADF264C199900A6AC00 /* SubViewProductRequest.swift in Sources */, + B4547ECA2CFA0EC6001478AD /* TokenData.swift in Sources */, F331DD232A84BFDE00222120 /* CustomDecodingError.swift in Sources */, 6FDD1463266F7CED00A50C35 /* ProductElementReponse.swift in Sources */, A192786C29D3A24000CDB53D /* ProductIDChecker.swift in Sources */, diff --git a/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift b/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift index 349e2794..e6d1bb00 100644 --- a/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift +++ b/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift @@ -10,28 +10,29 @@ import Foundation struct MobileApplicationInfoUpdated: Codable { - let notificationProvider: String - - let token: String - - var isTokenAvailable: Bool - let isNotificationsEnabled: Bool let version: Int let instanceId: String + let tokens: [TokenData] + init(token: String?, isNotificationsEnabled: Bool, version: Int, instanceId: String, notificationProvider: String = "APNS") { - self.token = token ?? "" - self.isTokenAvailable = !self.token.isEmpty + + if let tokenValue = token, !tokenValue.isEmpty { + let tokenData = TokenData(token: tokenValue, notificationProvider: notificationProvider) + self.tokens = [tokenData] + } else { + self.tokens = [] + } + self.isNotificationsEnabled = isNotificationsEnabled self.version = version self.instanceId = instanceId - self.notificationProvider = notificationProvider } } diff --git a/Mindbox/Model/Bodies/MobileApplicationInstalled.swift b/Mindbox/Model/Bodies/MobileApplicationInstalled.swift index 5afd37b8..5280c1a5 100644 --- a/Mindbox/Model/Bodies/MobileApplicationInstalled.swift +++ b/Mindbox/Model/Bodies/MobileApplicationInstalled.swift @@ -10,12 +10,6 @@ import Foundation struct MobileApplicationInstalled: Codable { - let notificationProvider: String - - let token: String - - var isTokenAvailable: Bool - let isNotificationsEnabled: Bool let installationId: String @@ -31,6 +25,8 @@ struct MobileApplicationInstalled: Codable { /// ID текущая таймзона устройства в формате IANA, например "Asia/Krasnoyarsk", null если недоступно let ianaTimeZone: String? + let tokens: [TokenData] + init( token: String? = nil, isNotificationsEnabled: Bool, @@ -42,15 +38,19 @@ struct MobileApplicationInstalled: Codable { notificationProvider: String = "APNS", ianaTimeZone: String? ) { - self.token = token ?? "" - self.isTokenAvailable = !self.token.isEmpty + if let tokenValue = token, !tokenValue.isEmpty { + let tokenData = TokenData(token: tokenValue, notificationProvider: notificationProvider) + self.tokens = [tokenData] + } else { + self.tokens = [] + } + self.isNotificationsEnabled = isNotificationsEnabled self.installationId = installationId ?? "" self.subscribe = subscribe ?? false self.externalDeviceUUID = externalDeviceUUID self.version = version self.instanceId = instanceId - self.notificationProvider = notificationProvider self.ianaTimeZone = ianaTimeZone } } diff --git a/Mindbox/Model/Bodies/TokenData.swift b/Mindbox/Model/Bodies/TokenData.swift new file mode 100644 index 00000000..cc088fd8 --- /dev/null +++ b/Mindbox/Model/Bodies/TokenData.swift @@ -0,0 +1,15 @@ +// +// TokenData.swift +// Pods +// +// Created by Egor Kitselyuk on 29.11.2024. +// + +import Foundation + +struct TokenData: Codable { + + let token: String + + let notificationProvider: String +} From c1f7589f60c394ffa9e8c017279865aa0a2799e1 Mon Sep 17 00:00:00 2001 From: Egor Kitselyuk Date: Mon, 2 Dec 2024 20:16:33 +0300 Subject: [PATCH 2/2] WMRUSTORE-6: Add comments --- Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift | 1 + Mindbox/Model/Bodies/MobileApplicationInstalled.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift b/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift index e6d1bb00..a4ad1073 100644 --- a/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift +++ b/Mindbox/Model/Bodies/MobileApplicationInfoUpdated.swift @@ -16,6 +16,7 @@ struct MobileApplicationInfoUpdated: Codable { let instanceId: String + /// Храним единственный токен в массиве, потому что в таком формате его ожидает бекенд let tokens: [TokenData] init(token: String?, diff --git a/Mindbox/Model/Bodies/MobileApplicationInstalled.swift b/Mindbox/Model/Bodies/MobileApplicationInstalled.swift index 5280c1a5..506e613d 100644 --- a/Mindbox/Model/Bodies/MobileApplicationInstalled.swift +++ b/Mindbox/Model/Bodies/MobileApplicationInstalled.swift @@ -25,6 +25,7 @@ struct MobileApplicationInstalled: Codable { /// ID текущая таймзона устройства в формате IANA, например "Asia/Krasnoyarsk", null если недоступно let ianaTimeZone: String? + /// Храним единственный токен в массиве, потому что в таком формате его ожидает бекенд let tokens: [TokenData] init(