Skip to content

Commit

Permalink
remove magic strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitpubnub committed Jun 6, 2024
1 parent 3596777 commit 4c5ae5d
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/Api/PubnubApi/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
namespace PubnubApi
{
public static class Constants
{
public static readonly string Pnpres = "-pnpres";
}
}

3 changes: 1 addition & 2 deletions src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,7 +133,7 @@ private void Subscribe(string[] channels, string[] channelGroups, SubscriptionCu
}
subscribeEventEngine.Subscribe<T>(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());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Api/PubnubApi/EndPoint/PubSub/UnsubscribeEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(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<string>(subscribeEventEngine.ChannelGroups);
foreach (var g in channelGroupsWithPresence) {
filteredChannelGroupNames.Remove(g);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/PubnubApi/Entity/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/Api/PubnubApi/Entity/ChannelGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/Api/PubnubApi/Entity/ChannelMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions src/Api/PubnubApi/Entity/SubscriptionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/PubnubApi/Entity/UserMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Api/PubnubApiPCL/PubnubApiPCL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@
<Compile Include="..\PubnubApi\Push\Mpns\MpnsToastNotification.cs">
<Link>Push\Mpns\MpnsToastNotification.cs</Link>
</Compile>
<Compile Include="..\PubnubApi\Constants.cs">
<Link>Constants.cs</Link>
</Compile>
<Compile Include="..\PubnubApi\Security\Crypto\Common\ByteArrayExtensions.cs" Link="Security\Crypto\Common\ByteArrayExtensions.cs" />
<Compile Include="..\PubnubApi\Security\Crypto\Common\Util.cs" Link="Security\Crypto\Common\Util.cs" />
<Compile Include="..\PubnubApi\Security\Crypto\CryptoModule.cs" Link="Security\Crypto\CryptoModule.cs" />
Expand Down
3 changes: 3 additions & 0 deletions src/Api/PubnubApiUWP/PubnubApiUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,9 @@
<Compile Include="..\PubnubApi\Push\Mpns\MpnsToastNotification.cs">
<Link>Push\Mpns\MpnsToastNotification.cs</Link>
</Compile>
<Compile Include="..\PubnubApi\Constants.cs">
<Link>Constants.cs</Link>
</Compile>
<Compile Include="..\PubnubApi\Security\Crypto\CryptoModule.cs">
<Link>Security\Crypto\CryptoModule.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions src/Api/PubnubApiUnity/PubnubApiUnity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@
<Compile Include="..\PubnubApi\Push\Mpns\MpnsToastNotification.cs">
<Link>Push\Mpns\MpnsToastNotification.cs</Link>
</Compile>
<Compile Include="..\PubnubApi\Constants.cs">
<Link>Constants.cs</Link>
</Compile>
<Compile Include="..\PubnubApi\Security\Crypto\Common\ByteArrayExtensions.cs" Link="Security\Crypto\Common\ByteArrayExtensions.cs" />
<Compile Include="..\PubnubApi\Security\Crypto\Common\Util.cs" Link="Security\Crypto\Common\Util.cs" />
<Compile Include="..\PubnubApi\Security\Crypto\CryptoModule.cs" Link="Security\Crypto\CryptoModule.cs" />
Expand Down

0 comments on commit 4c5ae5d

Please sign in to comment.