void IntroCode::onSubmitCode(bool force) { if (!force && (code.text() == sentCode || !code.isEnabled())) return; code.setDisabled(true); setFocus(); showError(""); checkRequest.start(1000); sentCode = code.text(); sentRequest = MTP::send(MTPauth_SignIn(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(sentCode)), rpcDone(&IntroCode::codeSubmitDone), rpcFail(&IntroCode::codeSubmitFail)); }
void IntroPhone::phoneCheckDone(const MTPauth_CheckedPhone &result) { stopCheck(); const MTPDauth_checkedPhone &d(result.c_auth_checkedPhone()); if (mtpIsTrue(d.vphone_registered)) { disableAll(); showError(""); checkRequest.start(1000); sentRequest = MTP::send(MTPauth_SendCode(MTP_string(sentPhone), MTP_int(5), MTP_int(ApiId), MTP_string(ApiHash), MTP_string(Sandbox::LangSystemISO())), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); } else { showError(lang(lng_bad_phone_noreg), true); enableAll(true); } }
void FileUploader::sendNext() { if (sentSize >= MaxUploadFileParallelSize || _paused.msg) return; bool killing = killSessionsTimer.isActive(); if (queue.isEmpty()) { if (!killing) { killSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout); } return; } if (killing) { killSessionsTimer.stop(); } Queue::iterator i = uploading.msg ? queue.find(uploading) : queue.begin(); if (!uploading.msg) { uploading = i.key(); } else if (i == queue.end()) { i = queue.begin(); uploading = i.key(); } int todc = 0; for (int dc = 1; dc < MTPUploadSessionsCount; ++dc) { if (sentSizes[dc] < sentSizes[todc]) { todc = dc; } } UploadFileParts &parts(i->file ? (i->type() == PreparePhoto ? i->file->fileparts : i->file->thumbparts) : i->media.parts); uint64 partsOfId(i->file ? (i->type() == PreparePhoto ? i->file->id : i->file->thumbId) : i->media.thumbId); if (parts.isEmpty()) { if (i->docSentParts >= i->docPartsCount) { if (requestsSent.isEmpty() && docRequestsSent.isEmpty()) { if (i->type() == PreparePhoto) { emit photoReady(uploading, MTP_inputFile(MTP_long(i->id()), MTP_int(i->partsCount), MTP_string(i->filename()), MTP_string(i->file ? i->file->filemd5 : i->media.jpeg_md5))); } else if (i->type() == PrepareDocument) { QByteArray docMd5(32, Qt::Uninitialized); hashMd5Hex(i->md5Hash.result(), docMd5.data()); MTPInputFile doc = (i->docSize > UseBigFilesFrom) ? MTP_inputFileBig(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename())) : MTP_inputFile(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename()), MTP_string(docMd5)); if (i->partsCount) { emit thumbDocumentReady(uploading, doc, MTP_inputFile(MTP_long(i->thumbId()), MTP_int(i->partsCount), MTP_string(i->file ? i->file->thumbname : (qsl("thumb.") + i->media.thumbExt)), MTP_string(i->file ? i->file->thumbmd5 : i->media.jpeg_md5))); } else { emit documentReady(uploading, doc); } } else if (i->type() == PrepareAudio) { QByteArray audioMd5(32, Qt::Uninitialized); hashMd5Hex(i->md5Hash.result(), audioMd5.data()); MTPInputFile audio = (i->docSize > UseBigFilesFrom) ? MTP_inputFileBig(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename())) : MTP_inputFile(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename()), MTP_string(audioMd5)); emit audioReady(uploading, audio); } queue.remove(uploading); uploading = FullMsgId(); sendNext(); } return; } QByteArray &content(i->file ? i->file->content : i->media.data); QByteArray toSend; if (content.isEmpty()) { if (!i->docFile) { i->docFile.reset(new QFile(i->file ? i->file->filepath : i->media.file)); if (!i->docFile->open(QIODevice::ReadOnly)) { currentFailed(); return; } } toSend = i->docFile->read(i->docPartSize); if (i->docSize <= UseBigFilesFrom) { i->md5Hash.feed(toSend.constData(), toSend.size()); } } else { toSend = content.mid(i->docSentParts * i->docPartSize, i->docPartSize); if ((i->type() == PrepareDocument || i->type() == PrepareAudio) && i->docSentParts <= UseBigFilesFrom) { i->md5Hash.feed(toSend.constData(), toSend.size()); } } if (toSend.size() > i->docPartSize || (toSend.size() < i->docPartSize && i->docSentParts + 1 != i->docPartsCount)) { currentFailed(); return; } mtpRequestId requestId; if (i->docSize > UseBigFilesFrom) { requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); } else { requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); } docRequestsSent.insert(requestId, i->docSentParts); dcMap.insert(requestId, todc); sentSize += i->docPartSize; sentSizes[todc] += i->docPartSize; i->docSentParts++; } else { UploadFileParts::iterator part = parts.begin(); mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(partsOfId), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); requestsSent.insert(requestId, part.value()); dcMap.insert(requestId, todc); sentSize += part.value().size(); sentSizes[todc] += part.value().size(); parts.erase(part); } nextTimer.start(UploadRequestInterval); }
void StickerSetInner::install() { if (_installRequest) return; _installRequest = MTP::send(MTPmessages_InstallStickerSet(_input, MTP_bool(false)), rpcDone(&StickerSetInner::installDone), rpcFail(&StickerSetInner::installFailed)); }
void Application::photoUpdated(MsgId msgId, const MTPInputFile &file) { if (!App::self()) return; QMap<MsgId, PeerId>::iterator i = photoUpdates.find(msgId); if (i != photoUpdates.end()) { PeerId peer = i.value(); if (peer == App::self()->id) { MTP::send(MTPphotos_UploadProfilePhoto(file, MTP_string(""), MTP_inputGeoPointEmpty(), MTP_inputPhotoCrop(MTP_double(0), MTP_double(0), MTP_double(100))), rpcDone(&Application::selfPhotoDone), rpcFail(&Application::peerPhotoFail, peer)); } else { History *hist = App::history(peer); hist->sendRequestId = MTP::send(MTPmessages_EditChatPhoto(MTP_int(peer & 0xFFFFFFFF), MTP_inputChatUploadedPhoto(file, MTP_inputPhotoCrop(MTP_double(0), MTP_double(0), MTP_double(100)))), rpcDone(&Application::chatPhotoDone, peer), rpcFail(&Application::peerPhotoFail, peer), 0, 0, hist->sendRequestId); } } }
void ApiWrap::requestPeer(PeerData *peer) { if (!peer || _fullPeerRequests.contains(peer) || _peerRequests.contains(peer)) return; mtpRequestId req; if (peer->chat) { req = MTP::send(MTPmessages_GetChats(MTP_vector<MTPint>(1, MTP_int(App::chatFromPeer(peer->id)))), rpcDone(&ApiWrap::gotChat, peer), rpcFail(&ApiWrap::gotPeerFailed, peer)); } else { req = MTP::send(MTPusers_GetUsers(MTP_vector<MTPInputUser>(1, peer->asUser()->inputUser)), rpcDone(&ApiWrap::gotUser, peer), rpcFail(&ApiWrap::gotPeerFailed, peer)); } _peerRequests.insert(peer, req); }
void UsernameBox::onSave() { if (_saveRequestId) return; _sentUsername = getName(); _saveRequestId = MTP::send(MTPaccount_UpdateUsername(MTP_string(_sentUsername)), rpcDone(&UsernameBox::onUpdateDone), rpcFail(&UsernameBox::onUpdateFail)); }
void PhoneWidget::phoneCheckDone(const MTPauth_CheckedPhone &result) { stopCheck(); auto &d = result.c_auth_checkedPhone(); if (mtpIsTrue(d.vphone_registered)) { hidePhoneError(); _checkRequest->start(1000); _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(0), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&PhoneWidget::phoneSubmitDone), rpcFail(&PhoneWidget::phoneSubmitFail)); } else { showSignup(); _sentRequest = 0; } }
void PhoneWidget::toSignUp() { hideError(); // Hide error, but leave the signup label visible. _checkRequest->start(1000); _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(0), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&PhoneWidget::phoneSubmitDone), rpcFail(&PhoneWidget::phoneSubmitFail)); }
void mtpLogoutOtherDCs() { QList<int32> dcs; { QMutexLocker lock(&_keysMapForWriteMutex); dcs = _keysMapForWrite.keys(); } for (int32 i = 0, cnt = dcs.size(); i != cnt; ++i) { if (dcs[i] != MTP::maindc()) { logoutGuestMap.insert(MTP::lgt + dcs[i], MTP::send(MTPauth_LogOut(), rpcDone(&logoutDone), rpcFail(&logoutDone), MTP::lgt + dcs[i])); } } }
void PhoneWidget::submit() { if (_sentRequest || isHidden()) return; if (!App::isValidPhone(fullNumber())) { showPhoneError(langFactory(lng_bad_phone)); _phone->setFocus(); return; } hidePhoneError(); _checkRequest->start(1000); _sentPhone = fullNumber(); _sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(_sentPhone)), rpcDone(&PhoneWidget::phoneCheckDone), rpcFail(&PhoneWidget::phoneSubmitFail)); }
bool mtpFileLoader::loadPart() { if (complete || lastComplete || (!requests.isEmpty() && !size)) return false; if (size && nextRequestOffset >= size) return false; int32 limit = DocumentDownloadPartSize; MTPInputFileLocation loc; switch (_locationType) { case UnknownFileLocation: loc = MTP_inputFileLocation(MTP_long(volume), MTP_int(local), MTP_long(secret)); limit = DownloadPartSize; break; case VideoFileLocation: loc = MTP_inputVideoFileLocation(MTP_long(id), MTP_long(access)); break; case AudioFileLocation: loc = MTP_inputAudioFileLocation(MTP_long(id), MTP_long(access)); break; case DocumentFileLocation: loc = MTP_inputDocumentFileLocation(MTP_long(id), MTP_long(access)); break; default: finishFail(); return false; break; } int32 offset = nextRequestOffset, dcIndex = 0; DataRequested &dr(_dataRequested[dc]); if (size) { for (int32 i = 1; i < MTPDownloadSessionsCount; ++i) { if (dr.v[i] < dr.v[dcIndex]) { dcIndex = i; } } } App::app()->killDownloadSessionsStop(dc); mtpRequestId reqId = MTP::send(MTPupload_GetFile(MTPupload_getFile(loc, MTP_int(offset), MTP_int(limit))), rpcDone(&mtpFileLoader::partLoaded, offset), rpcFail(&mtpFileLoader::partFailed), MTP::dld[dcIndex] + dc, 50); ++queue->queries; dr.v[dcIndex] += limit; requests.insert(reqId, dcIndex); nextRequestOffset += limit; return true; }
void ConfirmPhoneBox::onSendCode() { if (_sendCodeRequestId) { return; } auto code = _code->getLastText(); if (code.isEmpty()) { _code->showError(); return; } _code->setDisabled(true); setFocus(); showError(QString()); _sendCodeRequestId = MTP::send(MTPaccount_ConfirmPhone(MTP_string(_phoneHash), MTP_string(_code->getLastText())), rpcDone(&ConfirmPhoneBox::confirmDone), rpcFail(&ConfirmPhoneBox::confirmFail)); }
void ConfirmPhoneBox::checkPhoneAndHash() { if (_sendCodeRequestId) { return; } _sendCodeRequestId = MTP::send(MTPaccount_SendConfirmPhoneCode(MTP_flags(0), MTP_string(_hash), MTPBool()), rpcDone(&ConfirmPhoneBox::sendCodeDone), rpcFail(&ConfirmPhoneBox::sendCodeFail)); }
void PinMessageBox::onPin() { if (_requestId) return; MTPchannels_UpdatePinnedMessage::Flags flags = 0; if (!_notify.checked()) { flags |= MTPchannels_UpdatePinnedMessage::Flag::f_silent; } _requestId = MTP::send(MTPchannels_UpdatePinnedMessage(MTP_flags(flags), _channel->inputChannel, MTP_int(_msgId)), rpcDone(&PinMessageBox::pinDone), rpcFail(&PinMessageBox::pinFail)); }
void MembersBox::Inner::load() { if (!_loadingRequestId) { _loadingRequestId = MTP::send(MTPchannels_GetParticipants(_channel->inputChannel, (_filter == MembersFilter::Recent) ? MTP_channelParticipantsRecent() : MTP_channelParticipantsAdmins(), MTP_int(0), MTP_int(Global::ChatSizeMax())), rpcDone(&Inner::membersReceived), rpcFail(&Inner::membersFailed)); } }
void ApiWrap::requestFullPeer(PeerData *peer) { if (!peer || _fullPeerRequests.contains(peer)) return; mtpRequestId req; if (peer->chat) { req = MTP::send(MTPmessages_GetFullChat(MTP_int(App::chatFromPeer(peer->id))), rpcDone(&ApiWrap::gotChatFull, peer), rpcFail(&ApiWrap::gotPeerFullFailed, peer)); } else { req = MTP::send(MTPusers_GetFullUser(peer->asUser()->inputUser), rpcDone(&ApiWrap::gotUserFull, peer), rpcFail(&ApiWrap::gotPeerFullFailed, peer)); } _fullPeerRequests.insert(peer, req); }
void MembersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { auto pressed = _pressed; auto kickPressed = _kickPressed; setPressed(-1); if (e->button() == Qt::LeftButton) { if (pressed == _selected && kickPressed == _kickSelected) { if (kickPressed >= 0) { if (!_kickRequestId) { _kickConfirm = _rows.at(_kickSelected); if (_kickBox) _kickBox->deleteLater(); auto text = (_filter == MembersFilter::Recent ? (_channel->isMegagroup() ? lng_profile_sure_kick : lng_profile_sure_kick_channel) : lng_profile_sure_kick_admin)(lt_user, _kickConfirm->firstName); _kickBox = Ui::show(Box<ConfirmBox>(text, base::lambda_guarded(this, [this] { if (_filter == MembersFilter::Recent) { _kickRequestId = MTP::send(MTPchannels_KickFromChannel(_channel->inputChannel, _kickConfirm->inputUser, MTP_bool(true)), rpcDone(&Inner::kickDone), rpcFail(&Inner::kickFail)); } else { _kickRequestId = MTP::send(MTPchannels_EditAdmin(_channel->inputChannel, _kickConfirm->inputUser, MTP_channelRoleEmpty()), rpcDone(&Inner::kickAdminDone), rpcFail(&Inner::kickFail)); } })), KeepOtherLayers); } } else if (pressed >= 0) { chooseParticipant(); } } } }
void ApiWrap::requestStickerSets() { for (QMap<uint64, QPair<uint64, mtpRequestId> >::iterator i = _stickerSetRequests.begin(), j = i, e = _stickerSetRequests.end(); i != e; i = j) { if (i.value().second) continue; ++j; int32 wait = (j == e) ? 0 : 10; i.value().second = MTP::send(MTPmessages_GetStickerSet(MTP_inputStickerSetID(MTP_long(i.key()), MTP_long(i.value().first))), rpcDone(&ApiWrap::gotStickerSet, i.key()), rpcFail(&ApiWrap::gotStickerSetFail, i.key()), 0, wait); } }
bool CodeWidget::codeSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); _sentRequest = 0; showCodeError(langFactory(lng_flood_error)); return true; } if (MTP::isDefaultHandledError(error)) return false; stopCheck(); _sentRequest = 0; auto &err = error.type(); if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED")) { // show error goBack(); return true; } else if (err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID")) { showCodeError(langFactory(lng_bad_code)); return true; } else if (err == qstr("PHONE_NUMBER_UNOCCUPIED")) { // success, need to signUp getData()->code = _sentCode; goReplace(new Intro::SignupWidget(parentWidget(), getData())); return true; } else if (err == qstr("SESSION_PASSWORD_NEEDED")) { getData()->code = _sentCode; _checkRequest->start(1000); _sentRequest = MTP::send(MTPaccount_GetPassword(), rpcDone(&CodeWidget::gotPassword), rpcFail(&CodeWidget::codeSubmitFail)); return true; } if (Logs::DebugEnabled()) { // internal server error auto text = err + ": " + error.description(); showCodeError([text] { return text; }); } else { showCodeError(&Lang::Hard::ServerError); } return false; }
void UsernameBox::onCheck() { if (_checkRequestId) { MTP::cancel(_checkRequestId); } QString name = getName(); if (name.size() >= MinUsernameLength) { _checkUsername = name; _checkRequestId = MTP::send(MTPaccount_CheckUsername(MTP_string(name)), rpcDone(&UsernameBox::onCheckDone), rpcFail(&UsernameBox::onCheckFail)); } }
void CodeWidget::submit() { const auto text = QString( _code->getLastText() ).remove( QRegularExpression("[^\\d]") ).mid(0, getData()->codeLength); if (_sentRequest || _sentCode == text || text.size() != getData()->codeLength) { return; } hideError(); _checkRequest->start(1000); _sentCode = text; getData()->pwdRequest = Core::CloudPasswordCheckRequest(); getData()->hasRecovery = false; getData()->pwdHint = QString(); getData()->pwdNotEmptyPassport = false; _sentRequest = MTP::send(MTPauth_SignIn(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash), MTP_string(_sentCode)), rpcDone(&CodeWidget::codeSubmitDone), rpcFail(&CodeWidget::codeSubmitFail)); }
void Application::peerClearPhoto(PeerId peer) { if (App::self() && App::self()->id == peer) { MTP::send(MTPphotos_UpdateProfilePhoto(MTP_inputPhotoEmpty(), MTP_inputPhotoCropAuto()), rpcDone(&Application::selfPhotoCleared), rpcFail(&Application::peerPhotoFail, peer)); } else { MTP::send(MTPmessages_EditChatPhoto(MTP_int(int32(peer & 0xFFFFFFFF)), MTP_inputChatPhotoEmpty()), rpcDone(&Application::chatPhotoCleared, peer), rpcFail(&Application::peerPhotoFail, peer)); } }
void CodeWidget::onNoTelegramCode() { if (_noTelegramCodeRequestId) return; _noTelegramCodeRequestId = MTP::send(MTPauth_ResendCode(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash)), rpcDone(&CodeWidget::noTelegramCodeDone), rpcFail(&CodeWidget::noTelegramCodeFail)); }
void IntroPhone::onSubmitPhone(bool force) { if (!force && !next.isEnabled()) return; if (!App::isValidPhone(fullNumber())) { showError(lang(lng_bad_phone)); phone.setFocus(); return; } disableAll(); showError(""); checkRequest.start(1000); sentPhone = fullNumber(); sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(sentPhone)), rpcDone(&IntroPhone::phoneCheckDone), rpcFail(&IntroPhone::phoneSubmitFail)); }
void SessionsBox::Inner::onTerminate() { for (auto i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) { if (i.value()->isOver()) { if (_terminateBox) _terminateBox->deleteLater(); _terminateBox = Ui::show(Box<ConfirmBox>(lang(lng_settings_reset_one_sure), lang(lng_settings_reset_button), st::attentionBoxButton, base::lambda_guarded(this, [this, terminating = i.key()] { if (_terminateBox) { _terminateBox->closeBox(); _terminateBox = nullptr; } MTP::send(MTPaccount_ResetAuthorization(MTP_long(terminating)), rpcDone(&Inner::terminateDone, terminating), rpcFail(&Inner::terminateFail, terminating)); auto i = _terminateButtons.find(terminating); if (i != _terminateButtons.cend()) { i.value()->clearState(); i.value()->hide(); } })), LayerOption::KeepOther); } } }
void IntroPhone::toSignUp() { disableAll(); showError(""); checkRequest.start(1000); sentRequest = MTP::send(MTPauth_SendCode(MTP_string(sentPhone), MTP_int(0), MTP_int(ApiId), MTP_string(ApiHash), MTP_string(Sandbox::LangSystemISO())), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); }
void ConvertToSupergroupBox::onConvert() { MTP::send(MTPmessages_MigrateChat(_chat->inputChat), rpcDone(&ConvertToSupergroupBox::convertDone), rpcFail(&ConvertToSupergroupBox::convertFail)); }
void IntroPwdCheck::onToRecover() { if (_hasRecovery) { if (sentRequest) { MTP::cancel(sentRequest); sentRequest = 0; } showError(QString()); _toRecover.hide(); _toPassword.show(); _pwdField.hide(); _pwdField.setText(QString()); _codeField.show(); _codeField.setFocus(); if (_emailPattern.isEmpty()) { MTP::send(MTPauth_RequestPasswordRecovery(), rpcDone(&IntroPwdCheck::recoverStarted), rpcFail(&IntroPwdCheck::recoverStartFail)); } update(); } else { ConfirmBox *box = new InformBox(lang(lng_signin_no_email_forgot)); Ui::showLayer(box); connect(box, SIGNAL(destroyed(QObject*)), this, SLOT(onToReset())); } }
void AddContactBox::onSave() { if (_addRequest) return; QString firstName = prepareText(_first->getLastText()); QString lastName = prepareText(_last->getLastText()); QString phone = _phone->getLastText().trimmed(); if (firstName.isEmpty() && lastName.isEmpty()) { if (_invertOrder) { _last->setFocus(); _last->showError(); } else { _first->setFocus(); _first->showError(); } return; } else if (!_user && !App::isValidPhone(phone)) { _phone->setFocus(); _phone->showError(); return; } if (firstName.isEmpty()) { firstName = lastName; lastName = QString(); } _sentName = firstName; if (_user) { _contactId = rand_value<uint64>(); QVector<MTPInputContact> v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(_user->phone()), MTP_string(firstName), MTP_string(lastName))); _addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector<MTPInputContact>(v), MTP_bool(false)), rpcDone(&AddContactBox::onSaveUserDone), rpcFail(&AddContactBox::onSaveUserFail)); } else { _contactId = rand_value<uint64>(); QVector<MTPInputContact> v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(phone), MTP_string(firstName), MTP_string(lastName))); _addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector<MTPInputContact>(v), MTP_bool(false)), rpcDone(&AddContactBox::onImportDone)); } }