/// <inheritdoc />
        public async Task <IUpdates> SendUploadedDocumentAsync(IInputPeer peer,
                                                               IInputFile document,
                                                               string mimeType,
                                                               IReadOnlyList <IDocumentAttribute> attributes,
                                                               string message,
                                                               [AllowNull] IInputFile thumb        = null,
                                                               CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestSendMedia
            {
                RandomId   = Random.NextLong(),
                Background = false,
                ClearDraft = false,
                Message    = message,
                Media      = new TInputMediaUploadedDocument
                {
                    File       = document,
                    MimeType   = mimeType,
                    Thumb      = thumb,
                    Attributes = new TVector <IDocumentAttribute>(attributes.ToArray())
                },
                Peer = peer
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
Beispiel #2
0
        public async Task <TResult> SendRequestToOtherDcAsync <TResult>(int dcId, Func <IClientApi, Task <TResult> > requestFunc, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var requestExportAuthorization = new RequestExportAuthorization
            {
                DcId = dcId
            };
            var exportedAuth = (TExportedAuthorization)await RequestSender.SendRequestAsync(requestExportAuthorization, cancellationToken).ConfigureAwait(false);


            var dc = ClientSettings.Config.DcOptions.First(d => d.Id == dcId);

            var client = await ClientCache.GetOrCreate(ClientSettings, dc.IpAddress, dc.Port).ConfigureAwait(false);

            var requestImportAuthorization = new RequestImportAuthorization
            {
                Bytes = exportedAuth.Bytes,
                Id    = exportedAuth.Id
            };

            await client.CustomRequestsService.SendRequestAsync(requestImportAuthorization, cancellationToken).ConfigureAwait(false);

            var result = await requestFunc(client).ConfigureAwait(false);

            return(result);
        }
        /// <inheritdoc />
        public async Task <IChatFull> GetFullChatAsync(int chatId, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestGetFullChat {
                ChatId = chatId
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IChats> GetChatsAsync(IReadOnlyList <int> ids, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestGetChats {
                Id = new TVector <int>(ids.ToArray())
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IMessages> GetMessagesAsync(IReadOnlyList <IInputMessage> inputMessages, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var getMessagesRequest = new RequestGetMessages
            {
                Id = new TVector <IInputMessage>(inputMessages.ToArray())
            };

            return(await RequestSender.SendRequestAsync(getMessagesRequest, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> CreateChatAsync(string title, IReadOnlyList <IInputUser> users, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestCreateChat
            {
                Title = title,
                Users = new TVector <IInputUser>(users.ToArray())
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> EditChatPhoto(int chatId, IInputChatPhoto photo, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestEditChatPhoto
            {
                ChatId = chatId,
                Photo  = photo
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IAffectedMessages> ReadHistoryAsync(IInputPeer peer, int maxId, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var readHistory = new RequestReadHistory
            {
                Peer  = peer,
                MaxId = maxId
            };

            return(await RequestSender.SendRequestAsync(readHistory, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> DeleteChatUser(int chatId, IInputUser user, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestDeleteChatUser
            {
                ChatId = chatId,
                UserId = user
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IAffectedMessages> DeleteMessagesAsync(IReadOnlyList <int> ids, bool revoke, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var deleteMessages = new RequestDeleteMessages
            {
                Id     = new TVector <int>(ids.ToArray()),
                Revoke = revoke
            };

            return(await RequestSender.SendRequestAsync(deleteMessages, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> EditChatTitle(int chatId, string title, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestEditChatTitle
            {
                ChatId = chatId,
                Title  = title
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> SendMessageAsync(IInputPeer peer, string message, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            return(await RequestSender.SendRequestAsync(
                       new RequestSendMessage
            {
                Peer = peer,
                Message = message,
                RandomId = Random.NextLong()
            },
                       cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IDialogs> GetUserDialogsAsync(int limit = 100, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var getDialogs = new RequestGetDialogs
            {
                OffsetDate = 0,
                OffsetPeer = new TInputPeerSelf(),
                Limit      = limit
            };

            return(await RequestSender.SendRequestAsync(getDialogs, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IDifference> GetUpdatesFromState(IState currentState, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var getDiffRequest = new RequestGetDifference
            {
                Pts  = currentState.Pts,
                Qts  = currentState.Qts,
                Date = currentState.Date
            };

            return(await SenderService.SendRequestAsync(getDiffRequest, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IAffectedHistory> DeleteHistoryAsync(IInputPeer peer, int maxId, bool justClear, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var deleteHistory = new RequestDeleteHistory
            {
                Peer      = peer,
                JustClear = justClear,
                MaxId     = maxId
            };

            return(await RequestSender.SendRequestAsync(deleteHistory, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IReadOnlyList <IReceivedNotifyMessage> > ReceivedMessagesAsync(int maxId, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var receivedMessages = new RequestReceivedMessages
            {
                MaxId = maxId
            };

            var result = await RequestSender.SendRequestAsync(receivedMessages, cancellationToken).ConfigureAwait(false);

            return(result);
        }
        /// <inheritdoc />
        public async Task <IMessages> GetHistoryAsync(IInputPeer peer, int offset, int maxId, int limit, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var req = new RequestGetHistory
            {
                Peer      = peer,
                AddOffset = offset,
                MaxId     = maxId,
                Limit     = limit
            };

            return(await RequestSender.SendRequestAsync(req, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> SendMediaAsync(IInputPeer peer, IInputMedia media, string message, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var sendMedia = new RequestSendMedia
            {
                RandomId   = Random.NextLong(),
                Peer       = peer,
                Media      = media,
                Message    = message,
                Background = false,
                ClearDraft = false
            };

            return(await RequestSender.SendRequestAsync(sendMedia, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> SendUploadedPhotoAsync(IInputPeer peer, IInputFile photo, string message, CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var request = new RequestSendMedia
            {
                RandomId   = Random.NextLong(),
                Background = false,
                ClearDraft = false,
                Message    = message,
                Media      = new TInputMediaUploadedPhoto
                {
                    File = photo,
                },
                Peer = peer
            };

            return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc />
        public async Task <IUpdates> ForwardMessagesAsync(IInputPeer fromPeer,
                                                          IInputPeer toPeer,
                                                          IReadOnlyList <int> ids,
                                                          bool silent,
                                                          bool withMyScore,
                                                          CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            var forwardMessages = new RequestForwardMessages
            {
                FromPeer    = fromPeer,
                ToPeer      = toPeer,
                Id          = new TVector <int>(ids.ToArray()),
                Background  = false,
                Silent      = silent,
                WithMyScore = withMyScore,
                RandomId    = new TVector <long>(Random.NextLong())
            };

            return(await RequestSender.SendRequestAsync(forwardMessages, cancellationToken));
        }
        /// <inheritdoc />
        public async Task <IState> GetCurrentStateAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            ClientSettings.EnsureUserAuthorized();

            return(await SenderService.SendRequestAsync(new RequestGetState(), cancellationToken).ConfigureAwait(false));
        }