Beispiel #1
0
        public IdentityService(IServiceProvider provider)
        {
            _logger = provider.GetService <ILoggerFactory>()?
                      .CreateLogger <IdentityService>();
            _userManager   = provider.GetRequiredService <UserManager <ChatIdentityUser> >();
            _signInManager = provider.GetRequiredService <SignInManager <ChatIdentityUser> >();
            _userRepo      = provider.GetRequiredService <IUserRepository>();
            _chatroomRepo  = provider.GetRequiredService <IChatroomRepository>();
            _eventBus      = provider.GetRequiredService <IEventBus>();

            Subcriptions.Add(_eventBus.GetEventStream <UserSignupEvent>()
                             .Subscribe(async e => await AddNewUserToGlobalChatroom(e)));
            Subcriptions.Add(_eventBus.GetEventStream <UserEnteredEvent>()
                             .Subscribe(async e =>
            {
                var room = await _chatroomRepo.GetByIdAsync(e.ChatroomId);
                var user = await _userRepo.GetByIdAsync(e.UserId);
                user.UserChatrooms.Add(room.UserChatrooms.First(uc => uc.UserId == e.UserId));
                await _userRepo.SaveChangesAsync();
            }));
            Subcriptions.Add(_eventBus.GetEventStream <UserLeftEvent>()
                             .Subscribe(async e =>
            {
                var room = await _chatroomRepo.GetByIdAsync(e.ChatroomId);
                var user = await _userRepo.GetByIdAsync(e.UserId);
                user.UserChatrooms.Remove(user.UserChatrooms.First(uc => uc.ChatroomId == e.ChatroomId));
                await _userRepo.SaveChangesAsync();
            }));
//	        EnsureAddAdmin().Wait();
        }
Beispiel #2
0
        public ChatroomService(IServiceProvider provider)
        {
            _logger = provider.GetService <ILoggerFactory>()?
                      .CreateLogger <ChatroomService>();
            _chatroomRepo = provider.GetRequiredService <IChatroomRepository>();
            _userRepo     = provider.GetRequiredService <IUserRepository>();
            _eventBus     = provider.GetRequiredService <IEventBus>();

            Subcriptions.Add(_eventBus.GetEventStream <BecameFriendsEvent>().Subscribe(
                                 async e => await GetOrAddP2PChatroom(e.UserId, e.User2Id)));
        }
Beispiel #3
0
        public UserClientService(IServiceProvider provider)
        {
            _logger = provider.GetService <ILoggerFactory>()?
                      .CreateLogger <UserClientService>();
            _chatroomRepo = provider.GetRequiredService <IChatroomRepository>();
            _eventBus     = provider.GetRequiredService <IEventBus>();

            Subcriptions.Add(_eventBus.GetEventStream <ChatroomEvent>()
                             .Select(ChatroomEventMapper.Map)
                             .Where(m => m?.Content != null)
                             .Subscribe(async m => await ForwardMessage(m)));
        }