public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            Item = null;
            Full = null;

            var user = parameter as TLUser;
            var peer = parameter as TLPeerUser;

            if (peer != null)
            {
                user = CacheService.GetUser(peer.Id) as TLUser;
            }

            if (user != null)
            {
                Item = user;
                RaisePropertyChanged(() => IsEditEnabled);
                RaisePropertyChanged(() => AreNotificationsEnabled);
                RaisePropertyChanged(() => PhoneVisibility);
                RaisePropertyChanged(() => AddToGroupVisibility);
                RaisePropertyChanged(() => HelpVisibility);
                RaisePropertyChanged(() => ReportVisibility);
                RaisePropertyChanged(() => AddContactVisibility);

                var full = CacheService.GetFullUser(user.Id);
                if (full == null)
                {
                    var response = await ProtoService.GetFullUserAsync(user.ToInputUser());

                    if (response.IsSucceeded)
                    {
                        full = response.Result;
                    }
                }
                else
                {
                    ProtoService.GetFullUserAsync(user.ToInputUser(), null);
                }

                if (full != null)
                {
                    Full = full;
                    RaisePropertyChanged(() => IsPhoneCallsAvailable);
                    RaisePropertyChanged(() => AboutVisibility);
                    RaisePropertyChanged(() => BlockVisibility);
                    RaisePropertyChanged(() => UnblockVisibility);
                    RaisePropertyChanged(() => StopVisibility);
                    RaisePropertyChanged(() => UnstopVisibility);
                    RaisePropertyChanged(() => AddContactVisibility);
                }

                LastSeen = LastSeenConverter.GetLabel(user, true);

                Aggregator.Subscribe(this);
            }
        }
示例#2
0
        public UserPhotosViewModel(IMTProtoService protoService, TLUserFull userFull, TLUser user)
            : base(protoService, null, null)
        {
            //Items = new MvxObservableCollection<GalleryItem>();
            //Initialize(user);

            Items = new MvxObservableCollection <GalleryItem> {
                new GalleryPhotoItem(userFull.ProfilePhoto as TLPhoto, user)
            };
            SelectedItem = Items[0];
            FirstItem    = Items[0];
            //Initialize();
        }
示例#3
0
        public async System.Threading.Tasks.Task AuthAsync()
        {
            var store   = new FileSessionStore();
            var apiId   = 434408;
            var apiHash = "0bdea67547ee00f2e164a5522174d7dc";
            var client  = new TelegramClient(apiId, apiHash);
            await client.ConnectAsync();

            if (client.IsUserAuthorized() == false)
            {
                var phone = metroComboBox1.Text + metroTextBox1.Text;
                var hash  = await client.SendCodeRequestAsync(phone);

                var code = Microsoft.VisualBasic.Interaction.InputBox("Введите код полученый в СМС:");
                var user = await client.MakeAuthAsync(phone, hash, code);

                var    photo         = ((TLUserProfilePhoto)user.Photo);
                var    photoLocation = (TLFileLocation)photo.PhotoBig;
                TLFile file          = await client.GetFile(new TLInputFileLocation()
                {
                    LocalId  = photoLocation.LocalId,
                    Secret   = photoLocation.Secret,
                    VolumeId = photoLocation.VolumeId
                }, 1024 * 256);

                using (var m = new MemoryStream(file.Bytes))
                {
                    var img = Image.FromStream(m);
                    img.Save("profileimg", System.Drawing.Imaging.ImageFormat.Jpeg);
                }

                var rq = new TeleSharp.TL.Users.TLRequestGetFullUser {
                    Id = new TLInputUserSelf()
                };
                TLUserFull rUserSelf = await client.SendRequestAsync <TeleSharp.TL.TLUserFull>(rq);

                TLUser userSelf = (TLUser)rUserSelf.User;
                Properties.Settings.Default.Name = userSelf.Username;
                Properties.Settings.Default.Save();

                this.Hide();
                Main main = new Main();
                main.ShowDialog();
            }
        }
示例#4
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <TLPeerChannel, TLChannelParticipantBase>(from);
                    if (tuple.Item2 is TLChannelParticipant participant)
                    {
                        IsBannedAlready = false;

                        tuple.Item2 = new TLChannelParticipantBanned
                        {
                            UserId       = participant.UserId,
                            Date         = participant.Date,
                            BannedRights = new TLChannelBannedRights
                            {
                                IsViewMessages = true,
                                IsSendMessages = false,
                                IsSendMedia    = false,
                                IsSendStickers = false,
                                IsSendGifs     = false,
                                IsSendGames    = false,
                                IsSendInline   = false,
                                IsEmbedLinks   = false
                            }
                        };
                    }
                    else if (tuple.Item2 is TLChannelParticipantAdmin admin)
                    {
                        IsBannedAlready = false;

                        tuple.Item2 = new TLChannelParticipantBanned
                        {
                            UserId       = admin.UserId,
                            Date         = admin.Date,
                            BannedRights = new TLChannelBannedRights
                            {
                                IsViewMessages = true,
                                IsSendMessages = false,
                                IsSendMedia    = false,
                                IsSendStickers = false,
                                IsSendGifs     = false,
                                IsSendGames    = false,
                                IsSendInline   = false,
                                IsEmbedLinks   = false
                            }
                        };
                    }

                    Channel = CacheService.GetChat(tuple.Item1.ChannelId) as TLChannel;
                    Item    = tuple.Item2 as TLChannelParticipantBanned;

                    IsEmbedLinks   = _item.BannedRights.IsEmbedLinks;
                    IsSendInline   = _item.BannedRights.IsSendInline;
                    IsSendGames    = _item.BannedRights.IsSendGames;
                    IsSendGifs     = _item.BannedRights.IsSendGifs;
                    IsSendStickers = _item.BannedRights.IsSendStickers;
                    IsSendMedia    = _item.BannedRights.IsSendMedia;
                    IsSendMessages = _item.BannedRights.IsSendMessages;
                    IsViewMessages = _item.BannedRights.IsViewMessages;

                    var user = tuple.Item2.User;
                    if (user == null)
                    {
                        return;
                    }

                    var full = CacheService.GetFullUser(user.Id);
                    if (full == null)
                    {
                        var response = await ProtoService.GetFullUserAsync(user.ToInputUser());

                        if (response.IsSucceeded)
                        {
                            full = response.Result;
                        }
                    }

                    Full = full;
                }
            }
        }
示例#5
0
 public override void DeserializeResponse(BinaryReader br)
 {
     Response = (TLUserFull)ObjectUtils.DeserializeObject(br);
 }
示例#6
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <TLPeerChannel, TLChannelParticipantBase>(from);
                    if (tuple.Item2 is TLChannelParticipant participant)
                    {
                        IsAdminAlready = false;

                        tuple.Item2 = new TLChannelParticipantAdmin
                        {
                            UserId      = participant.UserId,
                            Date        = participant.Date,
                            IsCanEdit   = true,
                            AdminRights = new TLChannelAdminRights
                            {
                                IsChangeInfo     = true,
                                IsPinMessages    = true,
                                IsInviteLink     = true,
                                IsInviteUsers    = true,
                                IsBanUsers       = true,
                                IsDeleteMessages = true,
                                IsEditMessages   = true,
                                IsPostMessages   = true,
                                IsAddAdmins      = false
                            }
                        };
                    }
                    else if (tuple.Item2 is TLChannelParticipantBanned banned)
                    {
                        IsAdminAlready = false;

                        tuple.Item2 = new TLChannelParticipantAdmin
                        {
                            UserId      = banned.UserId,
                            Date        = banned.Date,
                            IsCanEdit   = true,
                            AdminRights = new TLChannelAdminRights
                            {
                                IsChangeInfo     = true,
                                IsPinMessages    = true,
                                IsInviteLink     = true,
                                IsInviteUsers    = true,
                                IsBanUsers       = true,
                                IsDeleteMessages = true,
                                IsEditMessages   = true,
                                IsPostMessages   = true,
                                IsAddAdmins      = false
                            }
                        };
                    }

                    Channel = CacheService.GetChat(tuple.Item1.ChannelId) as TLChannel;
                    Item    = tuple.Item2 as TLChannelParticipantAdmin;

                    IsAddAdmins      = _item.AdminRights.IsAddAdmins;
                    IsPinMessages    = _item.AdminRights.IsPinMessages;
                    IsInviteLink     = _item.AdminRights.IsInviteLink;
                    IsInviteUsers    = _item.AdminRights.IsInviteUsers;
                    IsBanUsers       = _item.AdminRights.IsBanUsers;
                    IsDeleteMessages = _item.AdminRights.IsDeleteMessages;
                    IsEditMessages   = _item.AdminRights.IsEditMessages;
                    IsPostMessages   = _item.AdminRights.IsPostMessages;
                    IsChangeInfo     = _item.AdminRights.IsChangeInfo;

                    var user = tuple.Item2.User;
                    if (user == null)
                    {
                        return;
                    }

                    var full = CacheService.GetFullUser(user.Id);
                    if (full == null)
                    {
                        var response = await ProtoService.GetFullUserAsync(user.ToInputUser());

                        if (response.IsSucceeded)
                        {
                            full = response.Result;
                        }
                    }

                    Full = full;
                }
            }
        }