public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var message = await _context.ChatMessages.AsNoTracking() .ProjectTo <Response>(_mapper.ConfigurationProvider) .FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken); _signalRHub.Send(HubEndpointConstants.ChatEndpoint, message); return(message); }
/// <inheritdoc /> /// <summary> /// Calls when user connected. /// </summary> /// <returns></returns> public override Task OnConnectedAsync() { if (Context.User.Identity.IsAuthenticated) { var model = new OnlineCounterModel { Id = int.Parse(Context.User.Claims.First(x => x.Type == "sub").Value), UserName = Context.User.Identity.Name, ConnectionId = Context.ConnectionId }; OnlineUsers.CurrentOnline.AddOrUpdate(Context.ConnectionId, model, (k, v) => model); } else { OnlineUsers.CurrentOnlineGuests.Add(Context.ConnectionId); } _signalRHub.Send(HubEndpointConstants.UsersOnlineEndpoint, OnlineUsers.GetStats()); return(base.OnConnectedAsync()); }
public async Task <IActionResult> CreateAsync([FromBody] CreateCommentCommand.Request request) { var result = await Mediator.Send(request); CacheManager.Remove(CacheKeysConstants.MaterialsLatest, CacheKeysConstants.MaterialsPinned, CacheKeysConstants.LastComments); var oldMessage = result.Message.Substring(0); result.Message = result.Message.SanitizeComment(); if (!string.IsNullOrWhiteSpace(result.Message)) { _signalRHubAggregator.Send(HubEndpointConstants.AddComment, result); } result.Message = oldMessage; return(Ok(result)); }