Commit 226c0aab authored by Jose Blaya's avatar Jose Blaya

Present expiring DIP token from a notification

parent 80e8766a
......@@ -208,8 +208,6 @@
82A1AD3024B87CF20003DD02 /* PIACard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82A1AD2E24B87CF20003DD02 /* PIACard.swift */; };
82C0071325231F2800F21AF2 /* String+VPNType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82C0071225231F2800F21AF2 /* String+VPNType.swift */; };
82C0071425231F2800F21AF2 /* String+VPNType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82C0071225231F2800F21AF2 /* String+VPNType.swift */; };
82C495B82562A53000233CB1 /* DateUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82C495B72562A53000233CB1 /* DateUtil.swift */; };
82C495B92562A53000233CB1 /* DateUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82C495B72562A53000233CB1 /* DateUtil.swift */; };
82CAB87A255AEA3500BB08EF /* MessagesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CAB879255AEA3500BB08EF /* MessagesManager.swift */; };
82CAB87B255AEA3500BB08EF /* MessagesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CAB879255AEA3500BB08EF /* MessagesManager.swift */; };
82CAB8B0255B050000BB08EF /* MessagesCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CAB8AF255B050000BB08EF /* MessagesCommands.swift */; };
......@@ -632,7 +630,6 @@
82A1AD2824B87CCD0003DD02 /* PIACard.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PIACard.xib; sourceTree = "<group>"; };
82A1AD2E24B87CF20003DD02 /* PIACard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIACard.swift; sourceTree = "<group>"; };
82C0071225231F2800F21AF2 /* String+VPNType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+VPNType.swift"; sourceTree = "<group>"; };
82C495B72562A53000233CB1 /* DateUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateUtil.swift; sourceTree = "<group>"; };
82CAB879255AEA3500BB08EF /* MessagesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesManager.swift; sourceTree = "<group>"; };
82CAB8AF255B050000BB08EF /* MessagesCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesCommands.swift; sourceTree = "<group>"; };
82CAB8D9255BEC7000BB08EF /* PIACommandTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIACommandTests.swift; sourceTree = "<group>"; };
......@@ -928,7 +925,6 @@
DD918575246BFA7F006B3A2B /* RatingManager.swift */,
DDD65312247E66AD00F0A897 /* CoordinatesFinder.swift */,
829EB51B2535A8FF003E74DD /* CollectionViewAutoSizeUtils.swift */,
82C495B72562A53000233CB1 /* DateUtil.swift */,
);
name = Utils;
sourceTree = "<group>";
......@@ -2111,7 +2107,6 @@
82CAB8B1255B050000BB08EF /* MessagesCommands.swift in Sources */,
DD4E84582243BD1200929B39 /* DashboardCollectionViewUtil.swift in Sources */,
DD74695B217F07AC00B7BD73 /* DNSList.swift in Sources */,
82C495B92562A53000233CB1 /* DateUtil.swift in Sources */,
0E9452AF1FDB5F7A00891948 /* PIAPageControl.swift in Sources */,
DDD271F121D6718F00B6D20F /* RegionFilter.swift in Sources */,
);
......@@ -2217,7 +2212,6 @@
DDFCFA8F21E892070081F235 /* RegionTileCollectionViewCell.swift in Sources */,
0E2215CC2008BF8300F5FB4D /* SwiftGen+Assets.swift in Sources */,
DD3B504624B758330002F4B5 /* Collectable.swift in Sources */,
82C495B82562A53000233CB1 /* DateUtil.swift in Sources */,
DD9706A4224262BF00630220 /* QuickSettingsTile.swift in Sources */,
82183D7B2500FD460033023F /* String+Substrings.swift in Sources */,
DDFCFA9421E892130081F235 /* RegionTile.swift in Sources */,
......
......@@ -605,6 +605,7 @@ class AppPreferences {
failureConnections = 0
showGeoServers = true
dedicatedTokenIPReleation = [:]
MessagesManager.shared.reset()
}
func clean() {
......@@ -635,6 +636,7 @@ class AppPreferences {
showGeoServers = true
dismissedMessages = []
dedicatedTokenIPReleation = [:]
MessagesManager.shared.reset()
}
// + (void)eraseForTesting;
......
//
// DateUtil.swift
// PIA VPN
//
// Created by Jose Blaya on 16/11/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
extension Date {
func removing(minutes: Int) -> Date? {
let result = Calendar.current.date(byAdding: .minute, value: -(minutes), to: self)
return result
}
func removing(hours: Int) -> Date? {
let result = Calendar.current.date(byAdding: .hour, value: -(hours), to: self)
return result
}
func removing(days: Int) -> Date? {
let result = Calendar.current.date(byAdding: .day, value: -(days), to: self)
return result
}
}
......@@ -90,14 +90,6 @@ class DedicatedIpEmptyHeaderViewCell: UITableViewCell {
return
}
if let expiringDate = dipServer?.dipExpire, let substractedDate = expiringDate.removing(days: 5) {
if Calendar.current.isDateInToday(substractedDate) {
//Expiring in 5 days
let message = InAppMessage(withMessage: ["en": L10n.Dedicated.Ip.Message.Token.willexpire], id: token, link: ["en": L10n.Dedicated.Ip.Message.Token.Willexpire.link], type: .link, level: .system, actions: nil, view: nil, uri: AppConstants.Web.homeURL.absoluteString)
MessagesManager.shared.postSystemMessage(message: message)
}
}
var relation = AppPreferences.shared.dedicatedTokenIPReleation
if relation.isEmpty {
//no data
......
......@@ -29,6 +29,15 @@ public class MessagesManager: NSObject {
private var apiMessage: InAppMessage!
private var systemMessage: InAppMessage!
public override init() {
super.init()
NotificationCenter.default.addObserver(self, selector: #selector(presentExpiringDIPRegionSystemMessage(notification:)), name: .PIADIPRegionExpiring, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
func refreshMessages() {
Client.providers.accountProvider.inAppMessages(forAppVersion: Macros.localizedVersionNumber()) { (message, error) in
......@@ -67,6 +76,11 @@ public class MessagesManager: NSObject {
}
}
func reset() {
self.apiMessage = nil
self.systemMessage = nil
}
private func updateMessages() -> InAppMessage? {
return nil
}
......@@ -151,3 +165,15 @@ extension InAppMessage {
}
}
extension MessagesManager {
@objc private func presentExpiringDIPRegionSystemMessage(notification: Notification) {
if let userInfo = notification.userInfo, let token = userInfo[NotificationKey.token] as? String {
let message = InAppMessage(withMessage: ["en": L10n.Dedicated.Ip.Message.Token.willexpire], id: token, link: ["en": L10n.Dedicated.Ip.Message.Token.Willexpire.link], type: .link, level: .system, actions: nil, view: nil, uri: AppConstants.Web.homeURL.absoluteString)
MessagesManager.shared.postSystemMessage(message: message)
}
}
}
......@@ -75,7 +75,7 @@ def shared_main_pods
#library_by_path('/Users/jose/Projects/PIA')
#library_by_git('ba3cd1f')
#library_by_gitlab_branch('develop')
library_by_gitlab_by_git('2040e18')
library_by_gitlab_by_git('8673da1')
#library_by_version('~> 1.1.3')
end
......
......@@ -151,10 +151,10 @@ DEPENDENCIES:
- Firebase/Core (= 6.5.0)
- GradientProgressBar (~> 2.0)
- "PIAAccountModule (from `git@codex.londontrustmedia.com:mobile/account.git`, commit `6116a38`)"
- PIALibrary/Library (from `/Users/jose/Projects/PIA/client-library-apple`)
- PIALibrary/Mock (from `/Users/jose/Projects/PIA/client-library-apple`)
- PIALibrary/UI (from `/Users/jose/Projects/PIA/client-library-apple`)
- PIALibrary/VPN (from `/Users/jose/Projects/PIA/client-library-apple`)
- "PIALibrary/Library (from `git@codex.londontrustmedia.com:ios/client-library-apple.git`, commit `8673da1`)"
- "PIALibrary/Mock (from `git@codex.londontrustmedia.com:ios/client-library-apple.git`, commit `8673da1`)"
- "PIALibrary/UI (from `git@codex.londontrustmedia.com:ios/client-library-apple.git`, commit `8673da1`)"
- "PIALibrary/VPN (from `git@codex.londontrustmedia.com:ios/client-library-apple.git`, commit `8673da1`)"
- "PIARegions (from `git@codex.londontrustmedia.com:mobile/regions.git`, commit `3b9395f`)"
- PIAWireguard (from `https://github.com/pia-foss/ios-wireguard`)
- Popover
......@@ -201,7 +201,8 @@ EXTERNAL SOURCES:
:commit: 6116a38
:git: "git@codex.londontrustmedia.com:mobile/account.git"
PIALibrary:
:path: "/Users/jose/Projects/PIA/client-library-apple"
:commit: 8673da1
:git: "git@codex.londontrustmedia.com:ios/client-library-apple.git"
PIARegions:
:commit: 3b9395f
:git: "git@codex.londontrustmedia.com:mobile/regions.git"
......@@ -215,6 +216,9 @@ CHECKOUT OPTIONS:
PIAAccountModule:
:commit: 6116a38
:git: "git@codex.londontrustmedia.com:mobile/account.git"
PIALibrary:
:commit: 8673da1
:git: "git@codex.londontrustmedia.com:ios/client-library-apple.git"
PIARegions:
:commit: 3b9395f
:git: "git@codex.londontrustmedia.com:mobile/regions.git"
......@@ -261,6 +265,6 @@ SPEC CHECKSUMS:
TunnelKit: 1733ed87934deb57edc7aa5f4b25185bf302a7d4
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
PODFILE CHECKSUM: 0876c502b108b080328b86e1488171d3fc0322e6
PODFILE CHECKSUM: 81391fc96f3771a369e7c3b26e2f73dc862e34ef
COCOAPODS: 1.9.3
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