mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
Fixed the way we will be using custom messages
This commit is contained in:
parent
8953d4eaa8
commit
fea4dd6309
9 changed files with 223 additions and 115 deletions
|
@ -1,7 +1,7 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: NotificationMessageResolution.cs
|
||||
// File: NotificationMessageContent.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
|
@ -26,7 +26,7 @@
|
|||
#endregion
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public class NotificationMessageResolution
|
||||
public class NotificationMessageContent
|
||||
{
|
||||
public string Subject { get; set; }
|
||||
public string Body { get; set; }
|
57
PlexRequests.Core/NotificationMessageCurlys.cs
Normal file
57
PlexRequests.Core/NotificationMessageCurlys.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: NotificationMessageCurlys.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public class NotificationMessageCurlys
|
||||
{
|
||||
public NotificationMessageCurlys(string username, string title, string dateTime, string type, string issue)
|
||||
{
|
||||
Username = username;
|
||||
Title = title;
|
||||
Date = dateTime;
|
||||
Type = type;
|
||||
Issue = issue;
|
||||
}
|
||||
private string Username { get; }
|
||||
private string Title { get; }
|
||||
private string Date { get; }
|
||||
private string Type { get; }
|
||||
private string Issue { get; }
|
||||
|
||||
public Dictionary<string, string> Curlys => new Dictionary<string, string>
|
||||
{
|
||||
{nameof(Username), Username },
|
||||
{nameof(Title), Title },
|
||||
{nameof(Date), Date },
|
||||
{nameof(Type), Type },
|
||||
{nameof(Issue), Issue }
|
||||
};
|
||||
}
|
||||
}
|
|
@ -36,17 +36,17 @@ namespace PlexRequests.Core
|
|||
{
|
||||
private const char StartChar = (char)123;
|
||||
private const char EndChar = (char)125;
|
||||
public NotificationMessageResolution ParseMessage<T>(T notification, NotificationType type) where T : NotificationSettings
|
||||
public NotificationMessageContent ParseMessage<T>(T notification, NotificationType type, NotificationMessageCurlys c) where T : NotificationSettings
|
||||
{
|
||||
var bodyToParse = notification.Message.FirstOrDefault(x => x.Key == type).Value;
|
||||
var subjectToParse = notification.Subject.FirstOrDefault(x => x.Key == type).Value;
|
||||
var content = notification.Message.FirstOrDefault(x => x.Key == type).Value;
|
||||
|
||||
//if (string.IsNullOrEmpty(notificationToParse))
|
||||
// return string.Empty;
|
||||
|
||||
return Resolve(bodyToParse, subjectToParse, notification.CustomParamaters);
|
||||
return Resolve(content.Body, content.Subject, c.Curlys);
|
||||
}
|
||||
|
||||
private NotificationMessageResolution Resolve(string body, string subject, Dictionary<string, string> paramaters)
|
||||
private NotificationMessageContent Resolve(string body, string subject, Dictionary<string, string> paramaters)
|
||||
{
|
||||
|
||||
var bodyFields = FindCurlyFields(body);
|
||||
|
@ -70,11 +70,15 @@ namespace PlexRequests.Core
|
|||
}
|
||||
}
|
||||
|
||||
return new NotificationMessageResolution { Body = body, Subject = subject };
|
||||
return new NotificationMessageContent { Body = body ?? string.Empty, Subject = subject ?? string.Empty };
|
||||
}
|
||||
|
||||
private IEnumerable<string> FindCurlyFields(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
var insideCurly = false;
|
||||
var fields = new List<string>();
|
||||
var currentWord = string.Empty;
|
||||
|
|
|
@ -71,7 +71,8 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CacheKeys.cs" />
|
||||
<Compile Include="NotificationMessageResolution.cs" />
|
||||
<Compile Include="NotificationMessageContent.cs" />
|
||||
<Compile Include="NotificationMessageCurlys.cs" />
|
||||
<Compile Include="NotificationMessageResolver.cs" />
|
||||
<Compile Include="IIssueService.cs" />
|
||||
<Compile Include="IRequestService.cs" />
|
||||
|
|
|
@ -34,18 +34,28 @@ namespace PlexRequests.Core.SettingModels
|
|||
{
|
||||
public NotificationSettings()
|
||||
{
|
||||
CustomParamaters = new Dictionary<string, string>
|
||||
Message = new Dictionary<NotificationType, NotificationMessageContent>
|
||||
{
|
||||
{"Username", string.Empty },
|
||||
{"Date", string.Empty },
|
||||
{"Title", string.Empty },
|
||||
{"RequestType", string.Empty },
|
||||
{"Issue", string.Empty },
|
||||
|
||||
{NotificationType.NewRequest, new NotificationMessageContent() },
|
||||
{NotificationType.Issue, new NotificationMessageContent() },
|
||||
{NotificationType.AdminNote, new NotificationMessageContent() },
|
||||
{NotificationType.RequestApproved, new NotificationMessageContent() },
|
||||
{NotificationType.RequestAvailable, new NotificationMessageContent() },
|
||||
{NotificationType.Test, new NotificationMessageContent() },
|
||||
};
|
||||
}
|
||||
public Dictionary<NotificationType, string> Message { get; set; }
|
||||
public Dictionary<NotificationType, string> Subject { get; set; }
|
||||
public Dictionary<string,string> CustomParamaters { get; set; }
|
||||
public Dictionary<NotificationType, NotificationMessageContent> Message { get; set; }
|
||||
}
|
||||
|
||||
public static class NotificationCurly
|
||||
{
|
||||
public static readonly List<string> Curlys = new List<string>
|
||||
{
|
||||
"Username",
|
||||
"Title",
|
||||
"Date",
|
||||
"Issue",
|
||||
"Type"
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue