Beispiel #1
0
        public async Task <ActionResult> CommentTo(long solutionId, long replyToCommentId)
        {
            var solution = await _problemAppService.GetSolution(solutionId);

            var reply = await _articleController.ReplyToComment(replyToCommentId);

            // publish notification to all subscriber, exclude self
            await _notificationPublisher.PublishAsync(NotificationName.CommentSolution,
                                                      new MessageNotificationData(Url.Action("GetSolution", new { SolutionId = solutionId })),
                                                      new EntityIdentifier(typeof(ProblemSolution), solutionId),
                                                      excludedUserIds : new [] { new UserIdentifier(AppConsts.DefaultTenant, AbpSession.GetUserId()) });

            // subscribe comment notification
            await _notificationSubscriptionManager.SubscribeAsync(
                new UserIdentifier(AbpSession.TenantId, AbpSession.GetUserId()),
                NotificationName.CommentSolution, new EntityIdentifier(typeof(ProblemSolution), solutionId));

            return(View("Template/Comment/CommentTo", new CommentToViewModel
            {
                ArticleId = solution.SolutionId,
                CommentTitle = solution.SolutionTitle,
                CommentToLink = Url.Action("GetSolution", new { solutionId }),
                ReplyToCommentId = reply.Second,
                ReturnUrl = Url.Action("GetSolution", new { solutionId }),
                ContentInit = reply.First
            }));
        }
        public async Task <IActionResult> CommentTo(long articleId, int replyToCommentId)
        {
            var article = await _articleAppService.GetArticleAsync(articleId);

            var reply = await ReplyToComment(replyToCommentId);

            // publish notification to all subscriber, exclude self
            await _notificationPublisher.PublishAsync(NotificationName.CommentArticle,
                                                      new MessageNotificationData(Url.Action("GetArticle", "Article", new { ArticleId = articleId })),
                                                      new EntityIdentifier(typeof(Blog), articleId),
                                                      excludedUserIds : new[] { new UserIdentifier(AppConsts.DefaultTenant, AbpSession.GetUserId()) });

            // subscribe comment notification
            await _notificationSubscriptionManager.SubscribeAsync(
                new UserIdentifier(AbpSession.TenantId, AbpSession.GetUserId()),
                NotificationName.CommentArticle, new EntityIdentifier(typeof(Blog), articleId));

            return(View("Template/Comment/CommentTo", new CommentToViewModel
            {
                ArticleId = article.ArticleId,
                CommentTitle = article.Title,
                CommentToLink = Url.Action("GetArticle", new { ArticleId = articleId }),
                ReplyToCommentId = reply.Second,
                ReturnUrl = Url.Action("GetArticle", new { ArticleId = articleId }),
                ContentInit = reply.First
            }));
        }
Beispiel #3
0
        /// <summary>
        /// 指定提供者发布通知
        /// </summary>
        /// <param name="providers">提供者列表</param>
        /// <param name="notificationInfo">通知信息</param>
        /// <returns></returns>
        protected async Task PublishFromProvidersAsync(IEnumerable <INotificationPublishProvider> providers,
                                                       NotificationInfo notificationInfo)
        {
            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            // TODO: 某些情况下,不能直接在服务内订阅消息,目前只能通过将订阅内容放进消息内部,需要重构通知系统设计了
            if (notificationInfo.Data.HasUserNotification(out Guid userId, out string userName))
            {
                await NotificationSubscriptionManager.SubscribeAsync(notificationInfo.TenantId,
                                                                     new UserIdentifier(userId, userName), notificationInfo.Name);
            }

            Logger.LogDebug($"Gets a list of user subscriptions {notificationInfo.Name}");
            // 获取用户订阅列表
            var userSubscriptions = await NotificationSubscriptionManager.GetSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name);

            Logger.LogDebug($"Persistent user notifications {notificationInfo.Name}");
            // 持久化用户通知
            var subscriptionUserIdentifiers = userSubscriptions.Select(us => new UserIdentifier(us.UserId, us.UserName));

            await NotificationStore.InsertUserNotificationsAsync(notificationInfo,
                                                                 subscriptionUserIdentifiers.Select(u => u.UserId));

            // 发布通知
            foreach (var provider in providers)
            {
                await PublishAsync(provider, notificationInfo, subscriptionUserIdentifiers);
            }

            if (notificationInfo.Lifetime == NotificationLifetime.OnlyOne)
            {
                // 一次性通知在发送完成后就取消用户订阅
                await NotificationStore.DeleteAllUserSubscriptionAsync(notificationInfo.TenantId,
                                                                       notificationInfo.Name);
            }
        }