Skip to content

Commit

Permalink
fix: status callback on subscriptionChange (#235)
Browse files Browse the repository at this point in the history
* Add a test for second PnStatuscallback

* eTag support for Channel and User metadata

* fix: PNSubscriptionChanged status support

* update pubnub yml for .net version

* PubNub SDK v7.2.0.0 release.

---------

Co-authored-by: PUBNUB\jakub.grzesiowski <[email protected]>
Co-authored-by: Mohit Tejani <[email protected]>
Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
4 people authored Jan 30, 2025
1 parent 0450d3a commit c953ac5
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 36 deletions.
25 changes: 16 additions & 9 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: c-sharp
version: "7.1.3"
version: "7.2.0"
schema: 1
scm: github.com/pubnub/c-sharp
changelog:
- date: 2025-01-29
version: v7.2.0
changes:
- type: feature
text: "Added new optional parameter `IfMatchesEtag` for `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the eTag on the server and if they don't match a HTTP 412 error is returned."
- type: bug
text: "Fixes issue of not getting `PNSubscriptionChangedCategory` status when subscription change happens."
- date: 2025-01-23
version: v7.1.3
changes:
Expand Down Expand Up @@ -828,7 +835,7 @@ features:
- QUERY-PARAM
supported-platforms:
-
version: Pubnub 'C#' 7.1.3
version: Pubnub 'C#' 7.2.0
platforms:
- Windows 10 and up
- Windows Server 2008 and up
Expand All @@ -839,7 +846,7 @@ supported-platforms:
- .Net Framework 4.6.1+
- .Net Framework 6.0
-
version: PubnubPCL 'C#' 7.1.3
version: PubnubPCL 'C#' 7.2.0
platforms:
- Xamarin.Android
- Xamarin.iOS
Expand All @@ -859,7 +866,7 @@ supported-platforms:
- .Net Core
- .Net 6.0
-
version: PubnubUWP 'C#' 7.1.3
version: PubnubUWP 'C#' 7.2.0
platforms:
- Windows Phone 10
- Universal Windows Apps
Expand All @@ -883,11 +890,11 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: Pubnub
location: https://github.com/pubnub/c-sharp/releases/tag/v7.1.3.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
requires:
-
name: ".Net"
min-version: "3.5 or higher"
min-version: "6 or higher"
license: "MS-EULA"
license-url: "https://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm"
location: "Should be installed on computer"
Expand Down Expand Up @@ -1026,7 +1033,7 @@ sdks:
requires:
-
name: ".Net"
min-version: "3.5 or higher"
min-version: "6 or higher"
license: "MS-EULA"
license-url: "https://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm"
location: "Should be installed on computer"
Expand Down Expand Up @@ -1166,7 +1173,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubNubPCL
location: https://github.com/pubnub/c-sharp/releases/tag/v7.1.3.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
requires:
-
name: ".Net Core"
Expand Down Expand Up @@ -1525,7 +1532,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubnubUWP
location: https://github.com/pubnub/c-sharp/releases/tag/v7.1.3.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.2.0.0
requires:
-
name: "Universal Windows Platform Development"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v7.2.0 - January 29 2025
-----------------------------
- Added: added new optional parameter `IfMatchesEtag` for `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the eTag on the server and if they don't match a HTTP 412 error is returned.

- Fixed: fixes issue of not getting `PNSubscriptionChangedCategory` status when subscription change happens.

v7.1.3 - January 23 2025
-----------------------------
- Modified: informative log statements throughout SDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SetChannelMetadataOperation : PubnubCoreBase
private Dictionary<string, object> custom;
private bool includeCustom;

private string ifMatchesEtag = null;
private PNCallback<PNSetChannelMetadataResult> savedCallback;
private Dictionary<string, object> queryParam;

Expand Down Expand Up @@ -66,6 +67,11 @@ public SetChannelMetadataOperation QueryParam(Dictionary<string, object> customQ
return this;
}

public SetChannelMetadataOperation IfMatchesEtag(string etag)
{
this.ifMatchesEtag = etag;
return this;
}
public void Execute(PNCallback<PNSetChannelMetadataResult> callback)
{
if (string.IsNullOrEmpty(channelId) || string.IsNullOrEmpty(channelId.Trim())) {
Expand Down Expand Up @@ -226,7 +232,10 @@ private RequestParameter CreateRequestParameter()
Query = requestQueryStringParams,
BodyContentString = patchMessage
};

if (!string.IsNullOrEmpty(ifMatchesEtag))
{
requestParameter.Headers.Add("If-Match", ifMatchesEtag);
}
return requestParameter;
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/Api/PubnubApi/EndPoint/Objects/SetUuidMetadataOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SetUuidMetadataOperation : PubnubCoreBase
private string uuidProfileUrl;
private Dictionary<string, object> uuidCustom;
private bool includeCustom;

private string ifMatchesEtag = null;

private PNCallback<PNSetUuidMetadataResult> savedCallback;
private Dictionary<string, object> queryParam;
Expand Down Expand Up @@ -96,6 +96,11 @@ public SetUuidMetadataOperation QueryParam(Dictionary<string, object> customQuer
this.queryParam = customQueryParam;
return this;
}
public SetUuidMetadataOperation IfMatchesEtag(string etag)
{
this.ifMatchesEtag = etag;
return this;
}

public void Execute(PNCallback<PNSetUuidMetadataResult> callback)
{
Expand Down Expand Up @@ -248,6 +253,10 @@ private RequestParameter CreateRequestParameter()
Query = requestQueryStringParams,
BodyContentString = patchMessage
};
if (!string.IsNullOrEmpty(ifMatchesEtag))
{
requestParameter.Headers.Add("If-Match", ifMatchesEtag);
}
return requestParameter;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Api/PubnubApi/Enum/PNStatusCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum PNStatusCategory
PNTimeoutCategory,
PNNetworkIssuesCategory,
PNConnectedCategory,
PNSubscriptionChangedCategory,
PNReconnectedCategory,
PNDisconnectedCategory,
PNUnexpectedDisconnectCategory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public override TransitionResult Transition(IEvent e)
{
Channels = subscriptionChanged.Channels?? Enumerable.Empty<string>(),
ChannelGroups = subscriptionChanged.ChannelGroups??Enumerable.Empty<string>(),
},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.ReconnectEvent reconnect => new HandshakingState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public override TransitionResult Transition(IEvent e)
Events.SubscriptionChangedEvent subscriptionChanged => new HandshakingState() {
Channels = subscriptionChanged.Channels?? Enumerable.Empty<string>(),
ChannelGroups = subscriptionChanged.ChannelGroups??Enumerable.Empty<string>(),
},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.DisconnectEvent disconnect => new HandshakeStoppedState() {
Channels = disconnect.Channels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public override TransitionResult Transition(IEvent e)
{
Channels = subscriptionChanged.Channels?? Enumerable.Empty<string>(),
ChannelGroups = subscriptionChanged.ChannelGroups??Enumerable.Empty<string>(),
},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.ReconnectEvent reconnect => new HandshakingState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public override TransitionResult Transition(IEvent e)
{
Channels = subscriptionChanged.Channels?? Enumerable.Empty<string>(),
ChannelGroups = subscriptionChanged.ChannelGroups??Enumerable.Empty<string>(),
},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.SubscriptionRestoredEvent subscriptionRestored => new States.HandshakingState()
{
Expand Down Expand Up @@ -53,7 +54,7 @@ public override TransitionResult Transition(IEvent e)
Channels = this.Channels,
ChannelGroups = this.ChannelGroups,
Cursor = success.Cursor,
}.With(new EmitStatusInvocation(success.Status)),
}.With(new EmitStatusInvocation(new PNStatus(null, PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

_ => null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public override TransitionResult Transition(IEvent e)
ChannelGroups = (ChannelGroups ?? Enumerable.Empty<string>()).Union(subscriptionChanged.ChannelGroups),
Cursor = this.Cursor,

},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.ReconnectEvent reconnect => new HandshakingState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public override TransitionResult Transition(IEvent e)
Channels = subscriptionChanged.Channels?? Enumerable.Empty<string>(),
ChannelGroups = subscriptionChanged.ChannelGroups??Enumerable.Empty<string>(),
Cursor = this.Cursor,
},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.DisconnectEvent disconnect => new ReceiveStoppedState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public override TransitionResult Transition(IEvent e)
Channels = subscriptionChanged.Channels?? Enumerable.Empty<string>(),
ChannelGroups = subscriptionChanged.ChannelGroups??Enumerable.Empty<string>(),
Cursor = this.Cursor,
},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.ReconnectEvent reconnect => new HandshakingState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public override TransitionResult Transition(IEvent e)
Channels = subscriptionChanged.Channels?? Enumerable.Empty<string>(),
ChannelGroups = subscriptionChanged.ChannelGroups??Enumerable.Empty<string>(),
Cursor = Cursor,
},
}.With(
new EmitStatusInvocation(new PNStatus(null,PNOperationType.PNSubscribeOperation, PNStatusCategory.PNSubscriptionChangedCategory, this.Channels, this.ChannelGroups, Constants.HttpRequestSuccessStatusCode))),

Events.SubscriptionRestoredEvent subscriptionRestored => new ReceivingState()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Api/PubnubApi/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[assembly: AssemblyProduct("Pubnub C# SDK")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("7.1.3.0")]
[assembly: AssemblyFileVersion("7.1.3.0")]
[assembly: AssemblyVersion("7.2.0.0")]
[assembly: AssemblyFileVersion("7.2.0.0")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
Expand Down
5 changes: 3 additions & 2 deletions src/Api/PubnubApi/PubnubApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

<PropertyGroup>
<PackageId>Pubnub</PackageId>
<PackageVersion>7.1.3.0</PackageVersion>
<PackageVersion>7.2.0.0</PackageVersion>
<Title>PubNub C# .NET - Web Data Push API</Title>
<Authors>Pandu Masabathula</Authors>
<Owners>PubNub</Owners>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
<PackageReleaseNotes>Informative log statements throughout SDK.</PackageReleaseNotes>
<PackageReleaseNotes>Added new optional parameter `IfMatchesEtag` for `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the eTag on the server and if they don't match a HTTP 412 error is returned.
Fixes issue of not getting `PNSubscriptionChangedCategory` status when subscription change happens.</PackageReleaseNotes>
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Api/PubnubApi/Transport/HttpClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public async Task<TransportResponse> PatchRequest(TransportRequest transportRequ
{
foreach (var kvp in transportRequest.Headers)
{
requestMessage.Headers.Add(kvp.Key, kvp.Value);
requestMessage.Headers.Add(kvp.Key, $"\"{kvp.Value}\"");
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Api/PubnubApi/Transport/Middleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public TransportRequest PreapareTransportRequest(RequestParameter requestParamet
RequestUrl = urlString,
BodyContentString = requestParameter.BodyContentString,
FormData = requestParameter.FormData,
CancellationToken = cts.Token
CancellationToken = cts.Token,
};
if(requestParameter.Headers.Count>0) transportRequest.Headers = requestParameter.Headers;
return transportRequest;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Api/PubnubApi/Transport/RequestParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public class RequestParameter
public Dictionary<string, string> Query { get; set; } = new Dictionary<string, string>();
public string BodyContentString { get; set; }
public byte[] FormData { get; set; }

public Dictionary<string, string> Headers { get; set; } = new Dictionary<string, string>();
}
}
5 changes: 3 additions & 2 deletions src/Api/PubnubApiPCL/PubnubApiPCL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

<PropertyGroup>
<PackageId>PubnubPCL</PackageId>
<PackageVersion>7.1.3.0</PackageVersion>
<PackageVersion>7.2.0.0</PackageVersion>
<Title>PubNub C# .NET - Web Data Push API</Title>
<Authors>Pandu Masabathula</Authors>
<Owners>PubNub</Owners>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
<PackageReleaseNotes>Informative log statements throughout SDK.</PackageReleaseNotes>
<PackageReleaseNotes>Added new optional parameter `IfMatchesEtag` for `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the eTag on the server and if they don't match a HTTP 412 error is returned.
Fixes issue of not getting `PNSubscriptionChangedCategory` status when subscription change happens.</PackageReleaseNotes>
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>
Expand Down
5 changes: 3 additions & 2 deletions src/Api/PubnubApiUWP/PubnubApiUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

<PropertyGroup>
<PackageId>PubnubUWP</PackageId>
<PackageVersion>7.1.3.0</PackageVersion>
<PackageVersion>7.2.0.0</PackageVersion>
<Title>PubNub C# .NET - Web Data Push API</Title>
<Authors>Pandu Masabathula</Authors>
<Owners>PubNub</Owners>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
<PackageReleaseNotes>Informative log statements throughout SDK.</PackageReleaseNotes>
<PackageReleaseNotes>Added new optional parameter `IfMatchesEtag` for `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the eTag on the server and if they don't match a HTTP 412 error is returned.
Fixes issue of not getting `PNSubscriptionChangedCategory` status when subscription change happens.</PackageReleaseNotes>
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Api/PubnubApiUnity/PubnubApiUnity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<PropertyGroup>
<PackageId>PubnubApiUnity</PackageId>
<PackageVersion>7.1.3.0</PackageVersion>
<PackageVersion>7.2.0.0</PackageVersion>
<Title>PubNub C# .NET - Web Data Push API</Title>
<Authors>Pandu Masabathula</Authors>
<Owners>PubNub</Owners>
Expand Down
Loading

0 comments on commit c953ac5

Please sign in to comment.