Commit 8673da12 authored by Jose Blaya's avatar Jose Blaya
Browse files

DIP expiring notification

parent 2040e188
......@@ -250,6 +250,8 @@
82C4962A25642D5800233CB1 /* String+Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82C4962825642D5800233CB1 /* String+Random.swift */; };
82CAB808255A9ACB00BB08EF /* InAppMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CAB807255A9ACB00BB08EF /* InAppMessage.swift */; };
82CAB809255A9ACB00BB08EF /* InAppMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CAB807255A9ACB00BB08EF /* InAppMessage.swift */; };
82CDC2E2257A5B440001669D /* DateUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CDC2E1257A5B440001669D /* DateUtil.swift */; };
82CDC2E3257A5B440001669D /* DateUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CDC2E1257A5B440001669D /* DateUtil.swift */; };
82DDD5302539CFDC0049E79E /* DIPTokenKeychainTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82DDD52F2539CFDC0049E79E /* DIPTokenKeychainTests.swift */; };
82E20B1124F652ED0065EFE3 /* AccountInfo+Kotlin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E20B1024F652ED0065EFE3 /* AccountInfo+Kotlin.swift */; };
82E20B1224F652ED0065EFE3 /* AccountInfo+Kotlin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E20B1024F652ED0065EFE3 /* AccountInfo+Kotlin.swift */; };
......@@ -574,6 +576,7 @@
82C374FA2514DEC700E391EE /* EndpointManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EndpointManager.swift; sourceTree = "<group>"; };
82C4962825642D5800233CB1 /* String+Random.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Random.swift"; sourceTree = "<group>"; };
82CAB807255A9ACB00BB08EF /* InAppMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppMessage.swift; sourceTree = "<group>"; };
82CDC2E1257A5B440001669D /* DateUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateUtil.swift; sourceTree = "<group>"; };
82DDD52F2539CFDC0049E79E /* DIPTokenKeychainTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DIPTokenKeychainTests.swift; sourceTree = "<group>"; };
82E20B1024F652ED0065EFE3 /* AccountInfo+Kotlin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AccountInfo+Kotlin.swift"; sourceTree = "<group>"; };
82E20B1524F6AA110065EFE3 /* RegionData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionData.swift; sourceTree = "<group>"; };
......@@ -701,6 +704,7 @@
DDD824E4218996CD00151709 /* Pages.swift */,
DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */,
DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */,
82CDC2E1257A5B440001669D /* DateUtil.swift */,
);
path = Util;
sourceTree = "<group>";
......@@ -1654,6 +1658,7 @@
buildActionMask = 2147483647;
files = (
0E492C5F1FE5F7C0007F23DF /* MockAccountProvider.swift in Sources */,
82CDC2E3257A5B440001669D /* DateUtil.swift in Sources */,
0E392DBC1FE34B5A0002160D /* NSString+URL.m in Sources */,
84125E0C213D7E0E001BCC19 /* PIAFonts.swift in Sources */,
0E3D13DA1F9E273300434A48 /* GlossSignup.swift in Sources */,
......@@ -1902,6 +1907,7 @@
0EFEB4C12007784A00F81029 /* PIATunnelProvider+Profile.swift in Sources */,
DD8C3E612327EF4C00BAD18E /* IKEv2IntegrityAlgorithm.swift in Sources */,
0E392DA31FE3247E0002160D /* Endpoint.swift in Sources */,
82CDC2E2257A5B440001669D /* DateUtil.swift in Sources */,
0E53A8581FE5DA16000C2A18 /* MockInAppProvider.swift in Sources */,
822BC1D024BF20C90041BF9A /* UIControl+Action.swift in Sources */,
DDD824E32189969400151709 /* Preset.swift in Sources */,
......
......@@ -26,6 +26,8 @@ import Foundation
public struct NotificationKey: Hashable {
static let products = NotificationKey("ProductsKey")
public static let token = NotificationKey("TokenKey")
/// An `UserAccount` object.
public static let user = NotificationKey("UserKey")
......
......@@ -56,6 +56,8 @@ extension Notification.Name {
public static let PIAPersistentConnectionSettingHaveChanged = Notification.Name("PIAPersistentConnectionSettingHaveChanged")
public static let PIAPersistentConnectionTileHaveChanged = Notification.Name("PIAPersistentConnectionTileHaveChanged")
public static let PIADIPRegionExpiring = Notification.Name("PIADIPRegionExpiring")
}
extension NotificationKey {
......
......@@ -248,6 +248,11 @@ class PIAWebServices: WebServices, ConfigurationAccess {
let status = DedicatedIPStatus(fromAPIStatus: dipServer.status)
let server = Server.ServerAddressIP(ip: ip, cn: cn)
if let nextDays = Calendar.current.date(byAdding: .day, value: 5, to: Date()), nextDays >= expiringDate {
//Expiring in 5 days or less
Macros.postNotification(.PIADIPRegionExpiring, [.token : token])
}
let dipUsername = "dedicated_ip_"+dipServer.dipToken+"_"+String.random(length: 8)
let dipRegion = Server(serial: firstServer.serial, name: firstServer.name, country: firstServer.country, hostname: firstServer.hostname, openVPNAddressesForTCP: [server], openVPNAddressesForUDP: [server], wireGuardAddressesForUDP: [server], iKEv2AddressesForUDP: [server], pingAddress: firstServer.pingAddress, geo: false, meta: nil, dipExpire: expiringDate, dipToken: dipServer.dipToken, dipStatus: status, dipUsername: dipUsername, regionIdentifier: firstServer.regionIdentifier)
......
//
// DateUtil.swift
// PIALibrary
//
// Created by Jose Blaya on 04/12/2020.
// Copyright © 2020 Private Internet Access, Inc.
//
// This file is part of the Private Internet Access iOS Client.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import Foundation
public extension Date {
public func removing(minutes: Int) -> Date? {
let result = Calendar.current.date(byAdding: .minute, value: -(minutes), to: self)
return result
}
public func removing(hours: Int) -> Date? {
let result = Calendar.current.date(byAdding: .hour, value: -(hours), to: self)
return result
}
public func removing(days: Int) -> Date? {
let result = Calendar.current.date(byAdding: .day, value: -(days), to: self)
return result
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment