Example #1
0
        public GroupStickersViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _channel = StateService.CurrentChat;
            var channel68 = _channel as TLChannel68;

            if (channel68 != null)
            {
                _stickerSet = channel68.StickerSet;
                _text       = _stickerSet != null && !TLString.IsNullOrEmpty(_stickerSet.ShortName)
                    ? _stickerSet.ShortName.ToString()
                    : null;

                var stickerSet32 = StickerSet as TLStickerSet32;
                if (stickerSet32 != null && stickerSet32.Stickers == null)
                {
                    MTProtoService.GetStickerSetAsync(new TLInputStickerSetShortName {
                        ShortName = stickerSet32.ShortName
                    },
                                                      result => Execute.BeginOnUIThread(() =>
                    {
                        var objects = new TLVector <TLObject>();
                        foreach (var sticker in result.Documents)
                        {
                            objects.Add(new TLStickerItem {
                                Document = sticker
                            });
                        }

                        stickerSet32.Stickers = objects;
                        stickerSet32.NotifyOfPropertyChange(() => stickerSet32.Stickers);
                    }),
                                                      error =>
                    {
                    });
                }
            }
            StateService.CurrentChat = null;

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => Text))
                {
                    if (string.IsNullOrEmpty(Text))
                    {
                        Remove(false);
                    }
                    else if (StickerSet is TLStickerSet32 && string.Equals(StickerSet.ShortName.ToString(), Text))
                    {
                    }
                    else if (Text.Contains("/addstickers"))
                    {
                        var shortNameStartIndex = Text.TrimEnd('/').LastIndexOf("/", StringComparison.OrdinalIgnoreCase);
                        if (shortNameStartIndex != -1)
                        {
                            var shortName = Text.Substring(shortNameStartIndex).Replace("/", string.Empty);

                            if (!string.IsNullOrEmpty(shortName))
                            {
                                Text = shortName;
                                var view = GetView() as GroupStickersView;
                                if (view != null)
                                {
                                    view.MoveCursorToEnd();
                                }
                            }
                        }
                    }
                    else
                    {
                        var text = Text;
                        Execute.BeginOnUIThread(TimeSpan.FromSeconds(0.5), () =>
                        {
                            if (string.Equals(text, Text))
                            {
                                SearchStickerSet(text);
                            }
                        });
                    }
                }
            };
        }
        public AddChatParticipantViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            if (StateService.CurrentRole != null)
            {
                _currentRole             = StateService.CurrentRole;
                StateService.CurrentRole = null;
            }

            if (StateService.CurrentChat != null)
            {
                _currentChat             = StateService.CurrentChat;
                StateService.CurrentChat = null;
            }

            if (StateService.RemovedUsers != null)
            {
                foreach (var user in StateService.RemovedUsers)
                {
                    _removedUsers[user.Index] = user;
                }
                StateService.RemovedUsers = null;
            }

            if (StateService.RequestForwardingCount)
            {
                _requestForwardingCount             = true;
                StateService.RequestForwardingCount = false;
            }

            _inviteVisibility            = StateService.IsInviteVisible ? Visibility.Visible : Visibility.Collapsed;
            StateService.IsInviteVisible = false;

            BeginOnThreadPool(() =>
            {
                var isAuthorized = SettingsHelper.GetValue <bool>(Constants.IsAuthorizedKey);
                if (isAuthorized)
                {
                    var contacts = CacheService.GetContacts();
                    Status       = string.Empty;
                    Items.Clear();
                    foreach (var contact in contacts.OrderBy(x => x.FullName))
                    {
                        if (!(contact is TLUserEmpty) && contact.Index != StateService.CurrentUserId && !_removedUsers.ContainsKey(contact.Index))
                        {
                            Items.Add(contact);
                        }
                    }
                }

                BeginOnUIThread(() =>
                {
                    if (StateService.RemoveBackEntry)
                    {
                        NavigationService.RemoveBackEntry();
                        StateService.RemoveBackEntry = false;
                    }
                });
            });
        }
 public SettingsLanguageViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
     Items = new MvxObservableCollection <TLLangPackLanguage>();
 }
Example #4
0
 public SettingsAccountsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
     Items = new ObservableCollection <string>();
 }
        public ChangePasswordHintViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            var password = PasswordViewModel.TempNewPassword;

            if (!string.IsNullOrEmpty(password) && password.Length > 2)
            {
                PasswordHint = string.Format("{0}{1}{2}",
                                             password[0],
                                             new string('*', password.Length - 2),
                                             password[password.Length - 1]);
            }
        }
        public AddSecretChatParticipantViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            BeginOnThreadPool(() =>
            {
                var isAuthorized = SettingsHelper.GetValue <bool>(Constants.IsAuthorizedKey);
                if (isAuthorized)
                {
                    var contacts = CacheService.GetContacts()
                                   .Where(x => !(x is TLUserEmpty) && x.Index != StateService.CurrentUserId)
                                   .OrderBy(x => x.FullName)
                                   .ToList();

                    Status = string.Empty;

                    var count = 0;
                    const int firstSliceCount = 10;
                    var secondSlice           = new List <TLUserBase>();
                    foreach (var contact in contacts)
                    {
                        if (count < firstSliceCount)
                        {
                            LazyItems.Add(contact);
                        }
                        else
                        {
                            secondSlice.Add(contact);
                        }
                        count++;
                    }

                    BeginOnUIThread(() => PopulateItems(() =>
                    {
                        foreach (var item in secondSlice)
                        {
                            Items.Add(item);
                        }
                    }));
                }

                GetDHConfig();
            });
        }
Example #7
0
 public SettingsSessionsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
     _cachedItems = new Dictionary <long, TLAuthorization>();
     Items        = new SortedObservableCollection <TLAuthorization>(new TLAuthorizationComparer());
 }
        public EditCurrentUserViewModel(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 = CacheService.GetUser(new TLInt(StateService.CurrentUserId));

            FirstName = ((TLUserBase)CurrentItem).FirstName.Value;
            LastName  = ((TLUserBase)CurrentItem).LastName.Value;
        }
 public PaymentFormStep3ViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
 }
Example #10
0
 public GalleryViewModelBase(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
 }
 public PerformanceViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
     : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
 {
     DisplayName = "performance";
 }
 public EditPhoneNumberViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
 {
     if (StateService.CurrentContact != null)
     {
         CurrentItem = StateService.CurrentContact;
         StateService.CurrentContact = null;
     }
 }
Example #13
0
 public EnterPasscodeViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
     : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
 {
     PropertyChanged += (sender, args) =>
     {
         if (Property.NameEquals(args.PropertyName, () => Passcode))
         {
             if (PasscodeUtils.IsEnabled && PasscodeUtils.IsSimple)
             {
                 Done();
             }
         }
     };
 }
        public ProxyListViewModel(IProxyChecker proxyChecker, ITransportService transportService, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            SuppressSharing = StateService.SuppressProxySharing;
            StateService.SuppressProxySharing = false;

            _proxyChecker     = proxyChecker;
            _transportService = transportService;

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => IsEnabled))
                {
                    var proxy = _proxyConfig.GetProxy();
                    _proxyConfig.IsEnabled = new TLBool(IsEnabled);
                    if (proxy != null)
                    {
                        proxy.NotifyOfPropertyChange(() => proxy.Self);
                    }
                    SetReconnect(!_proxyConfig.IsEmpty, _proxyConfig, null);
                }
                else if (Property.NameEquals(args.PropertyName, () => UseForCalls))
                {
                    var proxy = _proxyConfig.GetProxy();
                    _proxyConfig.UseForCalls = new TLBool(UseForCalls);
                    if (proxy != null)
                    {
                        proxy.NotifyOfPropertyChange(() => proxy.Self);
                    }
                    SetReconnect(false, _proxyConfig, null);
                }
            };
        }
 public SearchDialogsViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
     : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
 {
     Items       = new ObservableCollection <TLObject>();
     DisplayName = LowercaseConverter.Convert(AppResources.Conversations);
 }
 public ChannelParticipantsViewModelBase(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, TLChannelParticipantsFilterBase filter, Func <string, TLChannelParticipantsFilterBase> search)
     : base(protoService, cacheService, aggregator)
 {
     _filter = filter;
     _search = search;
 }
        public static void CreateSecretChatCommon(TLUserBase user, TLDHConfig dhConfig, IMTProtoService mtProtoService, ICacheService cacheService, INavigationService navigationService, IStateService stateService, ITelegramEventAggregator eventAggregator)
        {
            if (user == null)
            {
                return;
            }

            var random   = new Random();
            var randomId = random.Next();

            mtProtoService.RequestEncryptionAsync(user.ToInputUser(), new TLInt(randomId), dhConfig.GA,
                                                  encryptedChat =>
            {
                var chatWaiting = encryptedChat as TLEncryptedChatWaiting;

                if (chatWaiting != null)
                {
                    var action   = new TLMessageActionChatCreate();
                    action.Title = TLString.Empty;
                    action.Users = new TLVector <TLInt> {
                        Items = new List <TLInt> {
                            user.Id
                        }
                    };

                    var dialog             = new TLDialog53();
                    dialog.Flags           = new TLInt(0);
                    dialog.ReadOutboxMaxId = new TLInt(0);
                    dialog.ReadInboxMaxId  = new TLInt(0);
                    dialog.With            = user;
                    dialog.Peer            = new TLPeerUser {
                        Id = user.Id
                    };

                    var topMessage    = new TLMessageService17();
                    topMessage.Date   = chatWaiting.Date;
                    topMessage.FromId = chatWaiting.AdminId;
                    topMessage.ToId   = new TLPeerUser {
                        Id = user.Id
                    };
                    topMessage.Out    = new TLBool(true);
                    topMessage.Action = action;
                    topMessage.SetUnread(new TLBool(false));

                    chatWaiting.A = dhConfig.A;
                    chatWaiting.P = dhConfig.P;
                    chatWaiting.G = dhConfig.G;
                }

                stateService.RemoveBackEntry = true;
                stateService.With            = chatWaiting;
                stateService.Participant     = user;

                Execute.BeginOnUIThread(() =>
                {
                    stateService.AnimateTitle = true;
                    navigationService.UriFor <SecretDialogDetailsViewModel>().Navigate();
                });


                //syncing chat and message
                cacheService.SyncEncryptedChat(chatWaiting, eventAggregator.Publish);

                var message = new TLDecryptedMessageService17
                {
                    RandomId = TLLong.Random(),
                    //RandomBytes = TLString.Random(Telegram.Api.Constants.MinRandomBytesLength),
                    ChatId = chatWaiting.Id,
                    Action = new TLDecryptedMessageActionEmpty(),
                    FromId = new TLInt(stateService.CurrentUserId),
                    Date   = chatWaiting.Date,
                    Out    = new TLBool(false),
                    Unread = new TLBool(false),
                    Status = MessageStatus.Read
                };

                cacheService.SyncDecryptedMessage(message, chatWaiting, result => { });
            },
                                                  error =>
            {
                Execute.ShowDebugMessage("messages.requestEncryption error " + error);
            });
        }
        public ChannelMembersViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            CurrentItem = StateService.CurrentChat;
            StateService.CurrentChat = null;

            Items = new ObservableCollection <TLUserBase>();

            Status = AppResources.Loading;
        }
Example #19
0
        public EditContactViewModel(IFileManager fileManager, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            _fileManager = fileManager;

            CurrentItem = StateService.CurrentContact;
            StateService.CurrentContact = null;
            var contact = CurrentItem as TLUserBase;

            if (contact != null)
            {
                if (contact.ExtendedInfo != null)
                {
                    FirstName = contact.ExtendedInfo.FirstName.ToString();
                    LastName  = contact.ExtendedInfo.LastName.ToString();
                }
                else
                {
                    FirstName = contact.FirstName.ToString();
                    LastName  = contact.LastName.ToString();
                }
            }
        }
Example #20
0
 public SettingsBlockUserViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
 }
        public CreateChannelStep1ViewModel(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;

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => Title))
                {
                    NotifyOfPropertyChange(() => PlaceholderText);
                    NotifyOfPropertyChange(() => CanCreateChannel);
                }
            };
        }
        public PhotoPickerViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _settings = StateService.GetPhotoPickerSettings();

            MainRules = new List <TLPrivacyRuleBase>
            {
                new TLPrivacyValueAllowAll {
                    Label = AppResources.InAppPhotoPicker
                },
                new TLPrivacyValueAllowContacts {
                    Label = AppResources.ExternalPhotoPicker
                }
            };

            _selectedMainRule           = _settings.External ? MainRules[1] : MainRules[0];
            _selectedMainRule.IsChecked = true;

            PropertyChanged += OnPropertyChanged;
        }
        public static void SendEncryptedMediaInternal(TLEncryptedChat chat, TLObject obj, IMTProtoService mtProtoService, ICacheService cacheService)
        {
            Execute.BeginOnUIThread(() =>
            {
                var message = GetDecryptedMessage(obj);
                if (message == null)
                {
                    return;
                }

                var message17      = message as TLDecryptedMessage17;
                var messageLayer17 = obj as TLDecryptedMessageLayer17;
                var chat17         = chat as TLEncryptedChat17;
                if (chat17 != null &&
                    messageLayer17 != null &&
                    message17 != null &&
                    message17.InSeqNo.Value == -1 &&
                    message17.OutSeqNo.Value == -1)
                {
                    var inSeqNo  = TLUtils.GetInSeqNo(mtProtoService.CurrentUserId, chat17);
                    var outSeqNo = TLUtils.GetOutSeqNo(mtProtoService.CurrentUserId, chat17);

                    message17.InSeqNo  = inSeqNo;
                    message17.OutSeqNo = outSeqNo;
                    message17.NotifyOfPropertyChange(() => message17.InSeqNo);
                    message17.NotifyOfPropertyChange(() => message17.OutSeqNo);

                    messageLayer17.InSeqNo  = inSeqNo;
                    messageLayer17.OutSeqNo = outSeqNo;

                    chat17.RawOutSeqNo = new TLInt(chat17.RawOutSeqNo.Value + 1);
                }

                //message.Media.UploadingProgress = 0.0;
                mtProtoService.SendEncryptedFileAsync(
                    new TLInputEncryptedChat {
                    AccessHash = chat.AccessHash, ChatId = chat.Id
                },
                    message.RandomId,
                    TLUtils.EncryptMessage(obj, chat),
                    message.InputFile,
                    result =>
                {
                    message.Status = MessageStatus.Confirmed;
                    message.NotifyOfPropertyChange(() => message.Status);

                    var media = message.Media;
                    if (media != null)
                    {
                        var oldFile = media.File as TLEncryptedFile;

                        media.File = result.EncryptedFile;
                        if (oldFile != null)
                        {
                            var newFile = media.File as TLEncryptedFile;
                            if (newFile != null)
                            {
                                newFile.FileName = oldFile.FileName;
                                newFile.Duration = oldFile.Duration;

                                var mediaPhoto = media as TLDecryptedMessageMediaPhoto;
                                if (mediaPhoto != null)
                                {
                                    var sourceFileName = String.Format("{0}_{1}_{2}.jpg",
                                                                       oldFile.Id,
                                                                       oldFile.DCId,
                                                                       oldFile.AccessHash);

                                    var destinationFileName = String.Format("{0}_{1}_{2}.jpg",
                                                                            newFile.Id,
                                                                            newFile.DCId,
                                                                            newFile.AccessHash);

                                    try
                                    {
                                        using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                                        {
                                            if (store.FileExists(sourceFileName))
                                            {
                                                store.CopyFile(sourceFileName, destinationFileName);
                                                store.DeleteFile(sourceFileName);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                            }
                        }
                    }

                    cacheService.SyncSendingDecryptedMessage(chat.Id, result.Date, message.RandomId, m => { });
                },
                    () =>
                {
                    message.Status = MessageStatus.Confirmed;
                    message.NotifyOfPropertyChange(() => message.Status);
                },
                    error =>
                {
                    message.Status = MessageStatus.Failed;
                    message.NotifyOfPropertyChange(() => message.Status);

                    Execute.ShowDebugMessage("messages.sendEncryptedFile error " + error);
                });
            });
        }
Example #24
0
 public CreateChannelStep2ViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
     AdminedPublicChannels = new MvxObservableCollection <TLChannel>();
     PropertyChanged      += OnPropertyChanged;
 }
Example #25
0
 public ChannelCreateStep3ViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
 }
Example #26
0
 public MediaCollection(IMTProtoService protoService, TLInputPeerBase peer, TLMessagesFilterBase filter)
 {
     _protoService = protoService;
     _peer         = peer;
     _filter       = filter;
 }
Example #27
0
 public ChannelAdminLogViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
 }
 public SignInSentCodeViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
 }
Example #29
0
 public ChatInviteLinkViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator)
     : base(protoService, cacheService, aggregator)
 {
 }
        public EnterPasswordViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _authorizationForm             = stateService.AuthorizationForm;
            stateService.AuthorizationForm = null;

            _secureValues             = stateService.SecureValues;
            stateService.SecureValues = null;

            if (_authorizationForm != null)
            {
                Bot = _authorizationForm.Users.LastOrDefault();
            }
            else
            {
                Bot = CacheService.GetUser(new TLInt(StateService.CurrentUserId));
            }
        }