Exemple #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);
        }
Exemple #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
            });
        }
Exemple #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
            });
        }
Exemple #4
0
 internal bool Contains(User user)
 {
     return(UserChatrooms.Any(uc => uc.UserId == user.Id));
 }