Inheritance: INotifyPropertyChanged
 public InterlocutorResourceViewModel(Interlocutor interlocutor)
 {
     _interlocutor = interlocutor;
     _summary = new InterlocutorSummaryViewModel(_interlocutor);
     _context = SessionModel.GetInterlocutorContext(interlocutor);
     SetCommands();
 }
示例#2
0
 public void ShowChatWindow(Interlocutor interlocutor)
 {
     var control = HostedControls.GetControl<ChatFrameViewModel>();
     EnvWindowsManager.ShowNestedWindow(control);
     var context = HostedControls.GetContext<ChatFrameViewModel>();
     context.AttachEntity(interlocutor);
 }
示例#3
0
 public void OnRoster(RosterItem item)
 {
     var bare = item.Jid.Bare.ToLower();
     var target = GetOrDefault(bare);
     if (target == null && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         var interlocutor = new Interlocutor
         {
             Id = Guid.NewGuid(),
             Name = name,
             Server = jid.Server,
             User = jid.User,
             Subscribed = subscribed,
         };
         _client.Contacts.Add(interlocutor);
     }
     else if (target != null && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         target.Name = name;
         target.Server = jid.Server;
         target.User = jid.User;
         target.Subscribed = subscribed;
     }
     else if (target != null && item.Subscription == SubscriptionType.remove)
     {
         _client.Contacts.Remove(target);
     }
 }
示例#4
0
        public HistoryWindow(Interlocutor interlocutor, IModelContext context)
        {
            InitializeComponent();
            _context = context;
            this.DataContext = this;
            Interlocutor = interlocutor;
            var history = new MessageRepository().LoadHistory(interlocutor) ?? new History
            {
                InterlocutorId = interlocutor.Id,
                Messages = new List<Message>()
            };
            HistoryView = new ObservableCollection<HistoryView>();

            HistoryMessages = new RichTextBox(new FlowDocument());
            HistoryMessages.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            HistoryMessages.IsReadOnly = true;

            var monthGroups = history.Messages
                .OrderByDescending(note => note.Date)
                .GroupBy(key => key.Date.ToString("MMMM yyyy"));
            foreach (var monthGroup in monthGroups)
            {
                HistoryView.Add(new HistoryView
                {
                    Month = monthGroup.Key,
                    ActiveDates = new ObservableCollection<DayMessageView>(
                        monthGroup.GroupBy(key => key.Date.ToShortDateString())
                        .Select(dayGroup => new DayMessageView
                        {
                            Day = dayGroup.Key,
                            Messages = new ObservableCollection<Message>(dayGroup)
                        }))
                });
            }
        }
示例#5
0
 public UnreadMessageCounter GetCounter(Interlocutor interlocutor)
 {
     if (_counters.ContainsKey(interlocutor))
     {
         return _counters[interlocutor];
     }
     _log.WarnFormat("There is no msg counter for interlocutor {0}", interlocutor.Id);
     return null;
 }
示例#6
0
 public IInterlocutorContext GetInterlocutorContext(Interlocutor interlocutor)
 {
     if (_interlocutors.ContainsKey(interlocutor))
     {
         return _interlocutors[interlocutor];
     }
     var context = new InterlocutorContext(interlocutor);
     _interlocutors.Add(interlocutor, context);
     context.StartListen();
     return context;
 }
示例#7
0
        public InterlocutorContext(Interlocutor interlocutor)
        {
            Interlocutor = interlocutor;
            Bare = XmppIdConverter.Jid(interlocutor);
            Resources = new ObservableCollection<IInterlocutorResource>();

            _client = ModelContext.GetClientByContact(interlocutor);
            _connection = ConnectionManager
                    .GetOrCreateConnection(_client)
                    .Connection;
        }
示例#8
0
 public IInterlocutorChatSession Create(Interlocutor interlocutor)
 {
     if (_sessions.ContainsKey(interlocutor))
     {
         return _sessions[interlocutor];
     }
     var session = new InterlocutorChatSession(interlocutor);
     _sessions.Add(interlocutor, session);
     MessageFeed.Subscribe(session);
     return session;
 }
示例#9
0
 public static Predicate<IMessage> To(Interlocutor interlocutor)
 {
     return message =>
     {
         var client = AppServices.Get<IModelContext>().GetClientByContact(interlocutor);
         if (client == null) return false;
         if (message.XmppMessage.To == null) return false;
         return message.ClientId == client.Id &&
                string.Equals(message.XmppMessage.To.Bare,
                XmppIdConverter.Jid(interlocutor).Bare);
     };
 }
示例#10
0
 public void Subscribe(Interlocutor interlocutor, IContactDetailsMonitor monitor)
 {
     var jid = XmppIdConverter.Jid(interlocutor);
     if (_providers.ContainsKey(jid))
     {
         _providers[jid].Add(monitor);
         return;
     }
     var latest = _dataProvider.GetLatestInfo(jid);
     var provider = new ConactDetailsProvider(jid, latest);
     _providers[jid] = provider;
     provider.Add(monitor);
 }
示例#11
0
 public void Unsubscribe(Interlocutor interlocutor, IContactDetailsMonitor monitor)
 {
     var jid = XmppIdConverter.Jid(interlocutor);
     if (!_providers.ContainsKey(jid))
     {
         return;
     }
     var provider = _providers[jid];
     provider.Remove(monitor);
     if (provider.IsEmpty())
     {
         _providers.Remove(jid);
     }
 }
        public InterlocutorChatViewModel(Interlocutor interlocutor, IModelContext context)
        {
            Interlocutor = interlocutor;
            _context = context;
            Message = string.Empty;

            ChatTextBox = new RichTextBox(new FlowDocument());
            ChatTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            ChatTextBox.IsReadOnly = true;

            MessageTextBox = new RichTextBox(new FlowDocument());
            MessageTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

            ParseCurrentHistory();
            Interlocutor.History.CollectionChanged += HistoryChanged;
        }
示例#13
0
        public InterlocutorChatViewModel(IFrameViewModel frame, Interlocutor interlocutor)
        {
            _frame = frame;
            _interlocutor = interlocutor;

            var chatDocument = new FlowDocument();
            ChatTextBox = new RichTextBox(chatDocument);
            ChatTextBox.IsDocumentEnabled = true;
            ChatTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            ChatTextBox.Background = Brushes.Transparent;
            ChatTextBox.IsReadOnly = true;
            _conversationThread = CreateThread(chatDocument);

            MessageTextBox = new RichTextBox(new FlowDocument());
            MessageTextBox.IsDocumentEnabled = true;
            MessageTextBox.Background = Brushes.Transparent;
            MessageTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            ParseCurrentHistory();
            SetTheme(ThemeManager.ActiveTheme);
            SetCommands();
            _historyLoader = CreateHistoryLoader();
        }
示例#14
0
 public void OnRoster(RosterItem item)
 {
     var bare = item.Jid.Bare.ToLower();
     if (!_interlocutors.ContainsKey(bare) && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         var interlocutor = new Interlocutor
         {
             Id = Guid.NewGuid(),
             Name = name,
             Server = jid.Server,
             User = jid.User,
             Subscribed = subscribed,
         };
         _client.Contacts.Add(interlocutor);
     }
     else if (_interlocutors.ContainsKey(bare) && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         var interlocutor = _interlocutors[bare];
         interlocutor.Name = name;
         interlocutor.Server = jid.Server;
         interlocutor.User = jid.User;
         interlocutor.Subscribed = subscribed;
         _interlocutors.Remove(bare);
     }
     else if (_interlocutors.ContainsKey(bare) && item.Subscription == SubscriptionType.remove)
     {
         var interlocutor = _interlocutors[bare];
         _interlocutors.Remove(bare);
         _client.Contacts.Remove(interlocutor);
     }
 }
示例#15
0
 protected void ShowInterlocutorChatExecuted(Interlocutor interlocutor)
 {
     _core.ShowInterlocutorChat(interlocutor);
 }
示例#16
0
 protected bool RemoveContactCanExecute(Interlocutor interlocutor)
 {
     return interlocutor != null && _core.ModelContext.GetClientByContact(interlocutor).State == ClientState.Connected;
 }
示例#17
0
 private bool CanAddInterlocutor(Interlocutor interlocutor)
 {
     return ShowOffline || interlocutor.State != ContactState.Offline;
 }
示例#18
0
 private void AddInterlocutor(Interlocutor interlocutor)
 {
     if (!CanAddInterlocutor(interlocutor)) return;
     int targetIndex = InterlocutorPosition(interlocutor);
     Interlocutors.Insert(targetIndex, interlocutor);
 }
示例#19
0
 private void UpdatePlacement(Interlocutor interlocutor)
 {
     var targetPosition = InterlocutorPosition(interlocutor);
     var actualPosition = Interlocutors.IndexOf(interlocutor);
     if (targetPosition == actualPosition) return;
     RemoveInterlocutor(interlocutor);
     AddInterlocutor(interlocutor);
 }
示例#20
0
 private void UnsubscribeFromChange(Interlocutor oldContact)
 {
     oldContact.PropertyChanged -= InterlocutorStateChanged;
 }
示例#21
0
 private void SubscribeToChange(Interlocutor newContact)
 {
     newContact.PropertyChanged += InterlocutorStateChanged;
 }
示例#22
0
 private void RemoveInterlocutor(Interlocutor interlocutor)
 {
     Interlocutors.Remove(interlocutor);
 }
示例#23
0
 private int InterlocutorPosition(Interlocutor interlocutor)
 {
     var interlocutors = Interlocutors.AsEnumerable();
     if (!interlocutors.Contains(interlocutor))
     {
         interlocutors = interlocutors.Concat(new[] { interlocutor });
     }
     return interlocutors.OrderBy(contact => contact.State).ThenBy(contact => contact.Name).ToList().IndexOf(interlocutor);
 }
示例#24
0
 protected void ShowContactLogExecuted(Interlocutor interlocutor)
 {
     var historyWindow = new HistoryWindow(interlocutor, _core.ModelContext);
     historyWindow.Show();
 }
示例#25
0
 public Client GetClientByContact(Interlocutor interlocutor)
 {
     return _account.XmppClients.FirstOrDefault(client => client.Contacts.Contains(interlocutor));
 }
示例#26
0
 protected void RemoveContactExecuted(Interlocutor interlocutor)
 {
     _core.GetClientService(interlocutor).RemoveContact(interlocutor);
 }
示例#27
0
 public InterlocutorResource(Interlocutor interlocutor, Jid jid)
 {
     Jid = jid;
     Interlocutor = interlocutor;
 }
示例#28
0
 protected bool SendRequestAuthorizationCanExecute(Interlocutor interlocutor)
 {
     return interlocutor != null && !interlocutor.Subscribed && _core.ModelContext.GetClientByContact(interlocutor).State == ClientState.Connected;
 }
示例#29
0
 public static Predicate<IQ> To(Client _client, Interlocutor interlocutor)
 {
     return iq => (iq.From != null && iq.To != null) && (string.Equals(iq.To.Bare.ToLower(), XmppIdConverter.Jid(_client).Bare.ToLower()) &&
         string.Equals(iq.From.Bare.ToLower(), XmppIdConverter.Jid(interlocutor).Bare.ToLower()));
 }
示例#30
0
 public static Jid Jid(Interlocutor interlocutor)
 {
     return new Jid(interlocutor.User, interlocutor.Server, null);
 }