protected override async void SendExecute() { var user = SelectedItems.FirstOrDefault(); if (user == null) { return; } TLType type = 0; Task <MTProtoResponse <TLUpdatesBase> > task = null; if (_item is TLChannel channel) { type = TLType.ChannelsInviteToChannel; task = ProtoService.InviteToChannelAsync(channel.ToInputChannel(), new TLVector <TLInputUserBase> { user.ToInputUser() }); } else if (_item is TLChat chat) { var count = 100; var config = CacheService.GetConfig(); if (config != null) { count = config.ForwardedCountMax; } type = TLType.MessagesAddChatUser; task = ProtoService.AddChatUserAsync(chat.Id, user.ToInputUser(), count); } if (task == null) { return; } var response = await task; if (response.IsSucceeded) { NavigationService.GoBack(); if (response.Result is TLUpdates updates) { var newMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage; if (newMessage != null) { Aggregator.Publish(newMessage.Message); } var newChannelMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewChannelMessage) as TLUpdateNewChannelMessage; if (newChannelMessage != null) { Aggregator.Publish(newChannelMessage.Message); } } } else { AlertsService.ProcessError(response.Error, type, _item is TLChannel inner && inner.IsBroadcast); } }
protected override async void SendExecute() { var user = SelectedItems.FirstOrDefault(); if (user == null) { return; } Task <MTProtoResponse <TLUpdatesBase> > task = null; if (_item is TLChannel channel) { task = ProtoService.InviteToChannelAsync(channel.ToInputChannel(), new TLVector <TLInputUserBase> { user.ToInputUser() }); } else if (_item is TLChat chat) { var count = 100; var config = CacheService.GetConfig(); if (config != null) { count = config.ForwardedCountMax; } task = ProtoService.AddChatUserAsync(chat.Id, user.ToInputUser(), count); } if (task == null) { return; } var response = await task; if (response.IsSucceeded) { NavigationService.GoBack(); if (response.Result is TLUpdates updates) { var newMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage; if (newMessage != null) { Aggregator.Publish(newMessage.Message); } var newChannelMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewChannelMessage) as TLUpdateNewChannelMessage; if (newChannelMessage != null) { Aggregator.Publish(newChannelMessage.Message); } } } else { if (response.Error.TypeEquals(TLErrorType.PEER_FLOOD)) { var dialog = new TLMessageDialog(); dialog.Title = "Telegram"; dialog.Message = AppResources.PeerFloodAddContact; dialog.PrimaryButtonText = "More info"; dialog.SecondaryButtonText = "OK"; var confirm = await dialog.ShowQueuedAsync(); if (confirm == ContentDialogResult.Primary) { MessageHelper.HandleTelegramUrl("t.me/SpamBot"); } } else if (response.Error.TypeEquals(TLErrorType.USERS_TOO_MUCH)) { await TLMessageDialog.ShowAsync(AppResources.UsersTooMuch, "Telegram", "OK"); } else if (response.Error.TypeEquals(TLErrorType.BOTS_TOO_MUCH)) { await TLMessageDialog.ShowAsync(AppResources.BotsTooMuch, "Telegram", "OK"); } else if (response.Error.TypeEquals(TLErrorType.USER_NOT_MUTUAL_CONTACT)) { await TLMessageDialog.ShowAsync(AppResources.UserNotMutualContact, "Telegram", "OK"); } Execute.ShowDebugMessage("channels.inviteToChannel error " + response.Error); } }