Пример #1
0
        private void MaybeSendCampfireNotification(SendNotificationRequest request)
        {
            if (request.Application == null ||
                !request.Application.CampfireRoomId.HasValue ||
                request.Organisation.CampfireDetails == null ||
                request.Organisation.CampfireDetails.Token.IsNullOrEmpty() ||
                request.Organisation.CampfireDetails.Company.IsNullOrEmpty())
            {
                return;
            }

            string message = request.EmailInfo.ConvertToNonHtmlMessage(_configuration);

            if (message.IsNullOrEmpty())
            {
                return;
            }

            var campfireMessage = new SendCampfireMessage
            {
                CampfireDetails = request.Organisation.CampfireDetails,
                RoomId          = request.Application.CampfireRoomId.Value,
                Message         = message
            };

            Session.AddCommitAction(new SendMessageCommitAction(campfireMessage, _configuration.GetNotificationsQueueAddress(request.Organisation == null ? "1" : request.Organisation.RavenInstance.FriendlyId)));
        }
Пример #2
0
        private void MaybeSendHipChatNotification(SendNotificationRequest request)
        {
            if (request.Application == null || !request.Application.HipChatRoomId.HasValue || request.Organisation.HipChatAuthToken.IsNullOrEmpty())
            {
                return;
            }

            string message = request.EmailInfo.ConvertToSimpleMessage(_configuration);

            if (message.IsNullOrEmpty())
            {
                return;
            }

            var hipChatMessage = new SendHipChatMessage
            {
                HipChatRoomId    = request.Application.HipChatRoomId.Value,
                HipChatAuthToken = request.Organisation.HipChatAuthToken,
                Message          = message,
                Colour           = request.EmailInfo.HipChatColour,
            };

            Session.AddCommitAction(new SendMessageCommitAction(hipChatMessage,
                                                                _configuration.GetNotificationsQueueAddress(request.Organisation == null ?
                                                                                                            "1" :
                                                                                                            request.Organisation.RavenInstance.FriendlyId)));
        }
Пример #3
0
        private void MaybeSendIndividualEmailNotification(SendNotificationRequest request)
        {
            if (request.EmailInfo == null || request.EmailInfo.To.IsNullOrEmpty())
            {
                return;
            }

            Session.AddCommitAction(new SendMessageCommitAction(
                                        request.EmailInfo,
                                        _configuration.GetNotificationsQueueAddress(request.Organisation == null ? "1" : request.Organisation.RavenInstance.FriendlyId)));
        }
Пример #4
0
        public virtual SendNotificationResponse Invoke(SendNotificationRequest request)
        {
            //dont send emails to demo users, but they may want to try out chat features
            if (request.Organisation != null && request.Organisation.IsDemoOrganisation)
            {
                MaybeSendCampfireNotification(request);
                MaybeSendHipChatNotification(request);
            }
            else
            {
                MaybeSendIndividualEmailNotification(request);
                MaybeSendGroupEmailNotification(request);
                MaybeSendCampfireNotification(request);
                MaybeSendHipChatNotification(request);
            }

            return(new SendNotificationResponse());
        }
Пример #5
0
        private void MaybeSendGroupEmailNotification(SendNotificationRequest request)
        {
            if (request.Groups.Count == 0 && request.Users.Count == 0)
            {
                return;
            }

            ArgumentValidation.NotNull(request.OrganisationId, "request.OrganisationId");

            var allUsers = _getUsersQuery.Invoke(new GetUsersRequest
            {
                OrganisationId = request.OrganisationId,
                Paging         = new PageRequestWithSort(1, _configuration.MaxPageSize)
            }).Users;

            var usersToSendTo = (from userId in request.Users
                                 join userFromDb in allUsers.Items on userId equals userFromDb.Id
                                 select userFromDb)
                                .Union(
                from userFromDb2 in allUsers.Items
                from userGroup in userFromDb2.GroupIds
                join groupId in request.Groups on userGroup equals groupId
                select userFromDb2).Distinct().ToList();

            if (usersToSendTo.Count == 0)
            {
                return;
            }

            request.EmailInfo.To = usersToSendTo.Aggregate(string.Empty, (current, u) => current + (u.Email + ';')).TrimEnd(';');

            Session.AddCommitAction(new SendMessageCommitAction(request.EmailInfo,
                                                                _configuration.GetNotificationsQueueAddress(request.Organisation == null ?
                                                                                                            "1" :
                                                                                                            request.Organisation.RavenInstance.FriendlyId)));
        }