Exemple #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));
        }
        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);
        }
        public async Task <ChannelSummaryResponse> CreateDirectChannelAsync(CreateDirectChannelRequest request)
        {
            var channel = await _channelService.CreateDirectChannelAsync(request);

            // subscribe creator on channel
            await _pushNotificationService.SubscribeUserOnTagAsync(request.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(channel.Id.ToString()));

            var member = await _memberService.GetMemberByIdAsync(request.MemberId);

            // subscribe member on channel
            await _pushNotificationService.SubscribeUserOnTagAsync(member.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(channel.Id.ToString()));

            await _channelNotificationService.OnAddChannel(channel);

            //todo filter creator connection id on join channel
            await _channelNotificationService.OnJoinChannel(member, channel);

            return(channel);
        }
        public async Task <ChannelSummaryResponse> CreateChannelAsync(CreateChannelRequest request)
        {
            var channel = await _channelService.CreateChannelAsync(request);

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

            // subscribe creator on channel
            await _pushNotificationService.SubscribeUserOnTagAsync(member.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(channel.Id.ToString()));

            if (request.AllowedMembers != null)
            {
                // subscribe invited members
                foreach (var allowedMemberId in request.AllowedMembers)
                {
                    var chatMember = await _memberService.GetMemberByIdAsync(Guid.Parse(allowedMemberId));

                    if (chatMember == null)
                    {
                        throw new NetKitChatNotFoundException($"Specified chat member {allowedMemberId} is not found.");
                    }

                    await _pushNotificationService.SubscribeUserOnTagAsync(chatMember.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(channel.Id.ToString()));
                }
            }

            await _channelNotificationService.OnAddChannel(channel);

            //todo filter creator connection id on join channel
            await _channelNotificationService.OnJoinChannel(member, channel);

            return(channel);
        }
        public async Task MuteChannelAsync(MuteChannelRequest request)
        {
            if (request.IsMuted)
            {
                await _pushNotificationService.UnsubscribeUserFromTagAsync(request.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(request.ChannelId.ToString()));
            }
            else
            {
                await _pushNotificationService.SubscribeUserOnTagAsync(request.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(request.ChannelId.ToString()));
            }

            await _channelService.MuteChannelAsync(request.SaasUserId, request.ChannelId, request.IsMuted);
        }
        public async Task DeleteMemberFromChannelAsync(DeleteMemberRequest request)
        {
            var memberToDelete = await _memberService.GetMemberByIdAsync(request.MemberId);

            await _channelService.DeleteMemberFromChannelAsync(request.SaasUserId, request.ChannelId, memberToDelete.Id);

            await _pushNotificationService.UnsubscribeUserFromTagAsync(memberToDelete.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(request.ChannelId.ToString()));

            await _channelNotificationService.OnDeletedFromChannel(memberToDelete, request.ChannelId);

            await SendSystemMessageAsync(request.SaasUserId, request.ChannelId, new MemberDeletedLocalizationVisitor(memberToDelete), _systemMessagesConfiguration.MemberDeleted, memberToDelete.UserName);
        }
        public async Task LeaveChannelAsync(ChannelRequest request)
        {
            var member = await _memberService.GetMemberBySaasUserIdAsync(request.SaasUserId);

            await _channelService.LeaveFromChannelAsync(request.SaasUserId, request.ChannelId);

            await _pushNotificationService.UnsubscribeUserFromTagAsync(member.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(request.ChannelId.ToString()));

            await _channelNotificationService.OnLeaveChannel(member, request.ChannelId);

            await SendSystemMessageAsync(request.SaasUserId, request.ChannelId, new MemberLeftLocalizationVisitor(member), _systemMessagesConfiguration.MemberLeft, member.UserName);
        }
        public async Task <ChannelResponse> InviteMemberAsync(InviteMemberRequest request)
        {
            var inviteMemberResponse = await _memberService.InviteMemberAsync(request.MemberId, request.ChannelId);

            var invitedMember = await _memberService.GetMemberByIdAsync(request.MemberId);

            var channel = await _channelService.GetChannelSummaryAsync(request.SaasUserId, request.ChannelId);

            if (invitedMember != null && channel != null)
            {
                await _pushNotificationService.SubscribeUserOnTagAsync(invitedMember.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(channel.Id.ToString()));
            }

            await _channelNotificationService.OnJoinChannel(invitedMember, channel);

            return(inviteMemberResponse);
        }
        public async Task JoinToChannelAsync(ChannelRequest request)
        {
            // Locate the room, does NOT have to be open
            await _channelService.JoinToChannelAsync(request.SaasUserId, request.ChannelId);

            var channel = await _channelService.GetChannelSummaryAsync(request.SaasUserId, request.ChannelId);

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

            await _pushNotificationService.SubscribeUserOnTagAsync(member.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(request.ChannelId.ToString()));

            await _channelNotificationService.OnJoinChannel(member, channel);

            await SendSystemMessageAsync(request.SaasUserId, request.ChannelId, new MemberJoinedLocalizationVisitor(member), _systemMessagesConfiguration.MemberJoined, member.UserName);
        }
        public async Task CloseChannelAsync(ChannelRequest request)
        {
            await _channelService.CloseChannelAsync(request.SaasUserId, request.ChannelId);

            var channelSummary = await _channelService.GetChannelSummaryAsync(request.SaasUserId, request.ChannelId);

            await _channelNotificationService.OnCloseChannel(channelSummary);

            var channelMembers = await _memberService.GetChannelMembersAsync(request.ChannelId);

            foreach (var member in channelMembers)
            {
                // unsubscribe user from channel
                await _pushNotificationService.UnsubscribeUserFromTagAsync(member.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(request.ChannelId.ToString()));
            }

            // TODO [az]: do we need this notification?
            await _channelNotificationService.OnUpdateChannel(channelSummary);
        }
Exemple #11
0
        public async Task <IActionResult> SubscribeUserOnChannelsAsync()
        {
            var userId = GetCurrentSaasUserId();

            var memberChannels = await _channelService.GetMemberChannelsAsync(userId);

            await _pushNotificationService.SubscribeUserOnTagsAsync(userId, memberChannels.Select(x => PushNotificationsTagTemplates.GetChatChannelTag(x.Id.ToString())));

            return(Ok());
        }
Exemple #12
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));
                    }
                }
            }
        }
Exemple #13
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));
                    }
                }
            }
        }