Skip to content

Commit

Permalink
Update MentionController.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed May 30, 2024
1 parent 0d57d50 commit ce88430
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Moonglade.Web/Controllers/MentionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Moonglade.Pingback;
using Moonglade.Web.Attributes;
using System.ComponentModel.DataAnnotations;
using Moonglade.Webmention;

namespace Moonglade.Web.Controllers;

Expand All @@ -22,14 +23,15 @@ public class MentionController(
if (!blogConfig.AdvancedSettings.EnableWebmention) return Forbid();

var ip = Helper.GetClientIP(HttpContext);
// Verify that the source URL links to the target URL
// TODO
var response = await mediator.Send(new ReceiveWebmentionCommand(source, target, ip));
if (response.Status == WebmentionStatus.Success)
{
SendMentionEmailAction(response.MentionEntity);
return Ok("Webmention received and verified.");
}

// Process the Webmention
// TODO

// For demonstration purposes, we'll just return a success message.
return Ok("Webmention received and verified.");
return BadRequest("Webmention verification failed.");
}

[HttpPost("/pingback")]
Expand All @@ -46,17 +48,17 @@ public async Task<IActionResult> ReceivePingback()
var response = await mediator.Send(new ReceivePingCommand(requestBody, ip));
if (response.Status == PingbackStatus.Success)
{
SendPingbackEmailAction(response.MentionEntity);
SendMentionEmailAction(response.MentionEntity);
}

return new PingbackResult(response.Status);
}

private async void SendPingbackEmailAction(MentionEntity history)
private async void SendMentionEmailAction(MentionEntity history)
{
try
{
await mediator.Publish(new PingbackNotification(history.TargetPostTitle, history.Domain, history.SourceIp, history.SourceUrl, history.SourceTitle));
await mediator.Publish(new MentionNotification(history.TargetPostTitle, history.Domain, history.SourceIp, history.SourceUrl, history.SourceTitle));
}
catch (Exception e)
{
Expand Down

0 comments on commit ce88430

Please sign in to comment.