private async Task SyncContacts(List <InputContact> contacts) { try { logger.info("Importing {0} contacts", contacts.Count); // await TelegramSession.Instance.Api.contacts_getContacts() string contactsBlobStr = ""; foreach (InputContact contact in contacts) { contactsBlobStr += ((InputPhoneContactConstructor)contact).first_name; contactsBlobStr += ((InputPhoneContactConstructor)contact).last_name; contactsBlobStr += ","; } string hash = MD5.GetMd5String(contactsBlobStr); if (hash != TelegramSession.Instance.ContactsStateMarker) { logger.debug("blob hash is outdated, importing all contacts"); await TelegramSession.Instance.Api.contacts_importContacts(contacts, true); TelegramSession.Instance.ContactsStateMarker = hash; } else { logger.debug("blob hash is up-to-date"); } // TODO: access contacts store, and get ther ids ! string hashStr = await GetUserIdsMd5InStore(); logger.debug("user hash string for ids: {0}", hashStr); contacts_Contacts serverContacts = await TelegramSession.Instance.Api.contacts_getContacts(hashStr); if (serverContacts.Constructor == Constructor.contacts_contactsNotModified) { logger.debug("Contacts not modified, finishing sync."); return; } Contacts_contactsConstructor serverContactsConstructor = (Contacts_contactsConstructor)serverContacts; foreach (MTProto.User mtuser in serverContactsConstructor.users) { TelegramSession.Instance.SaveUser(mtuser); } foreach (MTProto.Contact mtcontact in serverContactsConstructor.contacts) { ContactConstructor mtcontactConstructor = (ContactConstructor)mtcontact; UserModel user = TelegramSession.Instance.GetUser(mtcontactConstructor.user_id); await UpdateContact(user.Id.ToString(), user.FirstName, user.LastName, user.PhoneNumber); } } catch (Exception ex) { logger.error("sync contacts exception {0}", ex); } }
public override void OnResponse(BinaryReader reader) { contacts = TL.Parse <contacts_Contacts>(reader); }