mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 04:49:33 -07:00
feat(email-notifications): Add a link to Ombi details page in email notifications (#4517)
[skip ci]
This commit is contained in:
parent
e09435da45
commit
a3e97b31e2
6 changed files with 47 additions and 4 deletions
|
@ -31,16 +31,35 @@ namespace Ombi.Notifications.Templates
|
||||||
private const string DateKey = "{@DATENOW}";
|
private const string DateKey = "{@DATENOW}";
|
||||||
private const string Logo = "{@LOGO}";
|
private const string Logo = "{@LOGO}";
|
||||||
|
|
||||||
public string LoadTemplate(string subject, string body, string imgsrc = default(string), string logo = default(string))
|
public string LoadTemplate(string subject, string body, string imgsrc = default(string), string logo = default(string), string url = default(string))
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder(File.ReadAllText(TemplateLocation));
|
var sb = new StringBuilder(File.ReadAllText(TemplateLocation));
|
||||||
sb.Replace(SubjectKey, subject);
|
sb.Replace(SubjectKey, subject);
|
||||||
sb.Replace(BodyKey, body);
|
sb.Replace(BodyKey, body);
|
||||||
sb.Replace(DateKey, DateTime.Now.ToString("f"));
|
sb.Replace(DateKey, DateTime.Now.ToString("f"));
|
||||||
sb.Replace(Poster, string.IsNullOrEmpty(imgsrc) ? string.Empty : $"<tr><td align=\"center\"><img src=\"{imgsrc}\" alt=\"Poster\" width=\"400px\" text-align=\"center\"/></td></tr>");
|
sb.Replace(Poster, GetPosterContent(imgsrc, url));
|
||||||
sb.Replace(Logo, string.IsNullOrEmpty(logo) ? OmbiLogo : logo);
|
sb.Replace(Logo, string.IsNullOrEmpty(logo) ? OmbiLogo : logo);
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetPosterContent(string imgsrc, string url) {
|
||||||
|
string posterContent;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(imgsrc))
|
||||||
|
{
|
||||||
|
posterContent = string.Empty;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
posterContent = $"<img src=\"{imgsrc}\" alt=\"Poster\" width=\"400px\" text-align=\"center\"/>";
|
||||||
|
if (!string.IsNullOrEmpty(url))
|
||||||
|
{
|
||||||
|
posterContent = $"<a href=\"{url}\">{posterContent}</a>";
|
||||||
|
}
|
||||||
|
posterContent = $"<tr><td align=\"center\">{posterContent}</td></tr>";
|
||||||
|
}
|
||||||
|
return posterContent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{
|
{
|
||||||
public interface IEmailBasicTemplate
|
public interface IEmailBasicTemplate
|
||||||
{
|
{
|
||||||
string LoadTemplate(string subject, string body, string img = default(string), string logo = default(string));
|
string LoadTemplate(string subject, string body, string img = default(string), string logo = default(string), string url = default(string));
|
||||||
string TemplateLocation { get; }
|
string TemplateLocation { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -64,7 +64,7 @@ namespace Ombi.Notifications.Agents
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var email = new EmailBasicTemplate();
|
var email = new EmailBasicTemplate();
|
||||||
var html = email.LoadTemplate(parsed.Subject, parsed.Message, parsed.Image, Customization.Logo);
|
var html = email.LoadTemplate(parsed.Subject, parsed.Message, parsed.Image, Customization.Logo, parsed.DetailsUrl);
|
||||||
|
|
||||||
|
|
||||||
var message = new NotificationMessage
|
var message = new NotificationMessage
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace Ombi.Notifications
|
||||||
public bool Disabled { get; set; }
|
public bool Disabled { get; set; }
|
||||||
public string Subject { get; set; }
|
public string Subject { get; set; }
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
|
public string DetailsUrl { get; set; }
|
||||||
public string Image { get; set; }
|
public string Image { get; set; }
|
||||||
public IReadOnlyDictionary<string, string> Data { get; set; }
|
public IReadOnlyDictionary<string, string> Data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,7 @@ namespace Ombi.Notifications
|
||||||
RequestId = req?.Id.ToString();
|
RequestId = req?.Id.ToString();
|
||||||
RequestedUser = req?.RequestedUser?.UserName;
|
RequestedUser = req?.RequestedUser?.UserName;
|
||||||
RequestedDate = req?.RequestedDate.ToString("D");
|
RequestedDate = req?.RequestedDate.ToString("D");
|
||||||
|
DetailsUrl = GetDetailsUrl(s, req);
|
||||||
|
|
||||||
if (Type.IsNullOrEmpty())
|
if (Type.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
|
@ -217,6 +218,26 @@ namespace Ombi.Notifications
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetDetailsUrl(CustomizationSettings s, BaseRequest req)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(s.ApplicationUrl))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (req)
|
||||||
|
{
|
||||||
|
case MovieRequests movieRequest:
|
||||||
|
return $"{s.ApplicationUrl}/details/movie/{movieRequest.TheMovieDbId}";
|
||||||
|
case ChildRequests tvRequest:
|
||||||
|
return $"{s.ApplicationUrl}/details/tv/{tvRequest.ParentRequest.ExternalProviderId}";
|
||||||
|
case AlbumRequest albumRequest:
|
||||||
|
return $"{s.ApplicationUrl}/details/artist/{albumRequest.ForeignArtistId}";
|
||||||
|
default:
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void CalculateRequestStatus(BaseRequest req)
|
private void CalculateRequestStatus(BaseRequest req)
|
||||||
{
|
{
|
||||||
RequestStatus = string.Empty;
|
RequestStatus = string.Empty;
|
||||||
|
@ -258,6 +279,7 @@ namespace Ombi.Notifications
|
||||||
public string Year { get; set; }
|
public string Year { get; set; }
|
||||||
public string EpisodesList { get; set; }
|
public string EpisodesList { get; set; }
|
||||||
public string SeasonsList { get; set; }
|
public string SeasonsList { get; set; }
|
||||||
|
public string DetailsUrl { get; set; }
|
||||||
public string PosterImage { get; set; }
|
public string PosterImage { get; set; }
|
||||||
public string ApplicationName { get; set; }
|
public string ApplicationName { get; set; }
|
||||||
public string ApplicationUrl { get; set; }
|
public string ApplicationUrl { get; set; }
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace Ombi.Notifications
|
||||||
{
|
{
|
||||||
var content = Resolve(notification.Message, notification.Subject, c.Curlys);
|
var content = Resolve(notification.Message, notification.Subject, c.Curlys);
|
||||||
content.Image = c.PosterImage;
|
content.Image = c.PosterImage;
|
||||||
|
content.DetailsUrl = c.DetailsUrl;
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue