From 1d38db3ef6b7ed94d0076eb7239a51082dd39472 Mon Sep 17 00:00:00 2001 From: khmMouna Date: Tue, 9 Jul 2024 18:15:42 +0200 Subject: [PATCH 1/6] Push for test --- src/Airship.Net/IAirship.cs | 13 ++++++ src/Airship.Net/Platforms/Android/Airship.cs | 44 +++++++++++++++++++- src/Airship.Net/Platforms/iOS/Airship.cs | 29 +++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/src/Airship.Net/IAirship.cs b/src/Airship.Net/IAirship.cs index ec58508..b198c71 100644 --- a/src/Airship.Net/IAirship.cs +++ b/src/Airship.Net/IAirship.cs @@ -1,5 +1,6 @@ /* Copyright Airship and Contributors */ +using System.Collections.Generic; using AirshipDotNet.Attributes; using AirshipDotNet.Channel; using AirshipDotNet.Contact; @@ -173,6 +174,18 @@ public interface IAirship /// The tags. IEnumerable Tags { get; } + /// + /// Gets the channel subscription list. + /// + /// The channel subscription list. + void FetchChannelSubscriptionList(Action list); + + /// + /// Gets the contact subscription list. + /// + /// The contact subscription list. + void FetchContactSubscriptionList(Action> list); + /// /// Get the channel ID for the device. /// diff --git a/src/Airship.Net/Platforms/Android/Airship.cs b/src/Airship.Net/Platforms/Android/Airship.cs index 161b344..2b48754 100644 --- a/src/Airship.Net/Platforms/Android/Airship.cs +++ b/src/Airship.Net/Platforms/Android/Airship.cs @@ -12,6 +12,12 @@ using AttributeEditor = AirshipDotNet.Attributes.AttributeEditor; using ChannelSubscriptionListEditor = AirshipDotNet.Channel.SubscriptionListEditor; using ContactSubscriptionListEditor = AirshipDotNet.Contact.SubscriptionListEditor; +using System.Collections.Generic; +using Microsoft.Maui.ApplicationModel; +using Java.Time; +using static Android.Provider.CalendarContract; +using System.Collections; +using System.Collections.ObjectModel; namespace AirshipDotNet { @@ -192,9 +198,45 @@ private static Features FeaturesFromUAFeatures(int uAFeatures) return features; } - public IEnumerable Tags => UAirship.Shared().Channel.Tags; + public void FetchChannelSubscriptionList(Action list) + { + PendingResult subscriptionsPendingResult = UAirship.Shared().Channel.FetchSubscriptionListsPendingResult(); + var result = subscriptionsPendingResult.Result; + if (result is not null && result is HashSet) + { + // FIXME: Find a way to convert a HashSet to a string[] + HashSet hashSet = (HashSet)result; + string[]? subscriptionlist = (string[]?)hashSet; + list(subscriptionlist ?? new string[0]); + return; + } + list(new string[0]); + } + + public void FetchContactSubscriptionList(Action> list) + { + PendingResult subscriptionsPendingResult = UAirship.Shared().Contact.FetchSubscriptionListsPendingResult(); + var result = subscriptionsPendingResult.Result; + Dictionary dictionary = new Dictionary(); + if (result is not null) + { + HashMap map = (HashMap)result; + foreach (string key in map.KeySet()) + { + Console.WriteLine(key); + // FIXME: Find a way to get the value + //var value = result[key]; + //if (value is not null) + //{ + //dictionary.Add(key, (object)value); + //} + } + } + list(dictionary); + } + public string? ChannelId => UAirship.Shared().Channel.Id; public void GetNamedUser(Action namedUser) => namedUser(UAirship.Shared().Contact.NamedUserId); diff --git a/src/Airship.Net/Platforms/iOS/Airship.cs b/src/Airship.Net/Platforms/iOS/Airship.cs index d4e3281..5364fa7 100644 --- a/src/Airship.Net/Platforms/iOS/Airship.cs +++ b/src/Airship.Net/Platforms/iOS/Airship.cs @@ -202,6 +202,35 @@ private static Features FeaturesFromUAFeatures(UAFeatures uAFeatures) public IEnumerable Tags => UAirship.Channel.Tags; + public void FetchChannelSubscriptionList(Action list) + { + UAirship.Channel.FetchSubscriptionLists((lists) => + { + list(lists); + }); + } + + public void FetchContactSubscriptionList(Action> list) + { + UAirship.Contact.FetchSubscriptionLists((lists) => + { + var dictionary = new Dictionary(); + if (lists is not null) + { + foreach (KeyValuePair kvp in lists) + { + string key = kvp.Key.ToString(); + object value = (object)kvp.Value; + if (key is not null && value is not null) + { + dictionary.Add(key, value); + } + } + } + list(dictionary); + }); + } + public string? ChannelId => UAirship.Channel.Identifier; public void GetNamedUser(Action namedUser) From 36d332b49f45d27ce411d415a170a622043a82e2 Mon Sep 17 00:00:00 2001 From: khmMouna Date: Thu, 11 Jul 2024 16:04:33 +0200 Subject: [PATCH 2/6] Fixme --- src/Airship.Net/IAirship.cs | 2 +- src/Airship.Net/Platforms/Android/Airship.cs | 25 ++++++-------------- src/Airship.Net/Platforms/iOS/Airship.cs | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/Airship.Net/IAirship.cs b/src/Airship.Net/IAirship.cs index b198c71..456bc36 100644 --- a/src/Airship.Net/IAirship.cs +++ b/src/Airship.Net/IAirship.cs @@ -178,7 +178,7 @@ public interface IAirship /// Gets the channel subscription list. /// /// The channel subscription list. - void FetchChannelSubscriptionList(Action list); + void FetchChannelSubscriptionList(Action list); /// /// Gets the contact subscription list. diff --git a/src/Airship.Net/Platforms/Android/Airship.cs b/src/Airship.Net/Platforms/Android/Airship.cs index 2b48754..644ef6c 100644 --- a/src/Airship.Net/Platforms/Android/Airship.cs +++ b/src/Airship.Net/Platforms/Android/Airship.cs @@ -200,19 +200,10 @@ private static Features FeaturesFromUAFeatures(int uAFeatures) public IEnumerable Tags => UAirship.Shared().Channel.Tags; - public void FetchChannelSubscriptionList(Action list) + public void FetchChannelSubscriptionList(Action list) { PendingResult subscriptionsPendingResult = UAirship.Shared().Channel.FetchSubscriptionListsPendingResult(); - var result = subscriptionsPendingResult.Result; - if (result is not null && result is HashSet) - { - // FIXME: Find a way to convert a HashSet to a string[] - HashSet hashSet = (HashSet)result; - string[]? subscriptionlist = (string[]?)hashSet; - list(subscriptionlist ?? new string[0]); - return; - } - list(new string[0]); + list(subscriptionsPendingResult.Result); } public void FetchContactSubscriptionList(Action> list) @@ -225,13 +216,11 @@ public void FetchContactSubscriptionList(Action> list HashMap map = (HashMap)result; foreach (string key in map.KeySet()) { - Console.WriteLine(key); - // FIXME: Find a way to get the value - //var value = result[key]; - //if (value is not null) - //{ - //dictionary.Add(key, (object)value); - //} + var value = map.Get(key); + if (value is not null) + { + dictionary.Add(key, value); + } } } list(dictionary); diff --git a/src/Airship.Net/Platforms/iOS/Airship.cs b/src/Airship.Net/Platforms/iOS/Airship.cs index 5364fa7..5c8316c 100644 --- a/src/Airship.Net/Platforms/iOS/Airship.cs +++ b/src/Airship.Net/Platforms/iOS/Airship.cs @@ -202,7 +202,7 @@ private static Features FeaturesFromUAFeatures(UAFeatures uAFeatures) public IEnumerable Tags => UAirship.Channel.Tags; - public void FetchChannelSubscriptionList(Action list) + public void FetchChannelSubscriptionList(Action list) { UAirship.Channel.FetchSubscriptionLists((lists) => { From 8c3c9e7027818e71c33f879f04eb63925d27d5c9 Mon Sep 17 00:00:00 2001 From: khmMouna Date: Thu, 11 Jul 2024 16:31:32 +0200 Subject: [PATCH 3/6] Update --- src/Airship.Net/Platforms/Android/Airship.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Airship.Net/Platforms/Android/Airship.cs b/src/Airship.Net/Platforms/Android/Airship.cs index 644ef6c..05c0945 100644 --- a/src/Airship.Net/Platforms/Android/Airship.cs +++ b/src/Airship.Net/Platforms/Android/Airship.cs @@ -203,7 +203,8 @@ private static Features FeaturesFromUAFeatures(int uAFeatures) public void FetchChannelSubscriptionList(Action list) { PendingResult subscriptionsPendingResult = UAirship.Shared().Channel.FetchSubscriptionListsPendingResult(); - list(subscriptionsPendingResult.Result); + var result = subscriptionsPendingResult.Result; + list(result); } public void FetchContactSubscriptionList(Action> list) From af4fc56ca2c2100a7955d0d3bfd67b0d07c53614 Mon Sep 17 00:00:00 2001 From: khmMouna Date: Mon, 15 Jul 2024 15:33:09 +0200 Subject: [PATCH 4/6] Feedback --- src/Airship.Net/IAirship.cs | 12 +-- src/Airship.Net/Platforms/Android/Airship.cs | 82 ++++++++++++++++---- src/Airship.Net/Platforms/iOS/Airship.cs | 40 ++++++++-- 3 files changed, 106 insertions(+), 28 deletions(-) diff --git a/src/Airship.Net/IAirship.cs b/src/Airship.Net/IAirship.cs index 456bc36..26eec3c 100644 --- a/src/Airship.Net/IAirship.cs +++ b/src/Airship.Net/IAirship.cs @@ -175,16 +175,16 @@ public interface IAirship IEnumerable Tags { get; } /// - /// Gets the channel subscription list. + /// Gets the channel subscription lists. /// - /// The channel subscription list. - void FetchChannelSubscriptionList(Action list); + /// The channel subscription lists. + void FetchChannelSubscriptionLists(Action> subscriptions); /// - /// Gets the contact subscription list. + /// Gets the contact subscription lists. /// - /// The contact subscription list. - void FetchContactSubscriptionList(Action> list); + /// The contact subscription lists. + void FetchContactSubscriptionLists(Action>> subscriptions); /// /// Get the channel ID for the device. diff --git a/src/Airship.Net/Platforms/Android/Airship.cs b/src/Airship.Net/Platforms/Android/Airship.cs index 05c0945..e89cc75 100644 --- a/src/Airship.Net/Platforms/Android/Airship.cs +++ b/src/Airship.Net/Platforms/Android/Airship.cs @@ -18,6 +18,7 @@ using static Android.Provider.CalendarContract; using System.Collections; using System.Collections.ObjectModel; +using Android.Util; namespace AirshipDotNet { @@ -200,31 +201,84 @@ private static Features FeaturesFromUAFeatures(int uAFeatures) public IEnumerable Tags => UAirship.Shared().Channel.Tags; - public void FetchChannelSubscriptionList(Action list) + private class ResultCallback : Java.Lang.Object, IResultCallback + { + Action action; + + internal ResultCallback(Action action) + { + this.action = action; + } + + public void OnResult(Java.Lang.Object? result) + { + action.Invoke(result); + } + } + + private List CastHashSetToList(HashSet set) + { + var list = new List(); + + var value = set.Iterator(); + if (value is not null) + { + while (value.HasNext) + { + var nextValue = (string?)value.Next(); + if (nextValue is not null) + { + list.Add(nextValue); + } + } + } + return list; + } + + public void FetchChannelSubscriptionLists(Action> subscriptions) { PendingResult subscriptionsPendingResult = UAirship.Shared().Channel.FetchSubscriptionListsPendingResult(); - var result = subscriptionsPendingResult.Result; - list(result); + + subscriptionsPendingResult.AddResultCallback(new ResultCallback((result) => + { + Console.WriteLine("-- ON RESULT!!! " + result + ", (" + result.GetType() + ")"); + var list = new List(); + if (result is HashSet) + { + list = CastHashSetToList((HashSet)result); + } + + subscriptions(list); + })); } - public void FetchContactSubscriptionList(Action> list) + public void FetchContactSubscriptionLists(Action>> subscriptions) { PendingResult subscriptionsPendingResult = UAirship.Shared().Contact.FetchSubscriptionListsPendingResult(); - var result = subscriptionsPendingResult.Result; - Dictionary dictionary = new Dictionary(); - if (result is not null) + + subscriptionsPendingResult.AddResultCallback(new ResultCallback((result) => { - HashMap map = (HashMap)result; - foreach (string key in map.KeySet()) + Dictionary> dictionary = new Dictionary>(); + if (result is not null) { - var value = map.Get(key); - if (value is not null) + var typedResult = (HashMap)result; + foreach (string? key in typedResult.KeySet()) { - dictionary.Add(key, value); + if (key is not null) + { + var typedValue = typedResult.Get(key); + + if (typedValue is not null && typedValue is HashSet) + { + var list = CastHashSetToList((HashSet)typedValue); + dictionary.Add(key, list); + } + + } } } - } - list(dictionary); + subscriptions(dictionary); + })); } public string? ChannelId => UAirship.Shared().Channel.Id; diff --git a/src/Airship.Net/Platforms/iOS/Airship.cs b/src/Airship.Net/Platforms/iOS/Airship.cs index 5c8316c..f48675b 100644 --- a/src/Airship.Net/Platforms/iOS/Airship.cs +++ b/src/Airship.Net/Platforms/iOS/Airship.cs @@ -202,35 +202,59 @@ private static Features FeaturesFromUAFeatures(UAFeatures uAFeatures) public IEnumerable Tags => UAirship.Channel.Tags; - public void FetchChannelSubscriptionList(Action list) + public void FetchChannelSubscriptionLists(Action> subscriptions) { UAirship.Channel.FetchSubscriptionLists((lists) => { - list(lists); + var list = new List(); + if (lists is not null) + { + foreach (string subscription in list) + { + list.Add(subscription.ToString()); + } + } + subscriptions(list); }); } - public void FetchContactSubscriptionList(Action> list) + public void FetchContactSubscriptionLists(Action>> subscriptions) { UAirship.Contact.FetchSubscriptionLists((lists) => { - var dictionary = new Dictionary(); + var dictionary = new Dictionary>(); if (lists is not null) { foreach (KeyValuePair kvp in lists) { string key = kvp.Key.ToString(); - object value = (object)kvp.Value; - if (key is not null && value is not null) + var scopes = ((UAChannelScopes)kvp.Value).Values; + + if (key is not null && scopes is not null) { - dictionary.Add(key, value); + var list = new List(); + foreach (var scope in scopes) + { + list.Add(ScopeOrdinalToString(scope)); + } + dictionary.Add(key, list); } } } - list(dictionary); + subscriptions(dictionary); }); } + private string ScopeOrdinalToString(NSNumber ordinal) + => ordinal.LongValue switch + { + 0 => "app", + 1 => "web", + 2 => "email", + 3 => "sms", + _ => "unknown", + }; + public string? ChannelId => UAirship.Channel.Identifier; public void GetNamedUser(Action namedUser) From 48f76dc8f1b097680dfa99ee9c346efe9f79fa82 Mon Sep 17 00:00:00 2001 From: khmMouna Date: Mon, 15 Jul 2024 15:38:00 +0200 Subject: [PATCH 5/6] Clean code --- src/Airship.Net/Platforms/Android/Airship.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Airship.Net/Platforms/Android/Airship.cs b/src/Airship.Net/Platforms/Android/Airship.cs index e89cc75..b452c01 100644 --- a/src/Airship.Net/Platforms/Android/Airship.cs +++ b/src/Airship.Net/Platforms/Android/Airship.cs @@ -12,13 +12,6 @@ using AttributeEditor = AirshipDotNet.Attributes.AttributeEditor; using ChannelSubscriptionListEditor = AirshipDotNet.Channel.SubscriptionListEditor; using ContactSubscriptionListEditor = AirshipDotNet.Contact.SubscriptionListEditor; -using System.Collections.Generic; -using Microsoft.Maui.ApplicationModel; -using Java.Time; -using static Android.Provider.CalendarContract; -using System.Collections; -using System.Collections.ObjectModel; -using Android.Util; namespace AirshipDotNet { @@ -241,7 +234,6 @@ public void FetchChannelSubscriptionLists(Action> subscriptions) subscriptionsPendingResult.AddResultCallback(new ResultCallback((result) => { - Console.WriteLine("-- ON RESULT!!! " + result + ", (" + result.GetType() + ")"); var list = new List(); if (result is HashSet) { From f8d2c0c07006aa12c8b2d8b6096c1d683557e108 Mon Sep 17 00:00:00 2001 From: khmMouna Date: Mon, 15 Jul 2024 15:42:38 +0200 Subject: [PATCH 6/6] fix an issue with fetch channels subscription list on ios --- src/Airship.Net/Platforms/iOS/Airship.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Airship.Net/Platforms/iOS/Airship.cs b/src/Airship.Net/Platforms/iOS/Airship.cs index f48675b..19a3d7f 100644 --- a/src/Airship.Net/Platforms/iOS/Airship.cs +++ b/src/Airship.Net/Platforms/iOS/Airship.cs @@ -209,7 +209,7 @@ public void FetchChannelSubscriptionLists(Action> subscriptions) var list = new List(); if (lists is not null) { - foreach (string subscription in list) + foreach (string subscription in lists) { list.Add(subscription.ToString()); }