public InterlocutorResourceViewModel(Interlocutor interlocutor) { _interlocutor = interlocutor; _summary = new InterlocutorSummaryViewModel(_interlocutor); _context = SessionModel.GetInterlocutorContext(interlocutor); SetCommands(); }
public void ShowChatWindow(Interlocutor interlocutor) { var control = HostedControls.GetControl<ChatFrameViewModel>(); EnvWindowsManager.ShowNestedWindow(control); var context = HostedControls.GetContext<ChatFrameViewModel>(); context.AttachEntity(interlocutor); }
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); } }
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) })) }); } }
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; }
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; }
public InterlocutorContext(Interlocutor interlocutor) { Interlocutor = interlocutor; Bare = XmppIdConverter.Jid(interlocutor); Resources = new ObservableCollection<IInterlocutorResource>(); _client = ModelContext.GetClientByContact(interlocutor); _connection = ConnectionManager .GetOrCreateConnection(_client) .Connection; }
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; }
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); }; }
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); }
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; }
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(); }
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); } }
protected void ShowInterlocutorChatExecuted(Interlocutor interlocutor) { _core.ShowInterlocutorChat(interlocutor); }
protected bool RemoveContactCanExecute(Interlocutor interlocutor) { return interlocutor != null && _core.ModelContext.GetClientByContact(interlocutor).State == ClientState.Connected; }
private bool CanAddInterlocutor(Interlocutor interlocutor) { return ShowOffline || interlocutor.State != ContactState.Offline; }
private void AddInterlocutor(Interlocutor interlocutor) { if (!CanAddInterlocutor(interlocutor)) return; int targetIndex = InterlocutorPosition(interlocutor); Interlocutors.Insert(targetIndex, interlocutor); }
private void UpdatePlacement(Interlocutor interlocutor) { var targetPosition = InterlocutorPosition(interlocutor); var actualPosition = Interlocutors.IndexOf(interlocutor); if (targetPosition == actualPosition) return; RemoveInterlocutor(interlocutor); AddInterlocutor(interlocutor); }
private void UnsubscribeFromChange(Interlocutor oldContact) { oldContact.PropertyChanged -= InterlocutorStateChanged; }
private void SubscribeToChange(Interlocutor newContact) { newContact.PropertyChanged += InterlocutorStateChanged; }
private void RemoveInterlocutor(Interlocutor interlocutor) { Interlocutors.Remove(interlocutor); }
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); }
protected void ShowContactLogExecuted(Interlocutor interlocutor) { var historyWindow = new HistoryWindow(interlocutor, _core.ModelContext); historyWindow.Show(); }
public Client GetClientByContact(Interlocutor interlocutor) { return _account.XmppClients.FirstOrDefault(client => client.Contacts.Contains(interlocutor)); }
protected void RemoveContactExecuted(Interlocutor interlocutor) { _core.GetClientService(interlocutor).RemoveContact(interlocutor); }
public InterlocutorResource(Interlocutor interlocutor, Jid jid) { Jid = jid; Interlocutor = interlocutor; }
protected bool SendRequestAuthorizationCanExecute(Interlocutor interlocutor) { return interlocutor != null && !interlocutor.Subscribed && _core.ModelContext.GetClientByContact(interlocutor).State == ClientState.Connected; }
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())); }
public static Jid Jid(Interlocutor interlocutor) { return new Jid(interlocutor.User, interlocutor.Server, null); }