Example #1
0
        public void DeletePhoto()
        {
            var channel = CurrentItem as TLChannel;

            if (channel != null)
            {
                //IsWorking = true;
                MTProtoService.EditPhotoAsync(channel, new TLInputChatPhotoEmpty(),
                                              result => { },
                                              error => Execute.BeginOnUIThread(() =>
                {
                    //IsWorking = false;
                    Execute.ShowDebugMessage("channels.editPhoto error " + error);
                }));
            }

            var chat = CurrentItem as TLChat;

            if (chat != null)
            {
                //IsWorking = true;
                MTProtoService.EditChatPhotoAsync(chat.Id, new TLInputChatPhotoEmpty(),
                                                  result => { },
                                                  error => Execute.BeginOnUIThread(() =>
                {
                    //IsWorking = false;
                    Execute.ShowDebugMessage("messages.editChatPhoto error " + error);
                }));
            }
        }
        private void ContinueUploadingPhoto(TLChannel channel)
        {
            if (_photo != null)
            {
                MTProtoService.EditPhotoAsync(channel, new TLInputChatUploadedPhoto {
                    File = _photo, Crop = new TLInputPhotoCropAuto()
                },
                                              result2 => Execute.BeginOnUIThread(() =>
                {
                    var updates2 = result2 as TLUpdates;
                    if (updates2 != null)
                    {
                        channel = updates2.Chats.FirstOrDefault() as TLChannel;
                        if (channel != null)
                        {
                            ContinueNextStep(channel);
                        }
                    }
                }),
                                              error2 => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    NotifyOfPropertyChange(() => CanCreateChannel);

                    Execute.ShowDebugMessage("channels.editPhoto error " + error2);
                }));
            }
        }
        public void DeletePhoto()
        {
            var channel = CurrentItem as TLChannel;

            if (channel != null)
            {
                //IsWorking = true;
                MTProtoService.EditPhotoAsync(channel, new TLInputChatPhotoEmpty(),
                                              statedMessage => Execute.BeginOnUIThread(() =>
                {
                    //IsWorking = false;
                    var updates = statedMessage as TLUpdates;
                    if (updates != null)
                    {
                        var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewChannelMessage) as TLUpdateNewChannelMessage;
                        if (updateNewMessage != null)
                        {
                            EventAggregator.Publish(updateNewMessage.Message);
                        }
                    }
                }),
                                              error => Execute.BeginOnUIThread(() =>
                {
                    //IsWorking = false;
                    Execute.ShowDebugMessage("channels.editPhoto error " + error);
                }));
            }

            var chat = CurrentItem as TLChat;

            if (chat != null)
            {
                //IsWorking = true;
                MTProtoService.EditChatPhotoAsync(chat.Id, new TLInputChatPhotoEmpty(),
                                                  statedMessage => Execute.BeginOnUIThread(() =>
                {
                    //IsWorking = false;
                    var updates = statedMessage as TLUpdates;
                    if (updates != null)
                    {
                        var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage;
                        if (updateNewMessage != null)
                        {
                            EventAggregator.Publish(updateNewMessage.Message);
                        }
                    }
                }),
                                                  error => Execute.BeginOnUIThread(() =>
                {
                    //IsWorking = false;
                    Execute.ShowDebugMessage("messages.editChatPhoto error " + error);
                }));
            }
        }
        public void Handle(UploadableItem item)
        {
            var userSelf = item.Owner as TLUserSelf;

            if (userSelf != null)
            {
                MTProtoService.UploadProfilePhotoAsync(
                    new TLInputFile
                {
                    Id          = item.FileId,
                    MD5Checksum = new TLString(MD5Core.GetHashString(item.Bytes).ToLowerInvariant()),
                    Name        = new TLString(Guid.NewGuid() + ".jpg"),
                    Parts       = new TLInt(item.Parts.Count)
                },
                    new TLString(""),
                    new TLInputGeoPointEmpty(),
                    new TLInputPhotoCropAuto(),
                    photosPhoto =>
                {
                    MTProtoService.GetFullUserAsync(new TLInputUserSelf(), userFull => { }, error => { });
                },
                    error =>
                {
                });
                return;
            }

            var channel = item.Owner as TLChannel;

            if (channel != null)
            {
                if (channel.Id != null)
                {
                    MTProtoService.EditPhotoAsync(
                        channel,
                        new TLInputChatUploadedPhoto
                    {
                        File = new TLInputFile
                        {
                            Id          = item.FileId,
                            MD5Checksum = new TLString(MD5Core.GetHashString(item.Bytes).ToLowerInvariant()),
                            Name        = new TLString("channelPhoto.jpg"),
                            Parts       = new TLInt(item.Parts.Count)
                        },
                        Crop = new TLInputPhotoCropAuto()
                    },
                        statedMessage =>
                    {
                        var updates = statedMessage as TLUpdates;
                        if (updates != null)
                        {
                            var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewChannelMessage) as TLUpdateNewChannelMessage;
                            if (updateNewMessage != null)
                            {
                                EventAggregator.Publish(updateNewMessage.Message);
                            }
                        }
                    },
                        error =>
                    {
                        Execute.ShowDebugMessage("messages.editChatPhoto error " + error);
                    });
                }
            }

            var chat = item.Owner as TLChat;

            if (chat != null)
            {
                MTProtoService.EditChatPhotoAsync(
                    chat.Id,
                    new TLInputChatUploadedPhoto
                {
                    File = new TLInputFile
                    {
                        Id          = item.FileId,
                        MD5Checksum = new TLString(MD5Core.GetHashString(item.Bytes).ToLowerInvariant()),
                        Name        = new TLString("chatPhoto.jpg"),
                        Parts       = new TLInt(item.Parts.Count)
                    },
                    Crop = new TLInputPhotoCropAuto()
                },
                    statedMessage =>
                {
                    var updates = statedMessage as TLUpdates;
                    if (updates != null)
                    {
                        var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage;
                        if (updateNewMessage != null)
                        {
                            EventAggregator.Publish(updateNewMessage.Message);
                        }
                    }
                },
                    error =>
                {
                    Execute.ShowDebugMessage("messages.editChatPhoto error " + error);
                });
            }
        }
Example #5
0
        public void SetPhoto()
        {
            var photo = CurrentItem as TLPhoto;

            if (photo == null)
            {
                return;
            }

            TLPhotoSize  size  = null;
            var          sizes = photo.Sizes.OfType <TLPhotoSize>();
            const double width = 800.0;

            foreach (var photoSize in sizes)
            {
                if (size == null ||
                    Math.Abs(width - size.W.Value) > Math.Abs(width - photoSize.W.Value))
                {
                    size = photoSize;
                }
            }
            if (size == null)
            {
                return;
            }

            var location = size.Location as TLFileLocation;

            if (location == null)
            {
                return;
            }

            if (_currentContact != null)
            {
                IsWorking = true;
                MTProtoService.UpdateProfilePhotoAsync(new TLInputPhoto {
                    Id = photo.Id, AccessHash = photo.AccessHash
                },
                                                       result =>
                {
                    IsWorking = false;
                    _items.Insert(0, result);
                    _currentIndex++;
                    MTProtoService.GetUserPhotosAsync(_currentContact.ToInputUser(), new TLInt(1), new TLLong(0), new TLInt(1),
                                                      photos =>
                    {
                        var previousPhoto = photos.Photos.FirstOrDefault();

                        if (previousPhoto != null)
                        {
                            _items.RemoveAt(1);
                            _items.Insert(1, previousPhoto);
                        }
                    },
                                                      error =>
                    {
                        Execute.ShowDebugMessage("photos.getUserPhotos error " + error);
                    });
                },
                                                       error =>
                {
                    IsWorking = false;
                    Execute.ShowDebugMessage("photos.updateProfilePhoto error " + error);
                });
            }
            else if (_currentChat != null)
            {
                var channel = _currentChat as TLChannel;
                if (channel != null)
                {
                    if (channel.Id != null)
                    {
                        IsWorking = true;
                        MTProtoService.EditPhotoAsync(
                            channel,
                            new TLInputChatPhoto56
                        {
                            Id = new TLInputPhoto {
                                Id = photo.Id, AccessHash = photo.AccessHash
                            }
                        },
                            result => Execute.BeginOnUIThread(() =>
                        {
                            IsWorking   = false;
                            var updates = result as TLUpdates;
                            if (updates != null)
                            {
                                var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage;
                                if (updateNewMessage != null)
                                {
                                    var serviceMessage = updateNewMessage.Message as TLMessageService;
                                    if (serviceMessage != null)
                                    {
                                        var chatEditPhotoAction = serviceMessage.Action as TLMessageActionChatEditPhoto;
                                        if (chatEditPhotoAction != null)
                                        {
                                            var newPhoto = chatEditPhotoAction.Photo as TLPhoto;
                                            if (newPhoto != null)
                                            {
                                                _items.Insert(0, newPhoto);
                                                _currentIndex++;
                                            }
                                        }
                                    }
                                }
                            }
                        }),
                            error => Execute.BeginOnUIThread(() =>
                        {
                            IsWorking = false;
                            Execute.ShowDebugMessage("messages.editChatPhoto error " + error);
                        }));
                    }
                }

                var chat = _currentChat as TLChat;
                if (chat != null)
                {
                    IsWorking = true;
                    MTProtoService.EditChatPhotoAsync(
                        chat.Id,
                        new TLInputChatPhoto56
                    {
                        Id = new TLInputPhoto {
                            Id = photo.Id, AccessHash = photo.AccessHash
                        }
                    },
                        result => Execute.BeginOnUIThread(() =>
                    {
                        IsWorking   = false;
                        var updates = result as TLUpdates;
                        if (updates != null)
                        {
                            var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage;
                            if (updateNewMessage != null)
                            {
                                var serviceMessage = updateNewMessage.Message as TLMessageService;
                                if (serviceMessage != null)
                                {
                                    var chatEditPhotoAction = serviceMessage.Action as TLMessageActionChatEditPhoto;
                                    if (chatEditPhotoAction != null)
                                    {
                                        var newPhoto = chatEditPhotoAction.Photo as TLPhoto;
                                        if (newPhoto != null)
                                        {
                                            _items.Insert(0, newPhoto);
                                            _currentIndex++;
                                        }
                                    }
                                }
                            }
                        }
                    }),
                        error => Execute.BeginOnUIThread(() =>
                    {
                        IsWorking = false;
                        Execute.ShowDebugMessage("messages.editChatPhoto error " + error);
                    }));
                }
            }
        }