Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OC.Notifications.Abstractions docs #14427

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,53 @@

namespace OrchardCore.Notifications;

/// <summary>
/// Represents a contract for notification events.
/// </summary>
public interface INotificationEvents
{
/// <summary>
/// Occurs before the notification is created.
/// </summary>
/// <param name="context">The <see cref="NotificationContext"/>.</param>
Task CreatingAsync(NotificationContext context);

/// <summary>
/// Occurs after the notification is created.
/// </summary>
/// <param name="context">The <see cref="NotificationContext"/>.</param>
Task CreatedAsync(NotificationContext context);

/// <summary>
/// Occurs before the notification is sent.
/// </summary>
/// <param name="provider">The <see cref="INotificationMethodProvider"/>.</param>
/// <param name="context">The <see cref="NotificationContext"/>.</param>
Task SendingAsync(INotificationMethodProvider provider, NotificationContext context);

/// <summary>
/// Occurs after the notification is sent.
/// </summary>
/// <param name="provider">The <see cref="INotificationMethodProvider"/>.</param>
/// <param name="context">The <see cref="NotificationContext"/>.</param>
Task SentAsync(INotificationMethodProvider provider, NotificationContext context);

/// <summary>
/// Occurs when the notification is failed.
/// </summary>
/// <param name="provider">The <see cref="INotificationMethodProvider"/>.</param>
/// <param name="context">The <see cref="NotificationContext"/>.</param>
Task FailedAsync(INotificationMethodProvider provider, NotificationContext context);

/// <summary>
/// Occurs before the notification is sent.
/// </summary>
/// <param name="context">The <see cref="NotificationContext"/>.</param>
Task SendingAsync(NotificationContext context);

/// <summary>
/// Occurs after the notification is sent.
/// </summary>
/// <param name="context">The <see cref="NotificationContext"/>.</param>
Task SentAsync(NotificationContext context);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
namespace OrchardCore.Notifications;

/// <summary>
/// Represents a contract for notification message information.
/// </summary>
public interface INotificationMessage
{
/// <summary>
/// Gets the message summary.
/// </summary>
string Summary { get; }

/// <summary>
/// Gets the plain message body.
/// </summary>
string TextBody { get; }

/// <summary>
/// Gets the HTML message body.
/// </summary>
string HtmlBody { get; }

/// <summary>
/// Gets whether HTML is preferred for the message body.
/// </summary>
bool IsHtmlPreferred { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@

namespace OrchardCore.Notifications;

/// <summary>
/// Represents a contract for a notification provider.
/// </summary>
public interface INotificationMethodProvider
{
/// <summary>
/// Unique name for the provider.
/// Gets the provider name.
/// </summary>
/// <remarks>The name should be unique.</remarks>
string Method { get; }

/// <summary>
/// A localized name for the method.
/// Gets a localized name for the method.
/// </summary>
LocalizedString Name { get; }

/// <summary>
/// Attempts to send the given message to the given notifiable object.
/// </summary>
/// <param name="notify"></param>
/// <param name="message"></param>
/// <param name="notify">The notifiable object.</param>
/// <param name="message">The <see cref="INotificationMessage"/>.</param>
/// <returns><c>true</c> when the message was successfully sent otherwise <c>false</c>.</returns>
Task<bool> TrySendAsync(object notify, INotificationMessage message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

namespace OrchardCore.Notifications;

/// <summary>
/// Represents a contract for accessing the <see cref="INotificationMethodProvider"/>.
/// </summary>
public interface INotificationMethodProviderAccessor
{
/// <summary>
/// Gets the registered notification method providers.
/// </summary>
/// <param name="notify">The notifiable object.</param>
/// <returns>A list of <see cref="INotificationMethodProvider"/>.</returns>
Task<IEnumerable<INotificationMethodProvider>> GetProvidersAsync(object notify);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace OrchardCore.Notifications;

/// <summary>
/// Contract for notification service.
/// </summary>
public interface INotificationService
{
/// <summary>
/// Attempts to send the given message to the given notifiable object.
/// </summary>
/// <param name="notify"></param>
/// <param name="message"></param>
/// <param name="notify">The notifiable object.</param>
/// <param name="message">The message to be sent.</param>
/// <returns>The number of messages that were successfully sent to the user.</returns>
Task<int> SendAsync(object notify, INotificationMessage message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@

namespace OrchardCore.Notifications;

/// <summary>
/// Represents a notification entity.
/// </summary>
public class Notification : Entity
{
/// <summary>
/// The Id of the notification.
/// Gets or sets the notification Id.
/// </summary>
public string NotificationId { get; set; }

/// <summary>
/// The summary of the notification
/// Gets or sets the notification summary.
/// </summary>
public string Summary { get; set; }

/// <summary>
/// The user id of the user who caused the event to occur.
/// Gets or sets the user id who caused the event to occur.
/// </summary>
public string UserId { get; set; }

/// <summary>
/// The date and time when the event occurred.
/// Gets or sets the date and time when the event occurred.
/// </summary>
public DateTime CreatedUtc { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

namespace OrchardCore.Notifications;

/// <summary>
/// Represents a context for notification.
/// </summary>
public class NotificationContext
{
public Notification Notification { get; set; }

public INotificationMessage NotificationMessage { get; }

public object Notify { get; }

/// <summary>
/// Creates a new instance of <see cref="NotificationContext"/>.
/// </summary>
/// <param name="notificationMessage">The notification message.</param>
/// <param name="notify">The notifiable object.</param>
/// <exception cref="ArgumentNullException">Occurs when <paramref name="notificationMessage"/> is <c>null</c>,</exception>
public NotificationContext(INotificationMessage notificationMessage, object notify)
{
NotificationMessage = notificationMessage ?? throw new ArgumentNullException(nameof(notificationMessage));
Notify = notify ?? throw new ArgumentNullException(nameof(notify));
}

/// <summary>
/// Gets ot sets the notification.
/// </summary>
public Notification Notification { get; set; }

/// <summary>
/// Gets or sets the notification message.
/// </summary>
public INotificationMessage NotificationMessage { get; }

/// <summary>
/// Gets or sets the notifiable object.
/// </summary>
public object Notify { get; }
}