public ChatSessionViewModel(AccountViewModel account, JIDViewModel target) { this.account = account; this.target = target; this.WhenAny(x => x.account, x => x.Value).Subscribe(x => raisePropertyChanged("CanSendMessage")); }
private void OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item) { Execute.BeginOnUIThread ( new System.Action ( () => { //Create the new JIDViewModel JIDViewModel jidvm = new JIDViewModel(item.Jid, this); //Add it to each group. Create the group when needed agsXMPP.Xml.Dom.ElementList list = item.GetGroups(); foreach (agsXMPP.Xml.Dom.Element element in list) { agsXMPP.protocol.Base.Group group = element as agsXMPP.protocol.Base.Group; RosterGroupViewModel rosterGroupVM = this.groups.SingleOrDefault(x => x.GroupName == group.Name); if (rosterGroupVM == null) { rosterGroupVM = new RosterGroupViewModel(group, this); this.groups.Add(rosterGroupVM); //Shitty, but this is the only way to re-order an observable collection groups = new ObservableCollection<RosterGroupViewModel>(groups.OrderBy(x => x.GroupName)); NotifyOfPropertyChange(() => Groups); } rosterGroupVM.Members.Add(jidvm); } //Add to our friends friends.Add(jidvm); } ) ); }
public void TryStartNewChatSession(KeyEventArgs eventArgs, JIDViewModel target) { if (eventArgs.IsDown && eventArgs.Key == Key.Enter) StartNewChatSession(target); }
private void OnMessage(object sender, agsXMPP.protocol.client.Message msg) { lock (chatSessionsMutext) { //Do we have a chat session with the sender of this message? ChatSessionViewModel chatSession = chatSessions.SingleOrDefault(x => x.Target.Bare == msg.From.Bare); if (chatSession == null) { JIDViewModel friend = friends.SingleOrDefault(x => x.Bare == msg.From.Bare); if (friend == null) { friend = new JIDViewModel(msg.From, this); friends.Add(friend); //No way to get groups here. :\ } //Nope. Create a new one. chatSession = new ChatSessionViewModel(this, friend); chatSessions.Add(chatSession); NotifyChatSessionStarted(chatSession); } if (!String.IsNullOrEmpty(msg.Body)) { ChatMessage newMsg = new ChatMessage() { To = msg.To, From = msg.From, Date = GetTimestamp(msg), Message = msg.Body, MessageType = msg.Type }; //Add the message. chatSession.OnMessage(newMsg); NotifyChatChatMessage(chatSession, newMsg); } else chatSession.OnChatState(msg.Chatstate); } }
/// <summary> /// Open up a new chat session with the target /// </summary> /// <param name="target"></param> public void StartNewChatSession(JIDViewModel target) { if (connectionState != XmppConnectionState.SessionStarted) return; lock (chatSessionsMutext) { //Do we already have a chat session open with this target? ChatSessionViewModel chatSession = chatSessions.SingleOrDefault(x => x.Target == target); if (chatSession == null) { //Create and add. chatSession = new ChatSessionViewModel(this, target); chatSessions.Add(chatSession); } //Always notify NotifyChatSessionInitiatedByUser(chatSession); } }