private async Task <IUploadFile> FetchUserThumbnail(IUser user, Telegram telegramService, bool small) { var thumbnailLocation = TelegramUtils.GetUserPhotoLocation(user, small); if (thumbnailLocation == null) { return(null); } if (thumbnailLocation.DcId == telegramService.Settings.NearestDcId) { using (var clientDisposable = new Telegram.FullClientDisposable(telegramService)) { return(await FetchFileBytes(clientDisposable.Client, thumbnailLocation)); } } else { try { var telegramClient = telegramService.GetClient((int)thumbnailLocation.DcId); return(await FetchFileBytes(telegramClient, thumbnailLocation)); } catch (Exception ex) { Utils.DebugPrint("Failed to obtain client from DC manager: " + ex); return(null); } } }
private async Task <bool> CheckUsername(string username) { using (var client = new Telegram.FullClientDisposable(_service as Telegram)) { return(await client.Client.Methods.AccountCheckUsernameAsync(new AccountCheckUsernameArgs { Username = username })); } }
private async Task UpdateUsername(string username) { using (var client = new Telegram.FullClientDisposable(_service as Telegram)) { var user = await client.Client.Methods.AccountUpdateUsernameAsync(new AccountUpdateUsernameArgs { Username = username }); (_service as Telegram).Dialogs.AddUser(user); } }
private async Task SetPrivacyOptions(Telegram telegramService, IInputPrivacyKey key, IInputPrivacyRule rule) { using (var client = new Telegram.FullClientDisposable(telegramService)) { await client.Client.Methods.AccountSetPrivacyAsync(new AccountSetPrivacyArgs { Key = key, Rules = new List <IInputPrivacyRule> { rule } }); } }
private async Task UpdateUserAccount(string firstName, string lastName) { if (string.IsNullOrWhiteSpace(lastName)) { lastName = string.Empty; } using (var client = new Telegram.FullClientDisposable(_service as Telegram)) { var user = await client.Client.Methods.AccountUpdateProfileAsync(new AccountUpdateProfileArgs { Flags = 3, FirstName = firstName, LastName = lastName, }); (_service as Telegram).Dialogs.AddUser(user); } }
private async void Populate(Service service) { _progressBar.IsVisible = true; _lastSeen.IsVisible = false; _userProfile.IsVisible = false; _groups.IsVisible = false; _privacyList.IsVisible = false; var telegramService = service as Telegram; var user = telegramService.Dialogs.GetUser(telegramService.Settings.AccountId); DependencyService.Get <IPluginPageControls>().BackPressEnabled = false; //RPC call using (var client = new Telegram.FullClientDisposable(service as Telegram)) { var iStatusPrivacyRules = await client.Client.Methods.AccountGetPrivacyAsync(new AccountGetPrivacyArgs { Key = new InputPrivacyKeyStatusTimestamp() }); var statusPrivacyRules = iStatusPrivacyRules as AccountPrivacyRules; if (statusPrivacyRules != null) { var statusPrivacyRule = GetPrivacyRule(statusPrivacyRules.Rules); if (statusPrivacyRule is PrivacyValueAllowAll) { _lastSeenPicker.Title = _privacyOptionsLastSeenStrings[0]; } else if (statusPrivacyRule is PrivacyValueAllowContacts) { _lastSeenPicker.Title = _privacyOptionsLastSeenStrings[1]; } else { _lastSeenPicker.Title = _privacyOptionsLastSeenStrings[2]; } } var iChatPrivacyRules = await client.Client.Methods.AccountGetPrivacyAsync(new AccountGetPrivacyArgs { Key = new InputPrivacyKeyChatInvite() }); var chatPrivacyRules = iChatPrivacyRules as AccountPrivacyRules; if (chatPrivacyRules != null) { var chatPrivacyRule = GetPrivacyRule(chatPrivacyRules.Rules); if (chatPrivacyRule is PrivacyValueAllowAll) { _groupsPicker.Title = _privacyOptionsLastSeenStrings[0]; } else if (chatPrivacyRule is PrivacyValueAllowContacts) { _groupsPicker.Title = _privacyOptionsLastSeenStrings[1]; } } var fileBytes = (UploadFile) await FetchUserThumbnail(user, telegramService, true); if (fileBytes != null) { var thumbnail = new DisaThumbnail(telegramService, fileBytes.Bytes, "userprofile"); _userProfile.SetThumbnail(thumbnail); } else { _userProfile.SetThumbnail(null); } _userProfile.Title = TelegramUtils.GetUserName(user); _userProfile.Subtitle = TelegramUtils.GetUserHandle(user); } _progressBar.IsVisible = false; _lastSeen.IsVisible = true; _userProfile.IsVisible = true; _privacyList.IsVisible = true; _groups.IsVisible = true; _userProfile.FetchThumbnail = async() => { var fileBytes = (UploadFile) await FetchUserThumbnail(user, telegramService, false); if (fileBytes == null) { return(null); } return(new DisaThumbnail(telegramService, fileBytes.Bytes, "userprofile")); }; _userProfile.ThumbnailChanged += async(sender, e) => { using (var client = new Telegram.FullClientDisposable(telegramService)) { var resizedPhoto = Platform.GenerateJpegBytes(e, 640, 640); var inputFile = await UploadProfilePhoto(telegramService, client.Client, resizedPhoto); await SetProfilePhoto(telegramService, client.Client, inputFile); } }; _userProfile.ThumbnailRemoved += async(sender, e) => { using (var client = new Telegram.FullClientDisposable(telegramService)) { await RemoveProfilePhoto(client.Client); } }; _groupsPicker.SelectedIndexChanged += async(sender, args) => { await SendGroupPrivacyChangeUpdate(telegramService, _groupsPicker.SelectedIndex); }; _lastSeenPicker.SelectedIndexChanged += async(sender, args) => { await SendLastSeenPrivacyChangeUpdate(telegramService, _lastSeenPicker.SelectedIndex); }; DependencyService.Get <IPluginPageControls>().BackPressEnabled = true; }