diff options
author | crupest <crupest@outlook.com> | 2021-05-15 16:01:21 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-05-15 16:01:21 +0800 |
commit | 49b0cb7b465561447b8d4693ba988b13e0e1b57a (patch) | |
tree | 4c533d940af0b2691619a960f439f5f33129a9ff /BackEnd/Timeline/Controllers/TimelinePostController.cs | |
parent | 741230818e8c8093f7ead04c7df1c21a17cceae4 (diff) | |
download | timeline-49b0cb7b465561447b8d4693ba988b13e0e1b57a.tar.gz timeline-49b0cb7b465561447b8d4693ba988b13e0e1b57a.tar.bz2 timeline-49b0cb7b465561447b8d4693ba988b13e0e1b57a.zip |
feat: Timeline post change notification with signalr.
Diffstat (limited to 'BackEnd/Timeline/Controllers/TimelinePostController.cs')
-rw-r--r-- | BackEnd/Timeline/Controllers/TimelinePostController.cs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index da45cbea..f00a689c 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.SignalR;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@@ -13,6 +15,7 @@ using Timeline.Models.Validation; using Timeline.Services.Mapper;
using Timeline.Services.Timeline;
using Timeline.Services.User;
+using Timeline.SignalRHub;
namespace Timeline.Controllers
{
@@ -24,6 +27,8 @@ namespace Timeline.Controllers [ProducesErrorResponseType(typeof(CommonResponse))]
public class TimelinePostController : MyControllerBase
{
+ private readonly ILogger<TimelinePostController> _logger;
+
private readonly ITimelineService _timelineService;
private readonly ITimelinePostService _postService;
@@ -31,12 +36,16 @@ namespace Timeline.Controllers private readonly MarkdownProcessor _markdownProcessor;
- public TimelinePostController(ITimelineService timelineService, ITimelinePostService timelinePostService, IGenericMapper mapper, MarkdownProcessor markdownProcessor)
+ private readonly IHubContext<TimelineHub> _timelineHubContext;
+
+ public TimelinePostController(ILogger<TimelinePostController> logger, ITimelineService timelineService, ITimelinePostService timelinePostService, IGenericMapper mapper, MarkdownProcessor markdownProcessor, IHubContext<TimelineHub> timelineHubContext)
{
+ _logger = logger;
_timelineService = timelineService;
_postService = timelinePostService;
_mapper = mapper;
_markdownProcessor = markdownProcessor;
+ _timelineHubContext = timelineHubContext;
}
private bool UserHasAllTimelineManagementPermission => UserHasPermission(UserPermission.AllTimelineManagement);
@@ -207,6 +216,11 @@ namespace Timeline.Controllers try
{
var post = await _postService.CreatePostAsync(timelineId, userId, createRequest);
+
+ var group = TimelineHub.GenerateTimelinePostChangeListeningGroupName(timeline);
+ await _timelineHubContext.Clients.Group(group).SendAsync(nameof(ITimelineClient.OnTimelinePostChanged), timeline);
+ _logger.LogInformation("Notify group {0} of timeline post change.", group);
+
var result = await Map(post);
return result;
}
|