internal UserChatroom GetUserChatroom(long userId) { var u = UserChatrooms.FirstOrDefault(uc => uc.UserId == userId); if (u == null) { throw new InvalidOperationException("User not exist."); } return(u); }
internal void Quit(long userId) { EnsureActive(); EnsureNotP2P(); var uc = GetUserChatroom(userId); if (uc == null) { throw new InvalidOperationException($"User {userId} doesn't exist in chatroom {Id}."); } UserChatrooms.Remove(uc); _provider.GetRequiredService <IEventBus>().Publish( new UserLeftEvent { ChatroomId = Id, UserId = userId, OperatorId = userId }); }
internal void AddPeople(long userId, long operatorId) { EnsureActive(); EnsureNotP2P(); EnsureAdmin(operatorId); if (UserIds.Contains(userId)) { throw new InvalidOperationException($"User {userId} already exist in chatroom {Id}."); } var uc = new UserChatroom { UserId = userId, ChatroomId = Id }; UserChatrooms.Add(uc); _provider.GetRequiredService <IEventBus>().Publish( new UserEnteredEvent { ChatroomId = Id, UserId = userId, OperatorId = operatorId }); }
internal bool Contains(User user) { return(UserChatrooms.Any(uc => uc.UserId == user.Id)); }