Skip to content

Commit

Permalink
refactor: rename ListItems to ChoiceItem and ProductItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Dovchik committed Apr 25, 2024
1 parent 3aab328 commit f775c76
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Sinch.Conversation.Messages.Message
/// <summary>
/// A message component for interactive messages, containing a choice.
/// </summary>
public class ListItemChoice : IListItem
public class ChoiceItem : IListItem
{
/// <summary>
/// Required parameter. Title for the choice item.
Expand Down
16 changes: 8 additions & 8 deletions src/Sinch/Conversation/Messages/Message/ListMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public class ListItemJsonConverter : JsonConverter<IListItem>
var elem = JsonElement.ParseValue(ref reader);
if (elem.TryGetProperty("choice", out var choice))
{
return choice.Deserialize<ListItemChoice>(options);
return choice.Deserialize<ChoiceItem>(options);
}

if (elem.TryGetProperty("product", out var product))
{
return product.Deserialize<ListItemProduct>(options);
return product.Deserialize<ProductItem>(options);
}

throw new JsonException(
Expand All @@ -120,20 +120,20 @@ public class ListItemJsonConverter : JsonConverter<IListItem>
public override void Write(Utf8JsonWriter writer, IListItem value, JsonSerializerOptions options)
{
var type = value.GetType();
if (type == typeof(ListItemChoice))
if (type == typeof(ChoiceItem))
{
JsonSerializer.Serialize(writer, new ListItemChoiceWrapper()
{
Choice = value as ListItemChoice
Choice = value as ChoiceItem
}, options);
return;
}

if (type == typeof(ListItemProduct))
if (type == typeof(ProductItem))
{
JsonSerializer.Serialize(writer, new ListItemProductWrapper()
{
Product = value as ListItemProduct
Product = value as ProductItem
}, options);
return;
}
Expand All @@ -145,12 +145,12 @@ public override void Write(Utf8JsonWriter writer, IListItem value, JsonSerialize

internal class ListItemChoiceWrapper
{
public ListItemChoice? Choice { get; set; }
public ChoiceItem? Choice { get; set; }
}

internal class ListItemProductWrapper
{
public ListItemProduct? Product { get; set; }
public ProductItem? Product { get; set; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Sinch.Conversation.Messages.Message
/// <summary>
/// A message component for interactive messages, containing a product.
/// </summary>
public sealed class ListItemProduct : IListItem
public sealed class ProductItem : IListItem
{
/// <summary>
/// Required parameter. The ID for the product.
Expand Down
4 changes: 2 additions & 2 deletions tests/Sinch.Tests/Conversation/MessagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task GetMessage()
Title = "sec1",
Items = new List<IListItem>()
{
new ListItemChoice()
new ChoiceItem()
{
Title = "title",
Description = "desc",
Expand All @@ -61,7 +61,7 @@ public async Task GetMessage()
Title = "sec2",
Items = new List<IListItem>
{
new ListItemProduct()
new ProductItem()
{
Id = "id",
Marketplace = "amazon"
Expand Down
4 changes: 2 additions & 2 deletions tests/Sinch.Tests/Conversation/SendMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public async Task SendList()
Title = "item1",
Items = new List<IListItem>()
{
new ListItemChoice()
new ChoiceItem()
{
Title = "listitemchoice",
PostbackData = "postno",
Expand All @@ -393,7 +393,7 @@ public async Task SendList()
ThumbnailUrl = new Uri("https://knowyourmeme.com/photos/377946")
}
},
new ListItemProduct
new ProductItem
{
Id = "prod_id",
Marketplace = "amazon",
Expand Down

0 comments on commit f775c76

Please sign in to comment.