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 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);
                }));
            }
        }
Esempio n. 3
0
        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);
            }));
        }