Ejemplo n.º 1
0
        public static async Task <Conversation> AddConversation(ConversationViewModel model)
        {
            await UserService.AddUsers(model.Participants);

            if (!string.IsNullOrEmpty(model.Creator))
            {
                await UserService.AddUsers(model.Creator);
            }
            if (!string.IsNullOrEmpty(model.Owner))
            {
                await UserService.AddUsers(model.Owner);
            }
            var conversation = new Conversation
            {
                Id           = model.Id,
                Type         = model.Type,
                Creator      = UserService.GetUser(model.Creator),
                Owner        = UserService.GetUser(model.Owner),
                Participants = UserService.Users.Where(u => model.Participants.Contains(u.Nickname)).ToArray()
            };

            switch (model.Type)
            {
            case ConversationType.Passive:
                PassiveConversationService.Conversations.Add(conversation);
                break;

            case ConversationType.Active:
                break;
            }

            return(conversation);
        }
Ejemplo n.º 2
0
        public static async Task <Conversation> AddConversation(ConversationType type, params string[] participants)
        {
            await UserService.AddUsers(participants);

            var conversation = new Conversation
            {
                Id           = Guid.Empty,
                Type         = type,
                Creator      = null,
                Owner        = null,
                Participants = UserService.Users.Where(u => participants.Contains(u.Nickname)).ToArray()
            };

            switch (type)
            {
            case ConversationType.Passive:
                PassiveConversationService.Conversations.Add(conversation);
                break;

            case ConversationType.Active:
                break;
            }

            return(conversation);
        }
Ejemplo n.º 3
0
        private void SelectConversationByActive(Conversation conversation)
        {
            var controls = ConversationList.Items.OfType <ConversationControl>();

            var control =
                controls.FirstOrDefault(c => c.ActiveConversation.Participants.SequenceEqual(conversation.Participants));

            if (control == null)
            {
                return;
            }

            ConversationList.SelectedItem = control;
        }
Ejemplo n.º 4
0
        private void DisplayMessages(Conversation conversation)
        {
            var messageDisplay = MessageDisplays.FirstOrDefault(m => m.Conversation == conversation);

            if (messageDisplay == null)
            {
                messageDisplay = new MessageDisplayControl(conversation);
                MessageDisplays.Add(messageDisplay);
            }

            MessagesPanel.Children.Clear();
            MessagesPanel.Children.Add(messageDisplay);
            CurrentMessageDisplay = messageDisplay;
        }
Ejemplo n.º 5
0
        private void SendPassiveMessage(Conversation conversation, TextMessage message)
        {
            if (CurrentMessageDisplay == null)
            {
                return;
            }

            foreach (var participant in conversation.Participants.Where(p => p.Nickname != UserService.LoggedUser.Nickname))
            {
                ClientService.Client.Send(new Message().DirectText(participant.Nickname, message.Content));
            }

            conversation.Messages.Add(message);
            CurrentMessageDisplay.AddMessageControl(message);
        }
Ejemplo n.º 6
0
        private void DisplayInfo(Conversation conversation)
        {
            var user = conversation.Participants.FirstOrDefault(u => u.Nickname != UserService.LoggedUser.Nickname);

            if (user == null)
            {
                return;
            }

            var userInfo = new UserInfoControl(user);

            userInfo.Called += OnUserCall;

            CurrentUserInfo = userInfo;
            UserInfoGrid.Children.Clear();
            UserInfoGrid.Children.Add(userInfo);
        }
Ejemplo n.º 7
0
        private void DisplayActiveConversationView(Conversation activeConversation)
        {
            if (CurrentActiveConversationView == null)
            {
                CurrentActiveConversationView = new ActiveConversationViewControl(activeConversation);
                CurrentActiveConversationView.MicrophoneToggled += OnMicrophoneToggle;
                CurrentActiveConversationView.SpeakerToggled    += OnSpeakerToggle;
                CurrentActiveConversationView.HangedUp          += OnHangedUp;
            }
            else if (CurrentActiveConversationView?.Conversation != activeConversation)
            {
                throw new InvalidOperationException("Cannot show new conversation when there is already one in progress.");
            }

            ActiveConversationGrid.Children.Clear();
            ActiveConversationGrid.Children.Add(CurrentActiveConversationView);
            ActiveConversationRow.Height = new GridLength(2, GridUnitType.Star);
        }
Ejemplo n.º 8
0
        private void Call(User user)
        {
            ClientService.Client.Call(user.Nickname);

            var conversation = new Conversation
            {
                Type         = ConversationType.Active,
                Creator      = UserService.LoggedUser,
                Owner        = UserService.LoggedUser,
                Participants = ClientService.Client.Conversation.Participants.Select(p => UserService.GetUser(p.Nickname)).ToArray()
            };

            ActiveConversationService.CurrentActiveConversation = conversation;
            SelectedConversationControl.ActiveConversation      = conversation;


            StartConversation();
        }
Ejemplo n.º 9
0
        public static async Task GetMoreMessages(this Conversation conversation, int page = 0, int count = 100)
        {
            var          filter = Filter.CreateNew.Set("ConversationId", conversation.Id);
            HttpResponse response;

            if (conversation.Messages.Any())
            {
                var earliestMessage = conversation.Messages.MinBy(m => m.Timestamp);
                response = await RestService.MessageApi.Get(RestService.CurrentToken, filter, earliestMessage.Id, page, count);
            }
            else
            {
                response = await RestService.MessageApi.Get(RestService.CurrentToken, filter, page, count);
            }

            if (response.Error != null)
            {
                throw new RestErrorException(response.Error);
            }

            var messages = response.GetModel <MessageViewModel[]>();

            conversation.Messages.AddRange(messages.Select(m => new TextMessage(m.Id, m.Content, m.Timestamp, UserService.Users.FirstOrDefault(u => u.Nickname == m.Sender))));
        }
Ejemplo n.º 10
0
 private void SendActiveMessage(Conversation conversation, TextMessage message)
 {
     //ClientService.Client.Conversation.SendToAll(Message.CreateNew.Text(message.Content));
     throw new InvalidOperationException("Deprecated");
 }