public async Task SendRoleAssignedNotification(int?currentTenant, User currentUser, User userAssigned)
        {
            var assignedUserIdentifier = new UserIdentifier(currentTenant, userAssigned.Id);
            var dataToSend             = new LocalizableMessageNotificationData(new LocalizableString("RoleAssignedNotification", AbpModuleZeroConsts.LocalizationSourceName))
            {
                ["userName"]         = currentUser.FullName,
                ["usernameAssigned"] = userAssigned.FullName,
                ["userId"]           = userAssigned.Id
            };
            await
            _notificationPublisher.PublishAsync(NotificationNames.RoleAssigned, dataToSend);

            var isRegistered = await
                               _notificationSubscriptionManager.IsSubscribedAsync(assignedUserIdentifier
                                                                                  , NotificationNames.RoleAssignedToUser);

            if (!isRegistered)
            {
                await _notificationSubscriptionManager.SubscribeAsync(assignedUserIdentifier, NotificationNames.RoleAssignedToUser);
            }
            var dataToSendUser = new LocalizableMessageNotificationData(new LocalizableString("RoleAssignedNotificationToUser", AbpModuleZeroConsts.LocalizationSourceName))
            {
                ["userName"]         = currentUser.FullName,
                ["usernameAssigned"] = userAssigned.FullName,
                ["userId"]           = userAssigned.Id
            };
            await _notificationPublisher.PublishAsync(NotificationNames.RoleAssignedToUser, dataToSendUser, userIds : new[] { assignedUserIdentifier });
        }
Beispiel #2
0
        public async Task SubscribeTenantToEditionChanges(Tenant tenant, Edition edition, User tenantOwner)
        {
            var entityIdentifier = new EntityIdentifier(typeof(Edition), edition.Id);
            var userIdentifier   = new UserIdentifier(tenant.Id, tenantOwner.Id);
            await _notificationSubscriptionManager.SubscribeAsync(userIdentifier, NotificationNames.EditionEdited, entityIdentifier);

            await _notificationSubscriptionManager.SubscribeAsync(userIdentifier, NotificationNames.EditionDeleted, entityIdentifier);
        }
        protected virtual async Task SeedUserSubscriptionNotifiersAsync(IUserData user)
        {
            var userIdentifier = new UserIdentifier(user.Id, user.UserName);

            await _notificationSubscriptionManager
            .SubscribeAsync(
                user.TenantId,
                userIdentifier,
                MessageServiceNotificationNames.IM.FriendValidation);

            await _notificationSubscriptionManager
            .SubscribeAsync(
                user.TenantId,
                userIdentifier,
                MessageServiceNotificationNames.IM.NewFriend);
        }
Beispiel #4
0
        public async Task CreateUser(CreateUserInput input)
        {
            var user = input.MapTo <User>();

            user.TenantId         = AbpSession.TenantId;
            user.Password         = new PasswordHasher().HashPassword(input.Password);
            user.IsEmailConfirmed = true;

            // todo: надо добавлять новые разрешения в AuthorizationProvider
            //// по умолчанию всегда добавляется разрешение Users
            //var p = _permissionManager.GetPermission("Users");
            //await _userManager.GrantPermissionAsync(user, p);

            var result = await UserManager.CreateAsync(user);

            CheckErrors(result);

            if (result.Succeeded)
            {
                await CurrentUnitOfWork.SaveChangesAsync();

                // подписка на изменение баланса
                await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(null, user.Id), "BalanceChanged");

                // добавление начального баланса
                EventBus.Trigger(new UserCreatedEventData {
                    UserId = user.Id
                });
            }
        }
Beispiel #5
0
        public async Task HandleEventAsync(EntityCreatedEventData <UserEto> eventData)
        {
            // 获取默认语言
            var userDefaultCultureName = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage);

            if (userDefaultCultureName.IsNullOrWhiteSpace())
            {
                userDefaultCultureName = CultureInfo.CurrentUICulture.Name;
                // CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(userDefaultCultureName);
            }
            using (CultureHelper.Use(userDefaultCultureName, userDefaultCultureName))
            {
                var userIdentifer = new UserIdentifier(eventData.Entity.Id, eventData.Entity.UserName);
                // 订阅用户欢迎消息
                await _notificationSubscriptionManager.SubscribeAsync(eventData.Entity.TenantId,
                                                                      userIdentifer, UserNotificationNames.WelcomeToApplication);

                // Store未检查已订阅
                //await _notificationStore.InsertUserSubscriptionAsync(eventData.Entity.TenantId,
                //    userIdentifer, UserNotificationNames.WelcomeToApplication);

                var userWelcomeNotifictionData = NotificationData.CreateUserNotificationData(eventData.Entity.Id, eventData.Entity.UserName);

                userWelcomeNotifictionData.WriteStandardData(
                    L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName),
                    L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName),
                    DateTime.Now, eventData.Entity.UserName);

                // 换成用户名称,而不是用户名
                // userWelcomeNotifictionData.Properties["message"] = L("WelcomeToApplicationFormUser", eventData.Entity.Name);

                var noticeNormalizerName = NotificationNameNormalizer.NormalizerName(UserNotificationNames.WelcomeToApplication);
                await _notificationDispatcher.DispatchAsync(noticeNormalizerName, userWelcomeNotifictionData, eventData.Entity.TenantId);
            }
        }
Beispiel #6
0
        //Just for test, could be implemented better
        private async Task ManageSubscription(string notificationName)
        {
            var userIdentifier = new UserIdentifier(AbpSession.TenantId, AbpSession.UserId ?? -1);

            if (AbpSession.UserId.HasValue &&
                !_notificationSubscriptionManager.IsSubscribed(
                    userIdentifier, notificationName))
            {
                await _notificationSubscriptionManager.SubscribeAsync(userIdentifier, notificationName);
            }
        }
Beispiel #7
0
        public async Task UpdateNotificationSettings(UpdateNotificationSettingsInput input)
        {
            await SettingManager.ChangeSettingForUserAsync(AbpSession.ToUserIdentifier(), NotificationSettingNames.ReceiveNotifications, input.ReceiveNotifications.ToString());

            foreach (var notification in input.Notifications)
            {
                if (notification.IsSubscribed)
                {
                    await _notificationSubscriptionManager.SubscribeAsync(AbpSession.ToUserIdentifier(), notification.Name);
                }
                else
                {
                    await _notificationSubscriptionManager.UnsubscribeAsync(AbpSession.ToUserIdentifier(), notification.Name);
                }
            }
        }
        public async Task RegisterToResponsibleNotifications(User user, Todo todo)
        {
            var notificationUserIdentity = new UserIdentifier(1, user.Id);
            var entityIdentity           = new EntityIdentifier(typeof(Todo), todo.Id);

            if (todo.ResponsibleId.HasValue && user.Id != todo.ResponsibleId)
            {
                //If the todo has already a responsible
                //its diferent we unsubscribe the old responsible from the notifications
                await _notificationSubscriptionManager.UnsubscribeAsync(
                    new UserIdentifier(1, (long)todo.ResponsibleId),
                    TodoNotificationTypes.AddedAsResponsibleOfTask,
                    entityIdentity);
            }
            //As responsible user must be register to his todo notifications
            await _notificationSubscriptionManager.SubscribeAsync(
                notificationUserIdentity,
                TodoNotificationTypes.AddedAsResponsibleOfTask,
                entityIdentity);
        }
Beispiel #9
0
        /// <summary>
        /// 更新通知设置
        /// </summary>
        public async Task UpdateNotificationSettings(UpdateNotificationSettingsInput input)
        {
            var currentUserId = AbpSession.ToUserIdentifier();

            //是否接收通知
            await SettingManager.ChangeSettingForUserAsync(currentUserId, NotificationSettingNames.ReceiveNotifications, input.ReceiveNotifications.ToString());

            foreach (var notification in input.Notifications)
            {
                if (notification.IsSubscribed)
                {
                    //订阅通知
                    await _notificationSubscriptionManager.SubscribeAsync(currentUserId, notification.Name);
                }
                else
                {
                    //关闭通知订阅
                    await _notificationSubscriptionManager.UnsubscribeAsync(currentUserId, notification.Name);
                }
            }
        }
        public async Task RegisterToGeneralNotifications(Project project, long userId)
        {
            //Register the user
            var userIdentifier = new UserIdentifier(1, userId);
            // To the entity
            // So he doesnt get notifications from another project
            var entityIdentifier = new EntityIdentifier(typeof(Project), project.Id);

            //Register to all todo changes notifications
            //Added to project
            await _notificationSubscriptionManager.SubscribeAsync(userIdentifier,
                                                                  TodoNotificationTypes.AddedToProjectNotification, entityIdentifier);

            //TodoList name changed
            await _notificationSubscriptionManager.SubscribeAsync(userIdentifier,
                                                                  TodoNotificationTypes.TodoListNameChanged, entityIdentifier);

            //Status change
            await _notificationSubscriptionManager.SubscribeAsync(userIdentifier,
                                                                  TodoNotificationTypes.TodoChangeStatusForAllInProject, entityIdentifier);

            //Date set
            await _notificationSubscriptionManager.SubscribeAsync(userIdentifier,
                                                                  TodoNotificationTypes.TodoDateEdited, entityIdentifier);

            //Name changed
            await _notificationSubscriptionManager.SubscribeAsync(userIdentifier,
                                                                  TodoNotificationTypes.TodoNameEdited, entityIdentifier);

            //Todo deleted
            await
            _notificationSubscriptionManager.SubscribeAsync(userIdentifier,
                                                            TodoNotificationTypes.TodoDeleted,
                                                            entityIdentifier);

            //Todo discussions
            await
            _notificationSubscriptionManager.SubscribeAsync(userIdentifier,
                                                            TodoNotificationTypes.DiscussionMessage,
                                                            entityIdentifier);
        }
        public async Task SendRoleDeletedNotification(int tenantId, User user, Role role, long[] userIdsInRole)
        {
            var dataToSend = new LocalizableMessageNotificationData(new LocalizableString("RoleDeletedByUser", AbpModuleZeroConsts.LocalizationSourceName))
            {
                ["roleName"] = role.DisplayName,
                ["user"]     = user.FullName
            };
            await _notificationPublisher.PublishAsync(NotificationNames.RoleDeleted, dataToSend, severity : NotificationSeverity.Warn);

            foreach (var l in userIdsInRole)
            {
                var userIdentifier = new UserIdentifier(tenantId, l);

                if ((!await(_notificationSubscriptionManager.IsSubscribedAsync(userIdentifier, NotificationNames.RoleDeletedForUser))))
                {
                    await _notificationSubscriptionManager.SubscribeAsync(userIdentifier, NotificationNames.RoleDeletedForUser);
                }
            }

            var roleToUserNotificationData = new LocalizableMessageNotificationData(new LocalizableString("RoleDeletedForUser", AbpModuleZeroConsts.LocalizationSourceName));

            await _notificationPublisher.PublishAsync(NotificationNames.RoleDeletedForUser, roleToUserNotificationData, severity : NotificationSeverity.Warn);
        }
Beispiel #12
0
        public async Task HandleEventAsync(EntityCreatedEventData <UserEto> eventData)
        {
            var userIdentifer = new UserIdentifier(eventData.Entity.Id, eventData.Entity.UserName);
            // 订阅用户欢迎消息
            await _notificationSubscriptionManager
            .SubscribeAsync(
                eventData.Entity.TenantId,
                userIdentifer,
                UserNotificationNames.WelcomeToApplication);

            var userWelcomeNotifictionData = new NotificationData();

            //userWelcomeNotifictionData.WriteStandardData(
            //    L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName),
            //    L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName),
            //    DateTime.Now, eventData.Entity.UserName);

            userWelcomeNotifictionData
            .WriteLocalizedData(
                new LocalizableStringInfo(
                    LocalizationResourceNameAttribute.GetName(typeof(MessageServiceResource)),
                    "WelcomeToApplicationFormUser"),
                new LocalizableStringInfo(
                    LocalizationResourceNameAttribute.GetName(typeof(MessageServiceResource)),
                    "WelcomeToApplicationFormUser"),
                DateTime.Now, eventData.Entity.UserName);

            await _notificationSender
            .SendNofiterAsync(
                UserNotificationNames.WelcomeToApplication,
                userWelcomeNotifictionData,
                userIdentifer,
                eventData.Entity.TenantId,
                NotificationSeverity.Info
                );
        }
 /// <summary>
 /// Subscribes to a notification.
 /// </summary>
 /// <param name="notificationSubscriptionManager">Notification subscription manager</param>
 /// <param name="user">User.</param>
 /// <param name="notificationName">Name of the notification.</param>
 /// <param name="entityIdentifier">entity identifier</param>
 public static void Subscribe(this INotificationSubscriptionManager notificationSubscriptionManager, UserIdentifier user, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     AsyncHelper.RunSync(() => notificationSubscriptionManager.SubscribeAsync(user, notificationName, entityIdentifier));
 }
Beispiel #14
0
 public async Task SubscribeToNotification(NotificationSubscriptionInput input)
 {
     await _notificationSubscriptionManager.SubscribeAsync(input.UserIdentifier, input.NotificationName, input.EntityIdentifier);
 }
 /// <summary>
 /// Subscribes to a notification.
 /// </summary>
 /// <param name="notificationSubscriptionManager">Notification subscription manager</param>
 /// <param name="userId">The user id.</param>
 /// <param name="notificationName">Name of the notification.</param>
 /// <param name="tenantId"></param>
 /// <param name="entityIdentifier">entity identifier</param>
 public static void Subscribe(this INotificationSubscriptionManager notificationSubscriptionManager, int?tenantId, long userId, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     AsyncHelper.RunSync(() => notificationSubscriptionManager.SubscribeAsync(tenantId, userId, notificationName, entityIdentifier));
 }
Beispiel #16
0
 //Subscribe to a general notification
 public async Task Subscribe_SentFriendshipRequest(int?tenantId, long userId)
 {
     await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(tenantId, userId), "SentFriendshipRequest");
 }
Beispiel #17
0
 public async Task Subscribe_SentFrendshipRequest(long userId)
 {
     await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(null, userId), "SentFrendshipRequest");
 }
 public async Task SubscribeAsync(string notificationName)
 {
     await _notificationSubscriptionManager.SubscribeAsync(LoginIdentifier, notificationName);
 }
Beispiel #19
0
 public async Task Subscribe(string notificationName)
 {
     await _notificationSubscriptionManager.SubscribeAsync(GetCurrentUserIdentifier(), notificationName);
 }
        /// <summary>
        /// Subscribe both users to the conversation
        /// </summary>
        /// <param name="convId"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private async Task SubscribeFromToUsers(string convId, UserIdentifier from, UserIdentifier to)
        {
            await _notificationSubscriptionManager.SubscribeAsync(from, convId);

            await _notificationSubscriptionManager.SubscribeAsync(to, convId);
        }
Beispiel #21
0
 public async Task Subscribe_Message(long userId)
 {
     await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(null, userId), "Message");
 }