From 4c5ae5d87997754aed3ad4e4f794392a7e9a19e0 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 6 Jun 2024 10:53:33 +0530 Subject: [PATCH] remove magic strings --- src/Api/PubnubApi/Constants.cs | 9 +++++++++ src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs | 3 +-- src/Api/PubnubApi/EndPoint/PubSub/UnsubscribeEndpoint.cs | 4 ++-- src/Api/PubnubApi/Entity/Channel.cs | 2 +- src/Api/PubnubApi/Entity/ChannelGroup.cs | 2 +- src/Api/PubnubApi/Entity/ChannelMetadata.cs | 2 +- src/Api/PubnubApi/Entity/SubscriptionSet.cs | 4 ++-- src/Api/PubnubApi/Entity/UserMetadata.cs | 2 +- .../EventEngine/Subscribe/SubscribeEventEngine.cs | 1 - src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 3 +++ src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 3 +++ src/Api/PubnubApiUnity/PubnubApiUnity.csproj | 3 +++ 12 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 src/Api/PubnubApi/Constants.cs diff --git a/src/Api/PubnubApi/Constants.cs b/src/Api/PubnubApi/Constants.cs new file mode 100644 index 000000000..70ab7c19e --- /dev/null +++ b/src/Api/PubnubApi/Constants.cs @@ -0,0 +1,9 @@ +using System; +namespace PubnubApi +{ + public static class Constants + { + public static readonly string Pnpres = "-pnpres"; + } +} + diff --git a/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs b/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs index c0f913be4..133ec8eae 100644 --- a/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs +++ b/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs @@ -5,7 +5,6 @@ using PubnubApi.EventEngine.Subscribe; using PubnubApi.EventEngine.Core; using PubnubApi.EventEngine.Subscribe.States; -using PubnubApi.EventEngine.Subscribe.Common; using PubnubApi.EventEngine.Common; namespace PubnubApi.EndPoint @@ -134,7 +133,7 @@ private void Subscribe(string[] channels, string[] channelGroups, SubscriptionCu } subscribeEventEngine.Subscribe(channels, channelGroups, cursor); if (this.presenceOperation != null) { - presenceOperation.Start(channels?.Where(c => !c.EndsWith("-pnpres")).ToArray(), channelGroups?.Where(cg => !cg.EndsWith("-pnpres")).ToArray()); + presenceOperation.Start(channels?.Where(c => !c.EndsWith(Constants.Pnpres)).ToArray(), channelGroups?.Where(cg => !cg.EndsWith(Constants.Pnpres)).ToArray()); } } diff --git a/src/Api/PubnubApi/EndPoint/PubSub/UnsubscribeEndpoint.cs b/src/Api/PubnubApi/EndPoint/PubSub/UnsubscribeEndpoint.cs index 71e6a5440..ef2efddb3 100644 --- a/src/Api/PubnubApi/EndPoint/PubSub/UnsubscribeEndpoint.cs +++ b/src/Api/PubnubApi/EndPoint/PubSub/UnsubscribeEndpoint.cs @@ -78,12 +78,12 @@ private void Unsubscribe(string[] channels, string[] channelGroups) subscribeEventEngine = subscribeEventEngineFactory.GetEventEngine(instanceId); channels = channels ?? new string[] { }; channelGroups = channelGroups ?? new string[] { }; - var channelsWithPresence = channels.Concat(channels.Select((c) => $"{c}-pnpres")).ToList(); + var channelsWithPresence = channels.Concat(channels.Select((c) => $"{c}{Constants.Pnpres}")).ToList(); var filteredChannelNames = new List(subscribeEventEngine.Channels); foreach (var c in channelsWithPresence) { filteredChannelNames.Remove(c); } - var channelGroupsWithPresence = channelGroups.Concat(channelGroups.Select((cg) => $"{cg}-pnpres")).ToList(); + var channelGroupsWithPresence = channelGroups.Concat(channelGroups.Select((cg) => $"{cg}{Constants.Pnpres}")).ToList(); var filteredChannelGroupNames = new List(subscribeEventEngine.ChannelGroups); foreach (var g in channelGroupsWithPresence) { filteredChannelGroupNames.Remove(g); diff --git a/src/Api/PubnubApi/Entity/Channel.cs b/src/Api/PubnubApi/Entity/Channel.cs index e986ccf44..eac4c787e 100644 --- a/src/Api/PubnubApi/Entity/Channel.cs +++ b/src/Api/PubnubApi/Entity/Channel.cs @@ -19,7 +19,7 @@ public Channel(string name, Pubnub pubnub, EventEmitter eventEmitter) public Subscription Subscription(SubscriptionOptions? options = SubscriptionOptions.None) { - return new Subscription(options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Name, $"{Name}-pnpres" } : new string[] { Name }, new string[] { }, options, this.Pubnub, this.EventEmitter); + return new Subscription(options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Name, $"{Name}{Constants.Pnpres}" } : new string[] { Name }, new string[] { }, options, this.Pubnub, this.EventEmitter); } } } \ No newline at end of file diff --git a/src/Api/PubnubApi/Entity/ChannelGroup.cs b/src/Api/PubnubApi/Entity/ChannelGroup.cs index 0395219a8..17a5060a7 100644 --- a/src/Api/PubnubApi/Entity/ChannelGroup.cs +++ b/src/Api/PubnubApi/Entity/ChannelGroup.cs @@ -18,7 +18,7 @@ public ChannelGroup(string name, Pubnub pubnub, EventEmitter eventEmitter) public Subscription Subscription(SubscriptionOptions? options = SubscriptionOptions.None) { - return new Subscription(new string[] { }, options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Name, $"{Name}-pnpres" } : new string[] { Name }, options, this.Pubnub, this.EventEmitter); + return new Subscription(new string[] { }, options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Name, $"{Name}{Constants.Pnpres}" } : new string[] { Name }, options, this.Pubnub, this.EventEmitter); } } } \ No newline at end of file diff --git a/src/Api/PubnubApi/Entity/ChannelMetadata.cs b/src/Api/PubnubApi/Entity/ChannelMetadata.cs index ca00bf599..1e09b9166 100644 --- a/src/Api/PubnubApi/Entity/ChannelMetadata.cs +++ b/src/Api/PubnubApi/Entity/ChannelMetadata.cs @@ -17,7 +17,7 @@ public ChannelMetadata(string id, Pubnub pubnub, EventEmitter eventEmitter) public Subscription Subscription(SubscriptionOptions options = SubscriptionOptions.None) { - return new Subscription(options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Id, $"{Id}-pnpres" } : new string[] { Id }, new string[] { }, options, this.Pubnub, this.EventEmitter); + return new Subscription(options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Id, $"{Id}{Constants.Pnpres}" } : new string[] { Id }, new string[] { }, options, this.Pubnub, this.EventEmitter); } } } diff --git a/src/Api/PubnubApi/Entity/SubscriptionSet.cs b/src/Api/PubnubApi/Entity/SubscriptionSet.cs index 74f72d446..e4cfd57fa 100644 --- a/src/Api/PubnubApi/Entity/SubscriptionSet.cs +++ b/src/Api/PubnubApi/Entity/SubscriptionSet.cs @@ -23,14 +23,14 @@ public SubscriptionSet(string[] channels, string[] channelGroups, SubscriptionOp this.Options = options; foreach (var c in channels - .Where(c => !c.EndsWith("-pnpres"))) { + .Where(c => !c.EndsWith(Constants.Pnpres))) { var subscription = this.Pubnub.Channel(c).Subscription(this.Options); this.ChannelNames.AddRange(subscription.ChannelNames); this.SubscriptionList.Add(subscription); } foreach (var cg in channelGroups - .Where(cg => !cg.EndsWith("-pnpres"))) { + .Where(cg => !cg.EndsWith(Constants.Pnpres))) { var subscription = this.Pubnub.ChannelGroup(cg).Subscription(this.Options); this.ChannelGroupNames.AddRange(subscription.ChannelGroupNames); this.SubscriptionList.Add(subscription); diff --git a/src/Api/PubnubApi/Entity/UserMetadata.cs b/src/Api/PubnubApi/Entity/UserMetadata.cs index 18888ad8d..f75baf756 100644 --- a/src/Api/PubnubApi/Entity/UserMetadata.cs +++ b/src/Api/PubnubApi/Entity/UserMetadata.cs @@ -17,7 +17,7 @@ public UserMetadata(string id, Pubnub pubnub, EventEmitter eventEmitter) public Subscription Subscription(SubscriptionOptions options = SubscriptionOptions.None) { - return new Subscription(options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Id, $"{Id}-pnpres" } : new string[] { Id }, new string[] { }, options, this.Pubnub, this.EventEmitter); + return new Subscription(options == SubscriptionOptions.ReceivePresenceEvents ? new string[] { Id, $"{Id}{Constants.Pnpres}" } : new string[] { Id }, new string[] { }, options, this.Pubnub, this.EventEmitter); } } } diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs b/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs index 6f086a0b4..b23405b6b 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs @@ -3,7 +3,6 @@ using PubnubApi.EventEngine.Subscribe.States; using System.Collections.Generic; using System.Linq; -using PubnubApi.EventEngine.Subscribe.Common; using System; using PubnubApi.EventEngine.Subscribe.Events; using PubnubApi.EventEngine.Common; diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 4571c1a94..f2e2a1df9 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -605,6 +605,9 @@ Push\Mpns\MpnsToastNotification.cs + + Constants.cs + diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 9a16b1e53..0609ee9c5 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -724,6 +724,9 @@ Push\Mpns\MpnsToastNotification.cs + + Constants.cs + Security\Crypto\CryptoModule.cs diff --git a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj index 8e6300d45..3e6cb80d2 100644 --- a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj +++ b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj @@ -605,6 +605,9 @@ Push\Mpns\MpnsToastNotification.cs + + Constants.cs +