Пример #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);
                }

            }
        }
Пример #2
0
        internal Conversation(ConversationState conversationState)
        {
            _conversationState = conversationState;

            Participants = _conversationState.conversation.participant_data.ToDictionary(c => c.id.chat_id, c => new Participant(c));
            Singleton.DefaultClient.OnConversationUpdated += DefaultClient_OnConversationUpdated;
            Singleton.DefaultClient.OnNewMessageReceived  += DefaultClient_OnNewMessageReceived;
        }
Пример #3
0
 void _client_NewConversationCreated(object sender, ConversationState e)
 {
     string participantId = e.conversation.current_participant.FirstOrDefault(c => c.chat_id != CurrentUser.Id).chat_id;
     _conversationCache.Add(participantId,new ConversationWindowManager(new ConversationViewModel(new WTalk.Model.Conversation(e), _client)));
     if(!_contactDictionary.ContainsKey(participantId))
     {
         _client.GetEntityById(participantId);
         LoadConversation(participantId, false);
     }
 }
Пример #4
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);
                }
            }

            
                        
        }
Пример #5
0
        void _channel_OnDataReceived(object sender, JArray rawdata)
        {               

            //Parse channel array and call the appropriate events.
            if (rawdata[0].ToString() == "noop")
            {
              // set active client if more than 120 sec of inactivity
                if ((DateTime.UtcNow - _last_response_date).TotalSeconds > 120)
                {
                    SetActiveClient();
                    _last_response_date = DateTime.UtcNow;
                }
            }
            else if (rawdata[0]["p"] != null)
            {
                JObject wrapper = JObject.Parse(rawdata[0]["p"].ToString());
                if (wrapper["3"] != null && wrapper["3"]["2"] != null)
                {
                    _client_id = wrapper["3"]["2"].ToString();
                    _requestHeader = null;

                    _channel.SendAck(0);

                    if (_channel.Connected && !_wasConnected)
                    {
                        _wasConnected = _channel.Connected;
                        if (ConnectionEstablished != null)
                            ConnectionEstablished(this, null);
                    }
                }

                if (wrapper["2"] != null && wrapper["2"]["2"] != null)
                {
                    JArray cbu = JArray.Parse(wrapper["2"]["2"].ToString());
                    cbu.RemoveAt(0);
                    BatchUpdate batchUpdate = ProtoJsonSerializer.Deserialize<BatchUpdate>(cbu as JArray);

                    foreach(StateUpdate state_update in batchUpdate.state_update)
                    {
                        
                        if(state_update.event_notification != null)
                            if (state_update.event_notification.current_event.event_type == EventType.EVENT_TYPE_REGULAR_CHAT_MESSAGE)
                            {
                                if (_active_conversation_ids.Contains(state_update.event_notification.current_event.conversation_id.id))
                                {
                                     if (NewConversationEventReceived != null)
                                        NewConversationEventReceived(this, state_update.event_notification.current_event);
                                }                                    
                                else
                                {
                                    if(NewConversationCreated != null)
                                    {
                                        ConversationState s = new ConversationState()
                                        {
                                            conversation_id = state_update.event_notification.current_event.conversation_id,
                                            conversation = state_update.conversation,
                                            events = new List<Event>(){ state_update.event_notification.current_event}
                                        };
                                        NewConversationCreated(this, s);
                                    }
                                }
                            }

                        if (state_update.presence_notification != null)
                            foreach (var presence in state_update.presence_notification.presence)
                                PresenceInformationReceived(this, presence);
                        
                        if(state_update.self_presence_notification != null)
                            PresenceInformationReceived(this, new PresenceResult()
                            {
                                user_id = CurrentUser.id,
                                presence = new Presence()
                                {
                                    available = state_update.self_presence_notification.client_presence_state.state == ClientPresenceStateType.CLIENT_PRESENCE_STATE_DESKTOP_ACTIVE
                                }
                            });

                    }



                    this._timestamp = long.Parse(wrapper["1"]["4"].ToString());
                }

            }           

           

        }
Пример #6
0
        void _channel_OnDataReceived(object sender, JArray rawdata)
        {               

            //Parse channel array and call the appropriate events.
            if (rawdata[0].ToString() == "noop")
            {
              // set active client if more than 120 sec of inactivity
                if ((DateTime.UtcNow - _last_response_date).TotalSeconds > 120 && _client_id != null)
                {                    
                    SetActiveClientAsync();
                    _last_response_date = DateTime.UtcNow;
                }
            }
            else if (rawdata[0]["p"] != null)
            {
                JObject wrapper = JObject.Parse(rawdata[0]["p"].ToString());
                if (wrapper["3"] != null && wrapper["3"]["2"] != null)
                {
                    _client_id = wrapper["3"]["2"].ToString();
                    _requestHeader = null;

                    _channel.SendAck(0);

                    if (_channel.Connected && !_wasConnected)
                    {                        
                        _wasConnected = _channel.Connected;
                        if (ConnectionEstablished != null)
                            ConnectionEstablished(this, null);
                       
                       

                    }
                }

                if (wrapper["2"] != null && wrapper["2"]["2"] != null)
                {
                    JArray cbu = JArray.Parse(wrapper["2"]["2"].ToString());
                    cbu.RemoveAt(0);
                    BatchUpdate batchUpdate = ProtoJsonSerializer.Deserialize<BatchUpdate>(cbu as JArray);

                    foreach(StateUpdate state_update in batchUpdate.state_update)
                    {
                        
                        if(state_update.event_notification != null)
                            switch(state_update.event_notification.current_event.event_type)
                            {
                                case EventType.EVENT_TYPE_REGULAR_CHAT_MESSAGE:
                                case EventType.EVENT_TYPE_UNKNOWN:
                                     if (state_update.event_notification.current_event.conversation_id == null)
                                        break;

                                    if (_active_conversations.ContainsKey(state_update.event_notification.current_event.conversation_id.id))
                                    {
                                        _active_conversations[state_update.event_notification.current_event.conversation_id.id].AddNewMessage(state_update.event_notification.current_event);
                                        if (NewMessageReceived != null)
                                            NewMessageReceived(this, _active_conversations[state_update.event_notification.current_event.conversation_id.id]);
                                    }
                                    else
                                    {
                                        ConversationState s = new ConversationState()
                                        {
                                            conversation_id = state_update.event_notification.current_event.conversation_id,
                                            conversation = state_update.conversation,
                                            events = new List<Event>() { state_update.event_notification.current_event }
                                        };

                                        _active_conversations.Add(s.conversation_id.id, new Model.Conversation(s));
                                        if (NewConversationCreated != null)
                                            NewConversationCreated(this, _active_conversations.Last().Value);
                                    }
                                    break;
                                case EventType.EVENT_TYPE_OTR_MODIFICATION:
                                    _active_conversations[state_update.event_notification.current_event.conversation_id.id]._conversation.otr_status = state_update.event_notification.current_event.otr_status;
                                    break;
                                case EventType.EVENT_TYPE_CONVERSATION_RENAME:
                                    _active_conversations[state_update.event_notification.current_event.conversation_id.id]._conversation.name = state_update.event_notification.current_event.conversation_rename.new_name;
                                    break;                                    
                            }
                            

                        if (state_update.presence_notification != null)
                            foreach (var presence in state_update.presence_notification.presence)
                                if (_contacts.ContainsKey(presence.user_id.gaia_id))
                                    setPresence(_contacts[presence.user_id.gaia_id], presence.presence);
                                
                        
                        if(state_update.self_presence_notification != null)
                            CurrentUser.SetPresence(new Presence()
                                {
                                    available = state_update.self_presence_notification.client_presence_state.state == ClientPresenceStateType.CLIENT_PRESENCE_STATE_DESKTOP_ACTIVE
                                }
                            );

                        if(state_update.watermark_notification != null)
                        {
                            if (state_update.watermark_notification.sender_id.gaia_id == CurrentUser.Id)
                                _active_conversations[state_update.watermark_notification.conversation_id.id].SelfReadState = state_update.watermark_notification.latest_read_timestamp.FromUnixTime();
                            else
                                _active_conversations[state_update.watermark_notification.conversation_id.id].ReadState = state_update.watermark_notification.latest_read_timestamp.FromUnixTime();
                        }
                    }

                    _timestamp = long.Parse(wrapper["1"]["4"].ToString());
                }
            }    
        }