Ejemplo n.º 1
0
        public async Task <IReadOnlyCollection <ChatParticipant> > Set(Guid chatId, IEnumerable <ChatUser> chatUsers, ChatParticipantType participantType,
                                                                       ChatParticipantStatus participantStatus, Guid setterId)
        {
            await Task.Yield();

            return(chatUsers.Select(chatUser => SetUser(chatId, chatUser, participantType, participantStatus)).ToList());
        }
Ejemplo n.º 2
0
 public ChatParticipant(ChatParticipantType chatParticipantType, ChatParticipantStatus chatParticipantStatus, DateTime readTimestamp, long readIndex, long version, Guid userId, string name, string details, Guid?avatarId = null, bool inviteOnly = false, bool canCreateChat = true, string style = null, string metadata = null)
     : base(userId, name, details, avatarId, inviteOnly, canCreateChat, style, metadata)
 {
     ChatParticipantType   = chatParticipantType;
     ChatParticipantStatus = chatParticipantStatus;
     ReadTimestamp         = readTimestamp;
     ReadIndex             = readIndex;
     Version = version;
 }
Ejemplo n.º 3
0
        public async Task <ChatParticipant> Set(Guid chatId, ChatUser chatUser, ChatParticipantStatus participantStatus, Guid setterId)
        {
            await Task.Yield();

            var participants = Store.Chats[chatId].Participants;

            lock (participants)
            {
                var exist = participants.FirstOrDefault(r => r.UserId == chatUser.UserId);
                if (exist == null)
                {
                    exist = new ChatParticipant(ChatParticipantType.ReadOnlyParticipant, participantStatus, DateTime.MinValue, -1, 0, chatUser);
                    participants.Add(exist);
                }
                else
                {
                    exist.Version += 1;
                    exist.ChatParticipantStatus = participantStatus;
                }
                return(exist);
            }
        }
Ejemplo n.º 4
0
        private ChatParticipant SetUser(Guid chatId, ChatUser chatUser, ChatParticipantType participantType, ChatParticipantStatus participantStatus)
        {
            var participants = Store.Chats[chatId].Participants;

            lock (participants)
            {
                var exist = participants.FirstOrDefault(r => r.UserId == chatUser.UserId);
                if (exist == null)
                {
                    exist = new ChatParticipant(participantType, participantStatus, DateTime.MinValue, -1, 0, chatUser);
                    participants.Add(exist);
                }
                else
                {
                    exist.Version              += 1;
                    exist.ChatParticipantType   = participantType;
                    exist.ChatParticipantStatus = participantStatus;
                }
                return(exist);
            }
        }
Ejemplo n.º 5
0
        public async Task <ChatParticipant> Set(Guid chatId, ChatUser chatUser, ChatParticipantType participantType, ChatParticipantStatus participantStatus,
                                                Guid setterId)
        {
            await Task.Yield();

            return(SetUser(chatId, chatUser, participantType, participantStatus));
        }
Ejemplo n.º 6
0
 public ChatParticipant(ChatParticipantType chatParticipantType, ChatParticipantStatus chatParticipantStatus, DateTime readTimestamp, long readIndex, long version, IChatUser user)
     : this(chatParticipantType, chatParticipantStatus, readTimestamp, readIndex, version, user.UserId, user.Name, user.Details, user.AvatarId, user.InviteOnly, user.CanCreateChat, user.Style, user.Metadata)
 {
 }
Ejemplo n.º 7
0
 protected virtual Task <TChatParticipant> SetUser <TCommand>(TCommand command, ChatParticipantStatus participantStatus)
     where TCommand : IHasInitiator, IChatRelated, IUserRelated
 {
     return(SetUser(command.ChatId, command.UserId, participantStatus, command.InitiatorUserId));
 }
Ejemplo n.º 8
0
        protected virtual async Task <TChatParticipant> SetUser(Guid chatId, Guid userId, ChatParticipantStatus participantStatus, Guid setterId)
        {
            var user = await ReadUserStore.Retrieve(userId).ConfigureAwait(false);

            return(await ChatParticipantStore.Set(chatId, user, participantStatus, setterId).ConfigureAwait(false));
        }
Ejemplo n.º 9
0
 protected virtual Task <TChatParticipant> SetParticipationCandidate <TCommand>(TCommand command, ChatParticipantStatus participantStatus)
     where TCommand : IHasInitiator, IChatRelated, IParticipationCandidate
 {
     return(SetParticipationCandidate(command.ChatId, command.UserId, command.ChatParticipantType, participantStatus, command.Style, command.Metadata,
                                      command.InitiatorUserId));
 }
Ejemplo n.º 10
0
        protected virtual async Task <TChatParticipant> SetParticipationCandidate(Guid chatId, Guid userId, ChatParticipantType participantType, ChatParticipantStatus participantStatus, string style, string metadata, Guid setterId)
        {
            var user = await ReadUserStore.Retrieve(userId).ConfigureAwait(false);

            user = ReadUserStore.Customize(user, style, metadata);
            return(await ChatParticipantStore.Set(chatId, user, participantType,
                                                  participantStatus, setterId).ConfigureAwait(false));
        }