Exemple #1
0
        public void GetEntityById(params string[] chat_ids)
        {
            GetEntityByIdRequest request = new GetEntityByIdRequest()
            {
                request_header = RequestHeaderBody,
                batch_lookup_spec = chat_ids.Select(c => new EntityLookupSpec() { gaia_id = c }).ToList(),
                field_mask = new List<FieldMask>() { FieldMask.FIELD_MASK_AVAILABLE, FieldMask.FIELD_MASK_DEVICE, FieldMask.FIELD_MASK_REACHABLE }
            };

            HttpResponseMessage message = _client.PostProtoJson(_api_key, "contacts/getentitybyid", request);
            
            if (ContactInformationReceived != null)
            {
                GetEntityByIdResponse response = message.Content.ReadAsProtoJson<GetEntityByIdResponse>();

                foreach (var contact in response.entity.Where(c=>c.id != null))
                {   
                    _contact_ids.Add(contact.id.chat_id);
                    ContactInformationReceived(this, contact);
                }

                QueryPresences();
            }
        }
Exemple #2
0
        public async Task GetEntityByIdAsync(params string[] ids)
        {
            GetEntityByIdRequest request = new GetEntityByIdRequest()
            {
                request_header = RequestHeaderBody,
                batch_lookup_spec = ids.Select(c => new EntityLookupSpec() { gaia_id = c }).ToList()
                //field_mask = new List<FieldMask>() { FieldMask.FIELD_MASK_AVAILABLE, FieldMask.FIELD_MASK_DEVICE, FieldMask.FIELD_MASK_REACHABLE }
            };

            using (HttpResponseMessage message = await _client.PostProtoJson("contacts/getentitybyid", _api_key, request))
            {


                GetEntityByIdResponse response = await message.Content.ReadAsProtoJson<GetEntityByIdResponse>();
                if (_contacts.Count == 0)
                {
                    _contacts = response.entity.Where(c => c.id != null).ToDictionary(c => c.id.gaia_id, c => new User(c));
                    if (ContactListLoaded != null)
                        ContactListLoaded(this, _contacts.Values.ToList());
                }
                else
                {

                    foreach (var contact in response.entity.Where(c => c.id != null))
                    {
                        if (_contacts.ContainsKey(contact.id.gaia_id))
                            _contacts[contact.id.gaia_id] = new User(contact);
                        else
                            _contacts.Add(contact.id.gaia_id, new User(contact));

                        if (ContactInformationReceived != null)
                            ContactInformationReceived(this, _contacts[contact.id.gaia_id]);
                    }
                }
                QueryPresencesAsync();
            }

        }