Example #1
0
        internal UserChatroom GetUserChatroom(long userId)
        {
            var u = UserChatrooms.FirstOrDefault(uc => uc.UserId == userId);

            if (u == null)
            {
                throw new InvalidOperationException("User not exist.");
            }
            return(u);
        }
Example #2
0
        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
            });
        }
Example #3
0
        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
            });
        }
Example #4
0
 internal bool Contains(User user)
 {
     return(UserChatrooms.Any(uc => uc.UserId == user.Id));
 }