示例#1
0
        public Task SetPartyPhoto(BubbleGroup group, byte[] bytes, Action <DisaThumbnail> result)
        {
            return(Task.Factory.StartNew(() =>
            {
                //MessagesEditChatPhotoAsync
                byte[] resizedImage = Platform.GenerateJpegBytes(bytes, 640, 640);
                var inputFile = UploadPartyImage(resizedImage);

                using (var client = new FullClientDisposable(this))
                {
                    if (!group.IsExtendedParty)
                    {
                        var update = TelegramUtils.RunSynchronously(
                            client.Client.Methods.MessagesEditChatPhotoAsync(new MessagesEditChatPhotoArgs
                        {
                            ChatId = uint.Parse(group.Address),
                            Photo = new InputChatUploadedPhoto
                            {
                                Crop = new InputPhotoCropAuto(),
                                File = inputFile
                            }
                        }));
                        SendToResponseDispatcher(update, client.Client);
                    }
                    else
                    {
                        //ChannelsEditPhoto
                        var update = TelegramUtils.RunSynchronously(
                            client.Client.Methods.ChannelsEditPhotoAsync(new ChannelsEditPhotoArgs
                        {
                            Channel = new InputChannel
                            {
                                ChannelId = uint.Parse(group.Address),
                                AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                            },
                            Photo = new InputChatUploadedPhoto
                            {
                                Crop = new InputPhotoCropAuto(),
                                File = inputFile
                            }
                        }));
                        SendToResponseDispatcher(update, client.Client);
                    }
                }
                byte[] disaImage = Platform.GenerateJpegBytes(bytes, 96, 96);
                var thumbnail = new DisaThumbnail(this, disaImage, GenerateRandomId().ToString());
                result(thumbnail);
            }));
        }
示例#2
0
 public void SetThumbnail(DisaThumbnail thumbnail)
 {
     Thumbnail = thumbnail == null ? null : thumbnail.Location;
 }
示例#3
0
 public void SetThumbnail(DisaThumbnail thumbnail)
 {
     Thumbnail = thumbnail == null ? null : thumbnail.Location;
 }
示例#4
0
 public override DisaThumbnail CreatePartyBitmap(Service service, string name, DisaThumbnail big, string bigName, DisaThumbnail small1, string small1Name, DisaThumbnail small2, string small2Name)
 {
     throw new NotImplementedException();
 }
示例#5
0
            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;
            }
示例#6
0
            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;
            }
示例#7
0
        public Task SetPartyPhoto(BubbleGroup group, byte[] bytes, Action<DisaThumbnail> result)
        {
            return Task.Factory.StartNew(() =>
            {
                //MessagesEditChatPhotoAsync
                byte[] resizedImage = Platform.GenerateJpegBytes(bytes, 640, 640);
                var inputFile = UploadPartyImage(resizedImage);

                using (var client = new FullClientDisposable(this))
                {
                    if (!group.IsExtendedParty)
                    {
                        var update = TelegramUtils.RunSynchronously(
                            client.Client.Methods.MessagesEditChatPhotoAsync(new MessagesEditChatPhotoArgs
                            {
                                ChatId = uint.Parse(group.Address),
                                Photo = new InputChatUploadedPhoto
                                {
                                    Crop = new InputPhotoCropAuto(),
                                    File = inputFile
                                }
                            }));
                        SendToResponseDispatcher(update, client.Client);
                    }
                    else
                    {
                        //ChannelsEditPhoto
                        var update = TelegramUtils.RunSynchronously(
                            client.Client.Methods.ChannelsEditPhotoAsync(new ChannelsEditPhotoArgs
                        {
                            Channel = new InputChannel
                            {
                                ChannelId = uint.Parse(group.Address),
                                AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                            },
                            Photo = new InputChatUploadedPhoto
                            {
                                Crop = new InputPhotoCropAuto(),
                                File = inputFile
                            }
                        }));
                        SendToResponseDispatcher(update, client.Client);
                    }
                }
                byte[] disaImage = Platform.GenerateJpegBytes(bytes, 96, 96);
                var thumbnail = new DisaThumbnail(this,disaImage,GenerateRandomId().ToString());
                result(thumbnail);
            });
        }