🐛 Bug fixes in post embed links
This commit is contained in:
44
DysonNetwork.Sphere/Connection/WebReader/EmbeddableBase.cs
Normal file
44
DysonNetwork.Sphere/Connection/WebReader/EmbeddableBase.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DysonNetwork.Sphere.Connection.WebReader;
|
||||
|
||||
/// <summary>
|
||||
/// The embeddable can be used in the post or messages' meta's embeds fields
|
||||
/// To render a richer type of content.
|
||||
///
|
||||
/// A simple example of using link preview embed:
|
||||
/// <code>
|
||||
/// {
|
||||
/// // ... post content
|
||||
/// "meta": {
|
||||
/// "embeds": [
|
||||
/// {
|
||||
/// "type": "link",
|
||||
/// "title: "...",
|
||||
/// /// ...
|
||||
/// }
|
||||
/// ]
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public abstract class EmbeddableBase
|
||||
{
|
||||
public abstract string Type { get; }
|
||||
|
||||
public Dictionary<string, object> ToDictionary()
|
||||
{
|
||||
var dict = new Dictionary<string, object>();
|
||||
foreach (var prop in GetType().GetProperties())
|
||||
{
|
||||
if (prop.GetCustomAttribute<JsonIgnoreAttribute>() is not null)
|
||||
continue;
|
||||
var value = prop.GetValue(this);
|
||||
if (value is null) continue;
|
||||
dict[prop.Name] = value;
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
namespace DysonNetwork.Sphere.Connection.WebReader;
|
||||
|
||||
/// <summary>
|
||||
/// The embeddable can be used in the post or messages' meta's embeds fields
|
||||
/// To render richer type of content.
|
||||
///
|
||||
/// A simple example of using link preview embed:
|
||||
/// <code>
|
||||
/// {
|
||||
/// // ... post content
|
||||
/// "meta": {
|
||||
/// "embeds": [
|
||||
/// {
|
||||
/// "type": "link",
|
||||
/// "title: "...",
|
||||
/// /// ...
|
||||
/// }
|
||||
/// ]
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public interface IEmbeddable
|
||||
{
|
||||
public string Type { get; }
|
||||
}
|
@ -4,9 +4,9 @@ namespace DysonNetwork.Sphere.Connection.WebReader;
|
||||
/// The link embed is a part of the embeddable implementations
|
||||
/// It can be used in the post or messages' meta's embeds fields
|
||||
/// </summary>
|
||||
public class LinkEmbed : IEmbeddable
|
||||
public class LinkEmbed : EmbeddableBase
|
||||
{
|
||||
public string Type => "link";
|
||||
public override string Type => "link";
|
||||
|
||||
/// <summary>
|
||||
/// The original URL that was processed
|
||||
|
Reference in New Issue
Block a user