Files
telegram-bot/modules/RichSiteSummary/Data/Post.cs
T

114 lines
2.8 KiB
C#
Raw Normal View History

2023-07-29 15:03:45 +03:00
// This file is a part of RSS Bot for Telegram.
// License: MIT
// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
//
2020-03-02 00:00:52 +04:00
using System;
using System.ComponentModel.DataAnnotations;
2024-02-18 19:03:59 +03:00
using System.ComponentModel.DataAnnotations.Schema;
2020-03-02 00:00:52 +04:00
using System.Text;
2020-03-04 11:55:10 +04:00
using Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule;
2020-03-02 00:00:52 +04:00
using Telegram.Bot.Types.Enums;
2023-07-29 15:14:52 +03:00
namespace Kruzya.TelegramBot.RichSiteSummary.Data;
/// <summary>
/// Represents a post from feed in database.
/// </summary>
public class Post : RepresentableEntity
2020-03-02 00:00:52 +04:00
{
2023-07-29 15:14:52 +03:00
#region RepresentableEntity
protected override ParseMode DefaultRepresentation
2020-03-02 00:00:52 +04:00
{
2023-07-29 15:14:52 +03:00
get => ParseMode.Html;
}
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
protected override string ViewableText
{
get => Title;
}
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
protected override string ViewableUrl
{
get => UtmUtility.ApplyParameters(new Uri(new(Feed.Url), Url), new UtmParameters()
2020-03-02 00:00:52 +04:00
{
2023-07-29 15:14:52 +03:00
Source = "telegram",
Type = "rss_post",
Campaign = "subscriber",
Content = PostId.ToString()
});
}
2020-03-04 11:55:10 +04:00
2023-07-29 15:14:52 +03:00
#endregion
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
/// <summary>
/// The unique post id.
/// </summary>
[Key]
public Guid PostId { get; set; }
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
/// <summary>
/// The feed unique identifier from where this post is fetched.
/// </summary>
public Guid FeedId { get; set; }
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
/// <summary>
/// The feed from where this post is fetched.
/// </summary>
[Required]
public virtual Feed Feed { get; set; }
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
/// <summary>
/// The post title.
/// </summary>
[MaxLength(256)]
[Required]
public string Title { get; set; }
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
/// <summary>
/// The URI where this post is located in web.
/// </summary>
[Required]
[MaxLength(1024)]
2023-07-29 15:14:52 +03:00
public string Url { get; set; }
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
/// <summary>
/// DateTime when post is created in RSS feed.
/// </summary>
[Required]
public DateTime PostedAt { get; set; }
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
/// <summary>
/// DateTime when post is fetched/updated in database.
/// </summary>
[Required]
public DateTime ReceivedAt { get; set; }
2020-03-02 00:00:52 +04:00
/// <summary>
2024-02-18 19:03:59 +03:00
/// SHA256
/// </summary>
[MaxLength(64)]
2024-02-18 19:03:59 +03:00
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string UrlHash { get; set; }
2023-07-29 15:14:52 +03:00
public Post()
{
PostId = new Guid();
ReceivedAt = DateTime.Now;
}
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
public string MessageText
{
get
2020-03-02 00:00:52 +04:00
{
2023-07-29 15:14:52 +03:00
var message = new StringBuilder();
message.Append($"{Representation("🗞")} New on {Feed.Representation(ParseMode.Html)}\n");
message.Append("\n");
message.Append(Title);
message.Append("\n");
message.Append(Representation("Open in browser"));
2020-03-02 00:00:52 +04:00
2023-07-29 15:14:52 +03:00
return message.ToString();
2020-03-02 00:00:52 +04:00
}
}
2023-07-29 15:14:52 +03:00
}