Skip to content

Commit

Permalink
feat: support for status and type for membership,
Browse files Browse the repository at this point in the history
fix: files api subscribe event data parsing issue
  • Loading branch information
mohitpubnub committed Nov 20, 2024
1 parent b9c483e commit 8ba31a4
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/Api/PubnubApi/Builder/UrlParameterConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public static string MapEnumValueToEndpoint(string enumValue)
{
endpointParameterName = "uuid.custom";
}
else if (enumValue.ToLowerInvariant() == "status")
{
endpointParameterName = "status";
}
else if (enumValue.ToLowerInvariant() == "type")
{
endpointParameterName = "type";
}

return endpointParameterName;
}
Expand Down
15 changes: 11 additions & 4 deletions src/Api/PubnubApi/EndPoint/Objects/SetMembershipsOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,20 @@ private RequestParameter CreateRequestParameter()
Dictionary<string, object> messageEnvelope = new Dictionary<string, object>();
if (addMembership != null) {
List<Dictionary<string, object>> setMembershipFormatList = new List<Dictionary<string, object>>();
for (int index = 0; index < addMembership.Count; index++) {
foreach (var membership in addMembership)
{
Dictionary<string, object> currentMembershipFormat = new Dictionary<string, object>
{
{ "channel", new Dictionary<string, string> { { "id", addMembership[index].Channel } } }
{ "channel", new Dictionary<string, string> { { "id", membership.Channel } } }
};
if (addMembership[index].Custom != null) {
currentMembershipFormat.Add("custom", addMembership[index].Custom);
if (membership.Custom != null) {
currentMembershipFormat.Add("custom", membership.Custom);
}
if (membership.Status != null) {
currentMembershipFormat.Add("status", membership.Status);
}
if (membership.Type != null) {
currentMembershipFormat.Add("type", membership.Type);
}
setMembershipFormatList.Add(currentMembershipFormat);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Api/PubnubApi/Enum/PNMembershipField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public enum PNMembershipField
{
CUSTOM,
CHANNEL,
CHANNEL_CUSTOM
CHANNEL_CUSTOM,
STATUS,
TYPE
}
}
1 change: 1 addition & 0 deletions src/Api/PubnubApi/EventEngine/Common/EventEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public void EmitEvent<T>(object e)
}
}
} else if (eventData.MessageType == 4) {
payloadContainer.Add(eventData.CustomMessageType);
ResponseBuilder responseBuilder = new ResponseBuilder(configuration, jsonLibrary, log);
PNMessageResult<object> pnFileResult = responseBuilder.JsonToObject<PNMessageResult<object>>(payloadContainer, true);
if (pnFileResult != null) {
Expand Down
11 changes: 11 additions & 0 deletions src/Api/PubnubApi/JsonDataParse/PNMembershipsJsonDataParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ internal static PNMembershipsResult GetObject(IJsonPluggableLibrary jsonPlug, Li
mbrshipItem.ChannelMetadata = channelMetadataResult;
}
}

mbrshipItem.Status =
(getMbrshipItemDataDic.ContainsKey("status") &&
getMbrshipItemDataDic["status"] != null)
? getMbrshipItemDataDic["status"]?.ToString()
: null;
mbrshipItem.Type =
(getMbrshipItemDataDic.ContainsKey("type") &&
getMbrshipItemDataDic["type"] != null)
? getMbrshipItemDataDic["type"]?.ToString()
: null;
result.Memberships.Add(mbrshipItem);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/Api/PubnubApi/JsonDataParse/PNObjectEventJsonDataParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,8 @@ internal static PNObjectEventResult GetObject(IJsonPluggableLibrary jsonPlug, Li
}
}
}
if (listObject.Count == 6) {
result.Subscription = listObject[4].ToString();
result.Channel = listObject[5].ToString();
} else if (listObject.Count == 5) {
result.Channel = listObject[4].ToString();
}
result.Subscription = listObject[4]?.ToString();
result.Channel = listObject[5].ToString();
}

return result;
Expand Down
6 changes: 6 additions & 0 deletions src/Api/PubnubApi/Model/Consumer/Objects/PNMembership.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ public class PNMembership

[JsonProperty(PropertyName = "custom", DefaultValueHandling = DefaultValueHandling.Ignore)]
public Dictionary<string, object> Custom { get; set; }

[JsonProperty(PropertyName = "status", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Status { get; set; }

[JsonProperty(PropertyName = "type", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Type { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class PNMembershipsItemResult
{
public PNChannelMetadataResult ChannelMetadata { get; internal set; }
public Dictionary<string, object> Custom { get; internal set; }

public string Type { get; set; }

public string Status { get; set; }
public string Updated { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PNFileEventResult
public string Publisher { get; internal set; }
public long Timetoken { get; internal set; }

public string CustomMessageType { get; set; }
public string CustomMessageType { get; internal set; }
public object Message { get; internal set; }
public PNFile File { get; internal set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public override void File(Pubnub pubnub, PNFileEventResult fileEvent)
message1.Timetoken = fileEvent.Timetoken;
message1.Publisher = fileEvent.Publisher;
message1.File = fileEvent.File;
message1.CustomMessageType = fileEvent.CustomMessageType;

fileAction?.Invoke(pubnub, message1);
}
Expand Down

0 comments on commit 8ba31a4

Please sign in to comment.