public void AddToStickers(TLMessageBase messageBase) { if (messageBase == null) { return; } var message = messageBase as TLMessage; if (message == null) { return; } var mediaDocument = message.Media as TLMessageMediaDocument; if (mediaDocument == null) { return; } var document = mediaDocument.Document as TLDocument22; if (document != null) { var inputStickerSet = document.StickerSet; if (inputStickerSet != null) { TelegramViewBase.NavigateToStickers(MTProtoService, StateService, inputStickerSet); } } }
public void Open() { var stickerSet = StickerSet as TLStickerSet32; if (stickerSet == null) { return; } TelegramViewBase.NavigateToStickers(MTProtoService, StateService, new TLInputStickerSetShortName { ShortName = stickerSet.ShortName }, () => { Items.Insert(0, stickerSet); }, () => { for (var index = 0; index < Items.Count; index++) { var item = Items[index]; if (TLString.Equals(stickerSet.ShortName, item.ShortName, StringComparison.Ordinal)) { Items.RemoveAt(index); break; } } }); }
private void OnMentionNavigated(object sender, TelegramMentionEventArgs e) { if (!string.IsNullOrEmpty(e.Mention)) { var usernameStartIndex = e.Mention.LastIndexOf("@", StringComparison.OrdinalIgnoreCase); if (usernameStartIndex != -1) { var username = e.Mention.Substring(usernameStartIndex).TrimStart('@'); if (!string.IsNullOrEmpty(username)) { TelegramViewBase.NavigateToUsername(MTProtoService, username, string.Empty); } } } else if (e.UserId >= 0) { var user = CacheService.GetUser(new TLInt(e.UserId)); if (user != null) { TelegramViewBase.NavigateToUser(user, null, PageKind.Profile); } } else if (e.ChatId >= 0) { var chat = CacheService.GetChat(new TLInt(e.ChatId)); if (chat != null) { TelegramViewBase.NavigateToChat(chat); } } else if (e.ChannelId >= 0) { var channel = CacheService.GetChat(new TLInt(e.ChatId)) as TLChannel; if (channel != null) { TelegramViewBase.NavigateToChat(channel); } } }
public void AddRemoveStickerSet(TLStickerSet32 set) { if (set == null) { return; } var messagesStickerSet = _messagesStickerSets.FirstOrDefault(x => x.Set.Id.Value == set.Id.Value); if (messagesStickerSet == null) { return; } var stickerSetExists = set.Installed && !set.Archived; var inputStickerSet = new TLInputStickerSetId { Id = set.Id, AccessHash = set.AccessHash }; if (!stickerSetExists) { MTProtoService.InstallStickerSetAsync(inputStickerSet, TLBool.False, result => Execute.BeginOnUIThread(() => { Items.Remove(set); var archivedStickers = StateService.GetArchivedStickers(); var resultArchive = result as TLStickerSetInstallResultArchive; if (resultArchive != null) { Execute.BeginOnUIThread(() => TelegramViewBase.ShowArchivedStickersMessageBox(resultArchive)); var allStickers = StateService.GetAllStickers() as TLAllStickers43; if (allStickers != null) { for (var i = 0; i < resultArchive.Sets.Count; i++) { TLUtils.RemoveStickerSet(allStickers, resultArchive.Sets[i]); } StateService.SaveAllStickersAsync(allStickers); } if (archivedStickers != null) { for (var i = resultArchive.MessagesStickerSets.Count - 1; i >= 0; i--) { TLUtils.AddStickerSetCovered(archivedStickers, resultArchive.MessagesStickerSets[i], archivedStickers.SetsCovered, resultArchive.SetsCovered[i]); for (var j = 0; j < _messagesStickerSets.Count; j++) { if (_messagesStickerSets[j].Set.Id.Value == resultArchive.MessagesStickerSets[i].Set.Id.Value) { _messagesStickerSets.RemoveAt(j); break; } } _messagesStickerSets.Insert(0, resultArchive.MessagesStickerSets[i]); } } } if (archivedStickers != null) { TLUtils.RemoveStickerSetCovered(archivedStickers, set, archivedStickers.SetsCovered); StateService.SaveArchivedStickersAsync(archivedStickers); } if (resultArchive != null) { UpdateSets(archivedStickers); } else { set.Installed = true; var set76 = set as TLStickerSet76; if (set76 != null) { set76.InstalledDate = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now); } set.NotifyOfPropertyChange(() => set.Installed); set.Archived = false; set.NotifyOfPropertyChange(() => set.Archived); } var shellViewModel = IoC.Get <ShellViewModel>(); shellViewModel.Handle(new TLUpdateNewStickerSet { Stickerset = messagesStickerSet }); MTProtoService.SetMessageOnTime(2.0, AppResources.NewStickersAdded); }), error => Execute.BeginOnUIThread(() => { if (error.CodeEquals(ErrorCode.BAD_REQUEST)) { if (error.TypeEquals(ErrorType.STICKERSET_INVALID)) { MessageBox.Show(AppResources.StickersNotFound, AppResources.Error, MessageBoxButton.OK); } else { Execute.ShowDebugMessage("messages.installStickerSet error " + error); } } else { Execute.ShowDebugMessage("messages.installStickerSet error " + error); } })); } else { MTProtoService.UninstallStickerSetAsync(inputStickerSet, result => Execute.BeginOnUIThread(() => { set.Installed = false; var set76 = set as TLStickerSet76; if (set76 != null) { set76.InstalledDate = null; } set.NotifyOfPropertyChange(() => set.Installed); set.Archived = false; set.NotifyOfPropertyChange(() => set.Archived); var shellViewModel = IoC.Get <ShellViewModel>(); shellViewModel.RemoveStickerSet(set, inputStickerSet); var eventAggregator = EventAggregator; eventAggregator.Publish(new UpdateRemoveStickerSetEventArgs(set)); MTProtoService.SetMessageOnTime(2.0, AppResources.StickersRemoved); }), error => Execute.BeginOnUIThread(() => { Execute.ShowDebugMessage("messages.uninstallStickerSet error " + error); })); } }
public void AddRemoveStickerSet(TLStickerSet32 set) { if (set == null) { return; } //var featuredStickers = _stickers as TLFeaturedStickers; if (AttachedStickers == null) { return; } var messagesStickerSet = AttachedStickers.MessagesStickerSets.FirstOrDefault(x => x.Set.Id.Value == set.Id.Value); if (messagesStickerSet == null) { return; } var stickerSetExists = set.Installed; var inputStickerSet = new TLInputStickerSetId { Id = set.Id, AccessHash = set.AccessHash }; if (!stickerSetExists) { IoC.Get <IMTProtoService>().InstallStickerSetAsync(inputStickerSet, TLBool.False, result => Execute.BeginOnUIThread(() => { var resultArchive = result as TLStickerSetInstallResultArchive; if (resultArchive != null) { TelegramViewBase.ShowArchivedStickersMessageBox(resultArchive); } set.Installed = true; var set76 = set as TLStickerSet76; if (set76 != null) { set76.InstalledDate = TLUtils.DateToUniversalTimeTLInt(IoC.Get <IMTProtoService>().ClientTicksDelta, DateTime.Now); } set.NotifyOfPropertyChange(() => set.Installed); var shellViewModel = IoC.Get <ShellViewModel>(); shellViewModel.Handle(new TLUpdateNewStickerSet { Stickerset = messagesStickerSet }); IoC.Get <IMTProtoService>().SetMessageOnTime(2.0, AppResources.NewStickersAdded); }), error => Execute.BeginOnUIThread(() => { if (error.CodeEquals(ErrorCode.BAD_REQUEST)) { if (error.TypeEquals(ErrorType.STICKERSET_INVALID)) { MessageBox.Show(AppResources.StickersNotFound, AppResources.Error, MessageBoxButton.OK); } else { Execute.ShowDebugMessage("messages.importChatInvite error " + error); } } else { Execute.ShowDebugMessage("messages.importChatInvite error " + error); } })); } else { IoC.Get <IMTProtoService>().UninstallStickerSetAsync(inputStickerSet, result => Execute.BeginOnUIThread(() => { set.Installed = false; var set76 = set as TLStickerSet76; if (set76 != null) { set76.InstalledDate = null; } set.NotifyOfPropertyChange(() => set.Installed); var shellViewModel = IoC.Get <ShellViewModel>(); if (!set.Masks) { shellViewModel.RemoveStickerSet(set, inputStickerSet); } else { shellViewModel.RemoveMaskSet(set, inputStickerSet); } var eventAggregator = IoC.Get <ITelegramEventAggregator>(); eventAggregator.Publish(new UpdateRemoveStickerSetEventArgs(set)); IoC.Get <IMTProtoService>().SetMessageOnTime(2.0, AppResources.StickersRemoved); }), error => Execute.BeginOnUIThread( () => { Execute.ShowDebugMessage("messages.uninstallStickerSet error " + error); })); } }
public void ForwardInAnimationComplete() { UpdateItems(); if (StateService.Participant != null) { var participant = StateService.Participant; StateService.Participant = null; var channel = CurrentItem as TLChannel; if (channel == null) { return; } IsWorking = true; MTProtoService.InviteToChannelAsync(channel.ToInputChannel(), new TLVector <TLInputUserBase> { participant.ToInputUser() }, result => Execute.BeginOnUIThread(() => { if (channel.ParticipantsCount != null) { channel.ParticipantsCount = new TLInt(channel.ParticipantsCount.Value + 1); } CacheService.Commit(); IsWorking = false; Items.Insert(0, participant); Status = Items.Count > 0 ? string.Empty : AppResources.NoUsersHere; }), error => Execute.BeginOnUIThread(() => { IsWorking = false; if (error.TypeEquals(ErrorType.PEER_FLOOD)) { //MessageBox.Show(AppResources.PeerFloodAddContact, AppResources.Error, MessageBoxButton.OK); ShellViewModel.ShowCustomMessageBox(AppResources.PeerFloodAddContact, AppResources.Error, AppResources.MoreInfo.ToLowerInvariant(), AppResources.Ok.ToLowerInvariant(), result => { if (result == CustomMessageBoxResult.RightButton) { TelegramViewBase.NavigateToUsername(MTProtoService, Constants.SpambotUsername, null, null, null); } }); } else if (error.TypeEquals(ErrorType.USERS_TOO_MUCH)) { MessageBox.Show(AppResources.UsersTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.USER_CHANNELS_TOO_MUCH)) { MessageBox.Show(AppResources.UserChannelsTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.BOTS_TOO_MUCH)) { MessageBox.Show(AppResources.BotsTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.USER_NOT_MUTUAL_CONTACT)) { MessageBox.Show(AppResources.UserNotMutualContact, AppResources.Error, MessageBoxButton.OK); } Execute.ShowDebugMessage("channels.inviteToChannel error " + error); })); } }
public override void Create() { if (IsWorking) { return; } if (_newChannel == null) { return; } var participants = new TLVector <TLInputUserBase>(); foreach (var item in SelectedUsers) { participants.Add(item.ToInputUser()); } participants.Add(new TLInputUser { UserId = new TLInt(StateService.CurrentUserId), AccessHash = new TLLong(0) }); if (participants.Count == 0) { MessageBox.Show(AppResources.PleaseChooseAtLeastOneParticipant, AppResources.Error, MessageBoxButton.OK); return; } _newChannel.ParticipantIds = new TLVector <TLInt> { Items = SelectedUsers.Select(x => x.Id).ToList() }; IsWorking = true; MTProtoService.InviteToChannelAsync(_newChannel.ToInputChannel(), participants, result => Execute.BeginOnUIThread(() => { IsWorking = false; StateService.With = _newChannel; StateService.RemoveBackEntries = true; NavigationService.UriFor <DialogDetailsViewModel>().Navigate(); }), error => Execute.BeginOnUIThread(() => { if (error.TypeEquals(ErrorType.PEER_FLOOD)) { //MessageBox.Show(AppResources.PeerFloodAddContact, AppResources.Error, MessageBoxButton.OK); ShellViewModel.ShowCustomMessageBox(AppResources.PeerFloodAddContact, AppResources.Error, AppResources.MoreInfo.ToLowerInvariant(), AppResources.Ok.ToLowerInvariant(), result => { if (result == CustomMessageBoxResult.RightButton) { TelegramViewBase.NavigateToUsername(MTProtoService, Constants.SpambotUsername, null, null, null); } }); } else if (error.TypeEquals(ErrorType.USERS_TOO_MUCH)) { MessageBox.Show(AppResources.UsersTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.USER_CHANNELS_TOO_MUCH)) { MessageBox.Show(AppResources.UserChannelsTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.BOTS_TOO_MUCH)) { MessageBox.Show(AppResources.BotsTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.USER_NOT_MUTUAL_CONTACT)) { MessageBox.Show(AppResources.UserNotMutualContact, AppResources.Error, MessageBoxButton.OK); } IsWorking = false; Execute.ShowDebugMessage("channels.inviteToChannel error " + error); })); }