Beispiel #1
0
        internal Conversation(ConversationState conversationState)
        {
            _synchronizationContext = Client.CurrentSynchronizationContext;

            _conversation = conversationState.conversation;
            if (_conversation.read_state.Count > 0)
                ReadState = _conversation.read_state.Last(c=>c.latest_read_timestamp > 0).latest_read_timestamp.FromUnixTime();
            if (_conversation.self_conversation_state.self_read_state != null)
                SelfReadState = _conversation.self_conversation_state.self_read_state.latest_read_timestamp.FromUnixTime();
            Participants = _conversation.participant_data.ToDictionary(c=>c.id.chat_id, c => new Participant(c));
            MessagesHistory = new ObservableCollection<Message>();

            foreach(var cse in conversationState.events.Where(c=>c.chat_message != null))
            {
                messagesIds.Add(cse.event_id, cse.timestamp);
                if (_lastMessage != null && _lastMessage.SenderId == cse.sender_id.gaia_id)
                    _lastMessage.AddContent(cse);
                else
                {
                    _lastMessage = new Message(cse);
                    MessagesHistory.Add(_lastMessage);
                }

            }
        }
        public ConversationViewModel(WTalk.Model.Conversation conversationCache, Client client)
        {
            this.Participant = conversationCache.Participants.Values.FirstOrDefault(c=>c.Id != client.CurrentUser.id.chat_id);
            this.Messages = new ObservableCollection<Message>(conversationCache.MessagesHistory);
            _lastMessage = this.Messages.LastOrDefault();
            this._conversationCache = conversationCache;            
            this._client = client;
            this._client.NewConversationEventReceived += _client_NewConversationEventReceived;


            SendMessageCommand = new RelayCommand((p) => SendMessage(p.ToString()));
            SetFocusCommand = new RelayCommand((p) => SetFocus(_conversationCache.Id));            
        }
Beispiel #3
0
        public Conversation(ConversationState conversationState)
        {
            _conversation = conversationState.conversation;            
            Participants = _conversation.participant_data.ToDictionary(c=>c.id.chat_id, c => new Participant(c));
            MessagesHistory = new List<Message>();
            Message message = null;
            foreach(var cse in conversationState.events.Where(c=>c.chat_message != null))
            {                
                if (message != null && message.SenderId == cse.sender_id.chat_id)
                    message.AppendContent(cse.chat_message);
                else 
                {
                    message = new Message(Participants[cse.sender_id.chat_id], cse.chat_message);
                    MessagesHistory.Add(message);
                }
            }

            
                        
        }
        void _client_NewConversationEventReceived(object sender, Event e)
        {
            if (e.conversation_id.id == this._conversationCache.Id)
            {
                if (_lastMessage.SenderId == e.sender_id.chat_id)
                    _lastMessage.AppendContent(e.chat_message);
                else
                {
                    _lastMessage = new Message(_conversationCache.Participants[e.sender_id.chat_id], e.chat_message);
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        Messages.Add(_lastMessage);
                    });
                }

                App.Current.Dispatcher.Invoke(() =>
                     {
                         if (AttentionRequired != null)
                             AttentionRequired(this, null);
                     });
            }
        }
Beispiel #5
0
        internal void AddOldMessages(List<Event> events)
        {
            _synchronizationContext.Post((obj) =>
            {
                IEnumerable<Event> orderedEvents = ((List<Event>)obj).OrderByDescending(c => c.timestamp);
                Message current = MessagesHistory.First();
                // hangout return all messages
                foreach (Event e in orderedEvents)
                {
                    if (messagesIds.ContainsKey(e.event_id))
                        continue;

                    messagesIds.Add(e.event_id, e.timestamp);
                    if (current.SenderId == e.sender_id.chat_id)
                        current.AddContent(e, true);
                    else
                    {
                        current = new Message(e);
                        MessagesHistory.Insert(0, current);
                    }
                }

            }, events);
        }
Beispiel #6
0
        internal void AddNewMessage(Event e)
        {
            messagesIds.Add(e.event_id, e.timestamp);
            if (_lastMessage.SenderId == e.sender_id.chat_id)
                _lastMessage.AddContent(e);
            else
            {
                _lastMessage = new Message(e);
                _synchronizationContext.Post((obj) =>
                {
                    MessagesHistory.Add(obj as Message);
                }, _lastMessage);

            }

            OnPropertyChanged("MessagesHistory");
            OnPropertyChanged("LastMessage");

            if (NewMessageReceived != null)
                NewMessageReceived(this, _lastMessage);
        }
 void Conversation_NewMessageReceived(object sender, Message e)
 {
     OnPropertyChanged("HasUnreadMessages");
 }