Manos Chorianopoulos

fix questionnaire campaign disappear after answer

...@@ -41,6 +41,27 @@ import SwiftEventBus ...@@ -41,6 +41,27 @@ import SwiftEventBus
41 41
42 if (eventArray[0] == "event") { 42 if (eventArray[0] == "event") {
43 if (eventArray[1] == "closeArtwork") { 43 if (eventArray[1] == "closeArtwork") {
44 +
45 + swiftApi().getProfileAsync(getProfileCallback)
46 +
47 + func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void {
48 + if (profileData != nil) {
49 + DispatchQueue.main.async {
50 + swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback)
51 +
52 + func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
53 + if (campaignsData != nil) {
54 + DispatchQueue.main.async {
55 + }
56 + } else {
57 + }
58 + }
59 +
60 + }
61 + } else {
62 + }
63 + }
64 +
44 self.navigationController?.popViewController(animated: true) 65 self.navigationController?.popViewController(animated: true)
45 66
46 } else if (eventArray[1] == "addUserTag") { 67 } else if (eventArray[1] == "addUserTag") {
......
...@@ -797,13 +797,18 @@ public class swiftApi { ...@@ -797,13 +797,18 @@ public class swiftApi {
797 797
798 SwiftEventBus.post("campaigns_retrieved") 798 SwiftEventBus.post("campaigns_retrieved")
799 799
800 - let filteredCampaigns = campaignsArray.filter { 800 + var filteredCampaigns = campaignsArray.filter {
801 let tempCampaign = $0 801 let tempCampaign = $0
802 let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") 802 let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true")
803 let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco") 803 let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco")
804 804
805 return (!(isCcmsOffer || isTelco)) 805 return (!(isCcmsOffer || isTelco))
806 } 806 }
807 +
808 + if (swiftApi().getConsumer()?.answered == true) {
809 + filteredCampaigns = filteredCampaigns.filter { $0.offer_category != "questionnaire" }
810 + }
811 +
807 getCampaignsCallback(filteredCampaigns); 812 getCampaignsCallback(filteredCampaigns);
808 }) 813 })
809 814
...@@ -1400,6 +1405,7 @@ public class swiftApi { ...@@ -1400,6 +1405,7 @@ public class swiftApi {
1400 // profile_metadata 1405 // profile_metadata
1401 public let badge: String? 1406 public let badge: String?
1402 public let msisdnList: Array<String>? 1407 public let msisdnList: Array<String>?
1408 + public let answered: Bool?
1403 1409
1404 1410
1405 public init() { 1411 public init() {
...@@ -1441,6 +1447,7 @@ public class swiftApi { ...@@ -1441,6 +1447,7 @@ public class swiftApi {
1441 // profile_metadata 1447 // profile_metadata
1442 self.badge = "" 1448 self.badge = ""
1443 self.msisdnList = [] 1449 self.msisdnList = []
1450 + self.answered = false
1444 } 1451 }
1445 1452
1446 public init(dictionary: [String: Any]) { 1453 public init(dictionary: [String: Any]) {
...@@ -1491,16 +1498,19 @@ public class swiftApi { ...@@ -1491,16 +1498,19 @@ public class swiftApi {
1491 self.profile_metadata = profile_metadata_parsed as? [String: Any]? ?? [String: Any]() 1498 self.profile_metadata = profile_metadata_parsed as? [String: Any]? ?? [String: Any]()
1492 self.badge = profile_metadata_parsed["badge"] as? String? ?? "" 1499 self.badge = profile_metadata_parsed["badge"] as? String? ?? ""
1493 self.msisdnList = profile_metadata_parsed["msisdnList"] as? Array<String>? ?? [] 1500 self.msisdnList = profile_metadata_parsed["msisdnList"] as? Array<String>? ?? []
1501 + self.answered = profile_metadata_parsed["answered"] as? Bool? ?? false
1494 } else { 1502 } else {
1495 self.profile_metadata = [String: Any]() 1503 self.profile_metadata = [String: Any]()
1496 self.badge = "" 1504 self.badge = ""
1497 self.msisdnList = [] 1505 self.msisdnList = []
1506 + self.answered = false
1498 print("bad json") 1507 print("bad json")
1499 } 1508 }
1500 } catch let error as NSError { 1509 } catch let error as NSError {
1501 self.profile_metadata = [String: Any]() 1510 self.profile_metadata = [String: Any]()
1502 self.badge = "" 1511 self.badge = ""
1503 self.msisdnList = [] 1512 self.msisdnList = []
1513 + self.answered = false
1504 print(error) 1514 print(error)
1505 } 1515 }
1506 1516
...@@ -2735,11 +2745,16 @@ public class swiftApi { ...@@ -2735,11 +2745,16 @@ public class swiftApi {
2735 2745
2736 public func getCampaignList() -> Array<CampaignItemModel> { 2746 public func getCampaignList() -> Array<CampaignItemModel> {
2737 2747
2738 - let filteredCampaigns = GlobalVariables.campaigns.filter { 2748 + var filteredCampaigns = GlobalVariables.campaigns.filter {
2739 let tempCampaign = $0 2749 let tempCampaign = $0
2740 let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") 2750 let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true")
2751 + let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco")
2741 2752
2742 - return (!isCcmsOffer) 2753 + return (!(isCcmsOffer || isTelco))
2754 + }
2755 +
2756 + if (swiftApi().getConsumer()?.answered == true) {
2757 + filteredCampaigns = filteredCampaigns.filter { $0.offer_category != "questionnaire" }
2743 } 2758 }
2744 2759
2745 return filteredCampaigns 2760 return filteredCampaigns
......