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(); }
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))); }
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))); }