Esempio n. 1
0
        public async Task CreateOrUpdatePushSubscriptionAsync(CreatePushTokenRequest request)
        {
            Ensure.That(request, nameof(request)).IsNotNull();

            var member = await _memberService.GetMemberBySaasUserIdAsync(request.SaasUserId);

            var subscribedChannels = await _channelService.GetAllowedChannelsAsync(request.SaasUserId);

            var tags = new List <string> {
                PushNotificationsTagTemplates.GetMemberSubscriptionTag(member.SaasUserId)
            };

            // add user subscribed channels tags
            tags.AddRange(subscribedChannels.Select(x => PushNotificationsTagTemplates.GetChatChannelTag(x.Id.ToString())));

            await _pushNotificationSubscriber.CreateOrUpdatePushSubscriptionAsync(new PushSubscriptionRequest(request.Token, request.DevicePlatform, tags));
        }
Esempio n. 2
0
        private async Task SendPushNotificationToChannelMembersAsync(string senderId, Guid channelId)
        {
            var includedTags = new List <string>
            {
                PushNotificationsTagTemplates.GetChatChannelTag(channelId.ToString())
            };

            var membersWithDisabledGroupNotifications = await _notificationSettingsService.GetSaasUserIdsWithDisabledGroupNotificationsAsync();

            var membersWithDisabledChannelNotifications = await _channelMemberService.GetSaasUserIdsWithDisabledChannelNotificationsAsync(channelId);

            var excludedTags = membersWithDisabledChannelNotifications.Select(x => PushNotificationsTagTemplates.GetMemberSubscriptionTag(x.ToString())).ToList();

            excludedTags.AddRange(membersWithDisabledGroupNotifications.Select(x => PushNotificationsTagTemplates.GetMemberSubscriptionTag(x.ToString())).ToList());
            // exclude sender
            excludedTags.Add(PushNotificationsTagTemplates.GetMemberSubscriptionTag(senderId));

            await _pushNotificationService.SendForTagAsync(new NewMessagePush { ChannelId = channelId }, includedTags, excludedTags);
        }
Esempio n. 3
0
        public async Task SubscribeUserOnTagAsync(string userId, string tagName)
        {
            var registrations = await _pushNotificationSubscriber.GetRegistrationsByTagAsync(PushNotificationsTagTemplates.GetMemberSubscriptionTag(userId));

            foreach (var registration in registrations)
            {
                if (!registration.Tags.Contains(tagName))
                {
                    registration.Tags.Add(tagName);

                    if (registration.Platform == PushPlatformEnum.iOS)
                    {
                        await _pushNotificationSubscriber.CreateOrUpdatePushSubscriptionAsync(new PushSubscriptionRequest(registration.PnsHandle, PushPlatformEnum.iOS, registration.Tags));
                    }
                    else if (registration.Platform == PushPlatformEnum.Android)
                    {
                        await _pushNotificationSubscriber.CreateOrUpdatePushSubscriptionAsync(new PushSubscriptionRequest(registration.PnsHandle, PushPlatformEnum.Android, registration.Tags));
                    }
                }
            }
        }
Esempio n. 4
0
        public async Task SubscribeUserOnTagsAsync(string userId, IEnumerable <string> tagNames)
        {
            var registrations = await _pushNotificationSubscriber.GetRegistrationsByTagAsync(PushNotificationsTagTemplates.GetMemberSubscriptionTag(userId));

            foreach (var registration in registrations)
            {
                bool hasAnyNotIncludedTags = false;
                var  notIncludedTags       = tagNames.Where(x => !registration.Tags.Contains(x));

                foreach (var notIncludedTag in notIncludedTags)
                {
                    registration.Tags.Add(notIncludedTag);
                    hasAnyNotIncludedTags = true;
                }

                if (hasAnyNotIncludedTags)
                {
                    if (registration.Platform == PushPlatformEnum.iOS)
                    {
                        await _pushNotificationSubscriber.CreateOrUpdatePushSubscriptionAsync(new PushSubscriptionRequest(registration.PnsHandle, PushPlatformEnum.iOS, registration.Tags));
                    }
                    else if (registration.Platform == PushPlatformEnum.Android)
                    {
                        await _pushNotificationSubscriber.CreateOrUpdatePushSubscriptionAsync(new PushSubscriptionRequest(registration.PnsHandle, PushPlatformEnum.Android, registration.Tags));
                    }
                }
            }
        }