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;
|
|
|
|
|
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]
|
2024-02-18 18:50:01 +03:00
|
|
|
[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
|
|
|
|
2024-02-18 18:50:01 +03:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Required]
|
|
|
|
|
[MaxLength(64)]
|
|
|
|
|
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
|
|
|
}
|