public async Task <bool> Handle(LeaveFromRoomCommand request, CancellationToken cancellationToken)
        {
            // Get User from Cache
            CacheUser cacheUser = await _chatCacheModule.GetUserAsync(request.ConnectionId, cancellationToken);

            if (cacheUser == null)
            {
                throw new Exception("User doesnt exist. Please login");
            }

            // Set User's Room
            if (cacheUser.ConnectedRoomId == null)
            {
                throw new Exception("User didnt join any room. Please join to a room");
            }

            var userLeftNotification = new UserLeftNotification()
            {
                NickName = cacheUser.NickName, RoomId = cacheUser.ConnectedRoomId, ConnectionId = request.ConnectionId
            };

            cacheUser.ConnectedRoomId = null;
            await _chatCacheModule.SetUserAsync(cacheUser, cancellationToken);

            // Publish
            await _mediator.Publish(
                userLeftNotification,
                cancellationToken);

            return(await Task.FromResult(true));
        }
        public void Constructor_Always_PropertiesAreGiven()
        {
            var mockGuildUser = new Mock <ISocketGuildUser>();

            var uut = new UserLeftNotification(mockGuildUser.Object);

            uut.GuildUser.ShouldBeSameAs(mockGuildUser.Object);
        }
Esempio n. 3
0
        public Task HandleNotificationAsync(
            UserLeftNotification notification,
            CancellationToken cancellationToken)
        {
            var guild = notification.GuildUser.Guild;

            using var logScope = UserMetricsLogMessages.BeginGuildScope(_logger, guild.Id);

            UserMetricsLogMessages.UserLeftHandling(_logger);
            DoGuildStats(UserLeftCounterName, guild);
            UserMetricsLogMessages.UserLeftHandled(_logger);

            return(Task.CompletedTask);
        }
Esempio n. 4
0
 public Task HandleNotificationAsync(UserLeftNotification notification, CancellationToken cancellationToken)
 {
     ClearCacheEntry(notification.GuildUser.Guild);
     return(Task.CompletedTask);
 }