Beispiel #1
0
        //public ObservableCollection<TLUserBase> Items { get; set; }

        public EditChatViewModel(IUploadFileManager uploadManager, ICacheService cacheService,
                                 ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService,
                                 IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            _uploadManager = uploadManager;

            CurrentItem = StateService.CurrentChat;
            StateService.CurrentChat = null;
            var chat = CurrentItem as TLChat;

            if (chat != null)
            {
                Title = chat.Title.ToString();
            }
            var broadcastChat = CurrentItem as TLBroadcastChat;

            if (broadcastChat != null)
            {
                Title = broadcastChat.Title.ToString();
            }
            var channel = CurrentItem as TLChannel;

            if (channel != null)
            {
                Title = channel.Title.ToString();
                About = channel.About != null?channel.About.ToString() : string.Empty;
            }

            var channel44 = CurrentItem as TLChannel44;

            if (channel44 != null)
            {
                _signMessages = channel44.Signatures;
            }

            var channel68 = CurrentItem as TLChannel68;

            if (channel68 != null)
            {
                _hiddenPrehistory = channel68.HiddenPrehistory;
            }

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => SignMessages))
                {
                    if (channel44 == null)
                    {
                        return;
                    }

                    MTProtoService.ToggleSignaturesAsync(channel44.ToInputChannel(), new TLBool(SignMessages),
                                                         result => Execute.BeginOnUIThread(() =>
                    {
                    }),
                                                         error => Execute.BeginOnUIThread(() =>
                    {
                        Execute.ShowDebugMessage("channels.toggleComments error " + error);
                    }));
                }
                else if (Property.NameEquals(args.PropertyName, () => HiddenPrehistory))
                {
                    if (channel44 == null)
                    {
                        return;
                    }

                    MTProtoService.TogglePreHistoryHiddenAsync(channel44.ToInputChannel(), new TLBool(HiddenPrehistory),
                                                               result => Execute.BeginOnUIThread(() =>
                    {
                        MTProtoService.GetFullChannelAsync(channel44.ToInputChannel(), result2 =>
                        {
                        });
                    }),
                                                               error => Execute.BeginOnUIThread(() =>
                    {
                        Execute.ShowDebugMessage("channels.toggleComments error " + error);
                    }));
                }
            };
        }