Exemple #1
0
        public async Task SyncRecentConversationsAsync()
        {
            SyncRecentConversationsRequest request = new SyncRecentConversationsRequest()
            {
                request_header = RequestHeaderBody
            };


            using (HttpResponseMessage message = await _client.PostProtoJson("conversations/syncrecentconversations", _api_key, request))
            {
                SyncRecentConversationsResponse response = await message.Content.ReadAsProtoJson <SyncRecentConversationsResponse>();

                _active_conversations = response.conversation_state.ToDictionary(c => c.conversation_id.id, c => c);


                // check if contacts are loaded
                if (_contacts == null || _contacts.Count == 0)
                {
                    string[] participants_id = response.conversation_state.SelectMany(c => c.conversation.current_participant.Select(p => p.gaia_id)).Distinct().Where(p => p != CurrentUser.id.gaia_id).ToArray();
                    await GetEntityByIdAsync(participants_id);
                }

                if (OnConversationHistoryReceived != null)
                {
                    OnConversationHistoryReceived(this, _active_conversations.Values.ToList());
                }
            }
        }
Exemple #2
0
        public void SyncRecentConversations()
        {
            SyncRecentConversationsRequest request = new SyncRecentConversationsRequest()
            {
                request_header = RequestHeaderBody
            };


            HttpResponseMessage message = _client.PostProtoJson("conversations/syncrecentconversations", request);

            if (ConversationHistoryLoaded != null)
            {
                SyncRecentConversationsResponse response = message.Content.ReadAsProtoJson <SyncRecentConversationsResponse>();
                _active_conversations = response.conversation_state.ToDictionary(c => c.conversation_id.id, c => new WTalk.Model.Conversation(c));
                ConversationHistoryLoaded(this, _active_conversations.Values.ToList());
            }
        }
Exemple #3
0
        public void SyncRecentConversations()
        {
            SyncRecentConversationsRequest request = new SyncRecentConversationsRequest()
            {
                request_header = RequestHeaderBody
            };


            HttpResponseMessage message = _client.PostProtoJson(_api_key, "conversations/syncrecentconversations", request);

            if (ConversationHistoryLoaded != null)
            {
                SyncRecentConversationsResponse response = message.Content.ReadAsProtoJson <SyncRecentConversationsResponse>();

                ConversationHistoryLoaded(this, response.conversation_state);
                _active_conversation_ids = response.conversation_state.Select(c => c.conversation_id.id).ToList();
            }
        }
Exemple #4
0
        async Task initializeChat()
        {
            // We first need to fetch the 'pvt' token, which is required for the
            // initialization request (otherwise it will return 400).
            HttpResponseMessage message = await _client.Execute(HangoutUri.PVT_TOKEN_URL, _initParams);

            string data = await message.Content.ReadAsStringAsync();

            Newtonsoft.Json.Linq.JArray array = JArray.Parse(data);

            _initParams["pvt"] = array[1].ToString();

            // Now make the actual initialization request:
            message = await _client.Execute(HangoutUri.CHAT_INIT_URL, _initParams);

            data = await message.Content.ReadAsStringAsync();

            message.Dispose();


            // Parse the response by using a regex to find all the JS objects, and
            // parsing them. Not everything will be parsable, but we don't care if
            // an object we don't need can't be parsed.

            Dictionary <string, Newtonsoft.Json.Linq.JArray> dataDictionary = Parser.ParseInitParams(data);

            // a this time we can not fix key as index can change.
            string key = null;

            foreach (JArray jarray in dataDictionary.Values)
            {
                try
                {
                    key = jarray[0][0].ToString();
                }
                catch { key = null; }

                switch (key)
                {
                case "cin:cac":
                    _api_key = jarray[0][2].ToString();
                    break;

                case "cic:vd":
                    _email = jarray[0][2].ToString();     // cic:vd
                    break;

                case "cin:acc":
                    if (jarray[0].Count() > 6)
                    {
                        _header_date    = jarray[0][4].ToString();  //cin:acc
                        _header_version = jarray[0][6].ToString();
                    }
                    break;

                case "cin:bcsc":
                    _header_id = jarray[0][7].ToString();     // cin:bcsc
                    break;

                case "cgserp":
                    jarray[0][0].Remove();
                    GetSuggestedEntitiesResponse cgserp = ProtoJsonSerializer.Deserialize <GetSuggestedEntitiesResponse>(jarray[0] as JArray);
                    if (cgserp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK)
                    {
                        _contacts = cgserp.contacts_you_hangout_with.contact.ToDictionary(c => c.entity.id.gaia_id, c => new User(c.entity));
                    }
                    break;

                case "cgsirp":
                    jarray[0][0].Remove();
                    GetSelfInfoResponse cgsirp = ProtoJsonSerializer.Deserialize <GetSelfInfoResponse>(jarray[0] as JArray);
                    if (cgsirp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK)
                    {
                        if (!string.IsNullOrEmpty(_email))
                        {
                            cgsirp.self_entity.properties.canonical_email = _email;
                        }
                        CurrentUser = new User(cgsirp.self_entity);
                    }
                    break;

                case "csrcrp":
                    jarray[0][0].Remove();
                    SyncRecentConversationsResponse csrcrp = ProtoJsonSerializer.Deserialize <SyncRecentConversationsResponse>(jarray[0] as JArray);
                    if (csrcrp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK)
                    {
                        _active_conversations = csrcrp.conversation_state.ToDictionary(c => c.conversation_id.id, c => new WTalk.Model.Conversation(c));
                    }
                    break;
                }
            }

            // call all events
            if (UserInformationReceived != null)
            {
                UserInformationReceived(this, CurrentUser);
            }


            data           = null;
            dataDictionary = null;
            //this._timestamp = double.Parse(dataDictionary["ds:21"][0][1][4].ToString());
        }