Example #1
0
        public void CreateModeratorInvite(Channel channel, User inviter, User invited)
        {
            var now = DateTime.UtcNow;
            var moderatorNotification = new ModeratorNotificationModel
            {
                SenderName      = inviter.FirstName,
                SenderAvatarUrl = inviter.AvatarUrl,
                ChannelName     = channel.Name,
                ChannelId       = channel.Id,
                Date            = now.ToShortDateString(),
                Time            = now.ToShortTimeString(),
                Timestamp       = now.ToFileTimeUtc(),
                Guid            = Guid.NewGuid() //gera novo GUID
            };


            var    rz        = new RazorTemplate();
            string htmlNotif = rz.ParseRazorTemplate <ModeratorNotificationModel>
                                   ("~/Website/Views/NotificationPartials/Accept.cshtml", moderatorNotification);

            var wrapper = new ModeratorNotificationWrapper()
            {
                ChannelId = moderatorNotification.ChannelId,
                Html      = htmlNotif
            };

            NimbusHubContext.Clients.Group(NimbusHub.GetMessageGroupName(invited.Id)).newModeratorNotification(wrapper);

            StoreNotification(moderatorNotification, invited.Id);
        }
Example #2
0
        public void NewComment(Comment comment)
        {
            string topicGroup = NimbusHub.GetTopicGroupName(comment.TopicId);

            NimbusHubContext.Clients.Group(topicGroup)
            .newTopicCommentNotification(new
            {
                commentId = comment.Id,
                parentId  = comment.ParentId,
                topicId   = comment.TopicId
            });
        }
Example #3
0
        /// <summary>
        /// Envia notificações de tópico novo para os usuários seguidores do canal.
        /// Utiliza mesmo canal de notificações de mensagem.
        /// </summary>
        /// <param name="topic"></param>
        public void NewTopic(Topic topic)
        {
            using (var db = DatabaseFactory.OpenDbConnection())
            {
                var channelFollowers = db.Where <ChannelUser>(chu => chu.ChannelId == topic.ChannelId &&
                                                              chu.Follow == true &&
                                                              chu.Accepted == true &&
                                                              chu.Visible == true);

                var channel = db.Where <Channel>(ch => ch.Id == topic.ChannelId).FirstOrDefault();

                var now = DateTime.UtcNow;

                var nt = new TopicNotificationModel()
                {
                    TopicId          = topic.Id,
                    TopicName        = topic.Title,
                    ChannelId        = topic.ChannelId,
                    ChannelName      = channel.Name,
                    TopicImage       = topic.ImgUrl,
                    NotificationType = Model.NotificationTypeEnum.newtopic,

                    Date      = now.ToShortDateString(),
                    Time      = now.ToShortTimeString(),
                    Timestamp = now.ToFileTimeUtc(),
                };

                var    rz        = new RazorTemplate();
                string htmlNotif = rz.ParseRazorTemplate <TopicNotificationModel>
                                       ("~/Website/Views/NotificationPartials/NewTopic.cshtml", nt);

                foreach (var follower in channelFollowers)
                {
                    var ntClone = new TopicNotificationModel(nt);
                    NimbusHubContext.Clients.Group(NimbusHub.GetFollowerGroupName(follower.UserId)).newMessageNotification(htmlNotif);

                    StoreNotification(ntClone, follower.UserId);
                }

                var ntChClone = new TopicNotificationModel(nt);
                StoreNotificationChannel(ntChClone);
            }
        }
Example #4
0
        public void NewMessage(Model.ORM.Message msg)
        {
            var        sender    = msg.Receivers.Where(r => r.UserId == msg.SenderId).FirstOrDefault();
            List <int> receivers = msg.Receivers.Where(r => r.UserId != msg.SenderId).Select(s => s.UserId).ToList();

            if (receivers.Count() == 0)
            {
                receivers = new List <int>();
                receivers.Add(sender.UserId);
            }


            var messageNotification = new MessageNotificationModel
            {
                SenderName      = sender.Name,
                SenderAvatarUrl = sender.AvatarUrl,
                Subject         = msg.Title,
                MessageId       = msg.Id,
                Date            = msg.Date.ToShortDateString(),
                Time            = msg.Date.ToShortTimeString(),
                Timestamp       = msg.Date.ToFileTimeUtc()
            };

            Parallel.ForEach(receivers, (receiver) =>
            {
                var msgCopy = new MessageNotificationModel(messageNotification);

                var rz           = new RazorTemplate();
                string htmlNotif = rz.ParseRazorTemplate <MessageNotificationModel>
                                       ("~/Website/Views/NotificationPartials/Message.cshtml", msgCopy);

                var wrapper = new MessageNotificationWrapper()
                {
                    MessageId = msgCopy.MessageId,
                    Html      = htmlNotif
                };

                NimbusHubContext.Clients.Group(NimbusHub.GetMessageGroupName(receiver)).newMessageNotification(wrapper);

                StoreNotification(msgCopy, receiver);
            });
        }