From d840ec37db8cceca90985bde799b8a0a0a911a79 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 31 Aug 2015 17:27:20 +0300 Subject: [PATCH] preparing new dev version, date tooltip on timestamp hover, year marks in old day labels, new auth code / sms algo --- Telegram/Resources/lang.strings | 3 + Telegram/Resources/style.txt | 4 ++ Telegram/SourceFiles/gui/text.cpp | 22 +++++- Telegram/SourceFiles/history.cpp | 81 ++++++++++++++++++++--- Telegram/SourceFiles/historywidget.cpp | 26 +++++--- Telegram/SourceFiles/intro/intro.cpp | 10 +++ Telegram/SourceFiles/intro/intro.h | 4 +- Telegram/SourceFiles/intro/introcode.cpp | 73 +++++++++++++++++--- Telegram/SourceFiles/intro/introcode.h | 9 +++ Telegram/SourceFiles/intro/introphone.cpp | 3 +- Telegram/SourceFiles/lang.h | 8 ++- Telegram/SourceFiles/mainwidget.cpp | 1 + 12 files changed, 214 insertions(+), 30 deletions(-) diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index f6af33095..e34d4aa03 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -60,6 +60,7 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org "lng_weekday7_full" = "Sunday"; "lng_month_day" = "{month} {day}"; +"lng_month_day_year" = "{month} {day}, {year}"; "lng_cancel" = "Cancel"; "lng_continue" = "Continue"; @@ -117,6 +118,8 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org "lng_code_ph" = "Your code"; "lng_code_desc" = "We have sent you a message with activation\ncode to your phone. Please enter it below."; +"lng_code_telegram" = "Please enter the code you've just\nreceived in your previous [b]Telegram[/b] app."; +"lng_code_no_telegram" = "Send code via SMS"; "lng_code_call" = "Telegram will dial your number in {minutes}:{seconds}"; "lng_code_calling" = "Requesting a call from Telegram.."; "lng_code_called" = "Telegram dialed your number"; diff --git a/Telegram/Resources/style.txt b/Telegram/Resources/style.txt index 656a6e163..c258a78cf 100644 --- a/Telegram/Resources/style.txt +++ b/Telegram/Resources/style.txt @@ -340,6 +340,10 @@ introHeaderFont: font(24px); introHeaderSkip: 14px; introIconSkip: 54px; introFont: font(16px); +introLink: linkButton(btnDefLink) { + font: introFont; + overFont: font(16px underline); +} introColor: black; introLabel: flatLabel(labelDefFlat) { font: introFont; diff --git a/Telegram/SourceFiles/gui/text.cpp b/Telegram/SourceFiles/gui/text.cpp index 78c6f2523..83f24fb4c 100644 --- a/Telegram/SourceFiles/gui/text.cpp +++ b/Telegram/SourceFiles/gui/text.cpp @@ -542,7 +542,27 @@ public: flags(0), lnkIndex(0), stopAfterWidth(QFIXED_MAX) { - lnkRanges = links; + if ((options.flags & TextParseLinks) && !links.isEmpty()) { + bool parseMentions = (options.flags & TextParseMentions); + bool parseHashtags = (options.flags & TextParseHashtags); + bool parseBotCommands = (options.flags & TextParseBotCommands); + if (parseMentions && parseHashtags && parseBotCommands) { + lnkRanges = links; + } else { + int32 i = 0, l = links.size(); + lnkRanges.reserve(l); + const QChar *p = text.constData(), s = text.size(); + for (; i < l; ++i) { + LinkInTextType t = links.at(i).type; + if ((t == LinkInTextMention && !parseMentions) || + (t == LinkInTextHashtag && !parseHashtags) || + (t == LinkInTextBotCommand && !parseBotCommands)) { + continue; + } + lnkRanges.push_back(links.at(i)); + } + } + } parse(options); } void parse(const TextParseOptions &options) { diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 1361ad544..1388c2cee 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -2015,19 +2015,37 @@ void HistoryPhoto::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x return fwd->getForwardedState(lnk, state, x - st::mediaPadding.left(), width - st::mediaPadding.left() - st::mediaPadding.right()); } } - height -= st::mediaPadding.bottom(); + height -= skipy + st::mediaPadding.bottom(); width -= st::mediaPadding.left() + st::mediaPadding.right(); if (!_caption.isEmpty()) { + int32 dateX = skipx + width + st::msgDateDelta.x() - parent->timeWidth(true) + st::msgDateSpace; + int32 dateY = _height - st::msgPadding.bottom() + st::msgDateDelta.y() - st::msgDateFont->height; + bool inDate = QRect(dateX, dateY, parent->timeWidth(true) - st::msgDateSpace, st::msgDateFont->height).contains(x, y); + if (inDate) { + state = HistoryInDateCursorState; + } + height -= _caption.countHeight(width) + st::webPagePhotoSkip; - if (x >= skipx && y >= height + st::webPagePhotoSkip && x < skipx + width && y < _height) { + if (x >= skipx && y >= skipy + height + st::webPagePhotoSkip && x < skipx + width && y < _height) { bool inText = false; - _caption.getState(lnk, inText, x - skipx, y - height - st::webPagePhotoSkip, width); - state = inText ? HistoryInTextCursorState : HistoryDefaultCursorState; + _caption.getState(lnk, inText, x - skipx, y - skipy - height - st::webPagePhotoSkip, width); + state = inDate ? HistoryInDateCursorState : (inText ? HistoryInTextCursorState : HistoryDefaultCursorState); } } } - if (x >= skipx && y >= skipy && x < skipx + width && y < height) { + if (x >= skipx && y >= skipy && x < skipx + width && y < skipy + height) { lnk = openl; + if (_caption.isEmpty()) { + int32 dateX = skipx + width - parent->timeWidth(false) - st::msgDateImgDelta - st::msgDateImgPadding.x(); + int32 dateY = skipy + height - st::msgDateFont->height - st::msgDateImgDelta - st::msgDateImgPadding.y(); + if (parent->out()) { + dateX -= st::msgCheckRect.pxWidth() + st::msgDateImgCheckSpace; + } + bool inDate = QRect(dateX, dateY, parent->timeWidth(true) - st::msgDateSpace, st::msgDateFont->height).contains(x, y); + if (inDate) { + state = HistoryInDateCursorState; + } + } return; } } @@ -2422,6 +2440,13 @@ void HistoryVideo::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x } } + int32 dateX = width - st::msgPadding.right() + st::msgDateDelta.x() - parent->timeWidth(true) + st::msgDateSpace; + int32 dateY = _height - st::msgPadding.bottom() + st::msgDateDelta.y() - st::msgDateFont->height; + bool inDate = QRect(dateX, dateY, parent->timeWidth(true) - st::msgDateSpace, st::msgDateFont->height).contains(x, y); + if (inDate) { + state = HistoryInDateCursorState; + } + int32 tw = width - st::mediaPadding.left() - st::mediaPadding.right(); if (x >= st::mediaPadding.left() && y >= skipy + st::mediaPadding.top() && x < st::mediaPadding.left() + tw && y < skipy + st::mediaPadding.top() + st::mediaThumbSize && !data->loader && data->access) { lnk = _openl; @@ -2430,7 +2455,7 @@ void HistoryVideo::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x if (!_caption.isEmpty() && x >= st::mediaPadding.left() && x < st::mediaPadding.left() + tw && y >= skipy + st::mediaPadding.top() + st::mediaThumbSize + st::webPagePhotoSkip) { bool inText = false; _caption.getState(lnk, inText, x - st::mediaPadding.left(), y - skipy - st::mediaPadding.top() - st::mediaThumbSize - st::webPagePhotoSkip, tw); - state = inText ? HistoryInTextCursorState : HistoryDefaultCursorState; + state = inDate ? HistoryInDateCursorState : (inText ? HistoryInTextCursorState : HistoryDefaultCursorState); } } @@ -2918,6 +2943,14 @@ void HistoryAudio::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x if (x >= 0 && y >= skipy && x < width && y < _height && !data->loader && data->access) { lnk = _openl; + + int32 dateX = width - st::msgPadding.right() + st::msgDateDelta.x() - parent->timeWidth(true) + st::msgDateSpace; + int32 dateY = _height - st::msgPadding.bottom() + st::msgDateDelta.y() - st::msgDateFont->height; + bool inDate = QRect(dateX, dateY, parent->timeWidth(true) - st::msgDateSpace, st::msgDateFont->height).contains(x, y); + if (inDate) { + state = HistoryInDateCursorState; + } + return; } } @@ -3430,6 +3463,14 @@ void HistoryDocument::getState(TextLinkPtr &lnk, HistoryCursorState &state, int3 if (x >= 0 && y >= skipy && x < width && y < _height && !data->loader && data->access) { lnk = _openl; + + int32 dateX = width - st::msgPadding.right() + st::msgDateDelta.x() - parent->timeWidth(true) + st::msgDateSpace; + int32 dateY = _height - st::msgPadding.bottom() + st::msgDateDelta.y() - st::msgDateFont->height; + bool inDate = QRect(dateX, dateY, parent->timeWidth(true) - st::msgDateSpace, st::msgDateFont->height).contains(x, y); + if (inDate) { + state = HistoryInDateCursorState; + } + return; } } @@ -3602,6 +3643,10 @@ void HistorySticker::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 const HistoryReply *reply = toHistoryReply(parent); if (reply) { usew -= reply->replyToWidth(); + if (parent->out()) { + usex = width - usew; + } + int32 rw = width - usew, rh = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); int32 rx = parent->out() ? 0 : usew, ry = _height - rh; if (x >= rx && y >= ry && x < rx + rw && y < ry + rh) { @@ -3609,6 +3654,15 @@ void HistorySticker::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 return; } } + int32 dateX = usex + usew - parent->timeWidth(false) - st::msgDateImgDelta - st::msgDateImgPadding.x(); + int32 dateY = _height - st::msgDateFont->height - st::msgDateImgDelta - st::msgDateImgPadding.y(); + if (parent->out()) { + dateX -= st::msgCheckRect.pxWidth() + st::msgDateImgCheckSpace; + } + bool inDate = QRect(dateX, dateY, parent->timeWidth(true) - st::msgDateSpace, st::msgDateFont->height).contains(x, y); + if (inDate) { + state = HistoryInDateCursorState; + } } HistoryMedia *HistorySticker::clone() const { @@ -5159,11 +5213,22 @@ void HistoryImageLink::getState(TextLinkPtr &lnk, HistoryCursorState &state, int return fwd->getForwardedState(lnk, state, x - st::mediaPadding.left(), width - st::mediaPadding.left() - st::mediaPadding.right()); } } - height -= st::mediaPadding.bottom(); + height -= skipy + st::mediaPadding.bottom(); width -= st::mediaPadding.left() + st::mediaPadding.right(); } - if (x >= skipx && y >= skipy && x < skipx + width && y < height && data) { + if (x >= skipx && y >= skipy && x < skipx + width && y < skipy + height && data) { lnk = link; + + int32 dateX = skipx + width - parent->timeWidth(false) - st::msgDateImgDelta - st::msgDateImgPadding.x(); + int32 dateY = skipy + height - st::msgDateFont->height - st::msgDateImgDelta - st::msgDateImgPadding.y(); + if (parent->out()) { + dateX -= st::msgCheckRect.pxWidth() + st::msgDateImgCheckSpace; + } + bool inDate = QRect(dateX, dateY, parent->timeWidth(true) - st::msgDateSpace, st::msgDateFont->height).contains(x, y); + if (inDate) { + state = HistoryInDateCursorState; + } + return; } } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 94b74db1c..c44d7798c 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -559,10 +559,10 @@ void HistoryList::onDragExec() { QDrag *drag = new QDrag(App::wnd()); QMimeData *mimeData = new QMimeData; - if (dragSticker || dragByDate) { - mimeData->setData(qsl("application/x-td-forward-pressed"), "1"); - } else { + if (lnkPhoto || lnkVideo || lnkAudio || lnkDocument || lnkContact) { mimeData->setData(qsl("application/x-td-forward-pressed-link"), "1"); + } else { + mimeData->setData(qsl("application/x-td-forward-pressed"), "1"); } if (lnkDocument) { QString already = static_cast(textlnkDown().data())->document()->already(true); @@ -1346,7 +1346,6 @@ void HistoryList::onUpdateSelected() { if (_dragItem && _dragItem->detached()) { dragActionCancel(); } - linkTipTimer.start(1000); Qt::CursorShape cur = style::cur_default; HistoryCursorState cursorState = HistoryDefaultCursorState; @@ -1383,6 +1382,12 @@ void HistoryList::onUpdateSelected() { } } } + if (lnk || cursorState == HistoryInDateCursorState) { + linkTipTimer.start(1000); + } + if (_dragCursorState == HistoryInDateCursorState && cursorState != HistoryInDateCursorState) { + QToolTip::showText(_dragPos, QString(), App::wnd()); + } if (_dragAction == NoDrag) { _dragCursorState = cursorState; @@ -1546,6 +1551,10 @@ void HistoryList::showLinkTip() { TextLinkPtr lnk = textlnkOver(); if (lnk && !lnk->fullDisplayed()) { QToolTip::showText(_dragPos, lnk->readable(), App::wnd()); + } else if (_dragCursorState == HistoryInDateCursorState && _dragAction == NoDrag) { + if (App::hoveredItem()) { + QToolTip::showText(_dragPos, App::hoveredItem()->date.toString(QLocale::system().dateTimeFormat(QLocale::LongFormat)), App::wnd()); + } } } @@ -3416,7 +3425,7 @@ void HistoryWidget::shareContact(const PeerId &peer, const QString &phone, const fastShowAtEnd(h); PeerData *p = App::peer(peer); - int32 flags = newMessageFlags(p); // unread, out + int32 flags = newMessageFlags(p) | MTPDmessage::flag_media; // unread, out bool lastKeyboardUsed = lastForceReplyReplied(replyTo); @@ -4296,14 +4305,15 @@ void HistoryWidget::confirmSendImage(const ReadyLocalMedia &img) { fastShowAtEnd(h); - int32 flags = newMessageFlags(h->peer); // unread, out + int32 flags = newMessageFlags(h->peer) | MTPDmessage::flag_media; // unread, out if (img.replyTo) flags |= MTPDmessage::flag_reply_to_msg_id; if (img.type == ToPreparePhoto) { h->addToBack(MTP_message(MTP_int(flags), MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(img.peer), MTPint(), MTPint(), MTP_int(img.replyTo), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaPhoto(img.photo, MTP_string("")), MTPnullMarkup, MTPnullEntities)); } else if (img.type == ToPrepareDocument) { h->addToBack(MTP_message(MTP_int(flags), MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(img.peer), MTPint(), MTPint(), MTP_int(img.replyTo), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaDocument(img.document), MTPnullMarkup, MTPnullEntities)); } else if (img.type == ToPrepareAudio) { - h->addToBack(MTP_message(MTP_int(flags | MTPDmessage_flag_media_unread), MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(img.peer), MTPint(), MTPint(), MTP_int(img.replyTo), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaAudio(img.audio), MTPnullMarkup, MTPnullEntities)); + flags |= MTPDmessage_flag_media_unread; + h->addToBack(MTP_message(MTP_int(flags), MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(img.peer), MTPint(), MTPint(), MTP_int(img.replyTo), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaAudio(img.audio), MTPnullMarkup, MTPnullEntities)); } if (_peer && img.peer == _peer->id) { @@ -4902,7 +4912,7 @@ void HistoryWidget::onStickerSend(DocumentData *sticker) { bool lastKeyboardUsed = lastForceReplyReplied(); bool out = (_peer->input.type() != mtpc_inputPeerSelf), unread = (_peer->input.type() != mtpc_inputPeerSelf); - int32 flags = newMessageFlags(_peer); // unread, out + int32 flags = newMessageFlags(_peer) | MTPDmessage::flag_media; // unread, out int32 sendFlags = 0; if (replyToId()) { flags |= MTPDmessage::flag_reply_to_msg_id; diff --git a/Telegram/SourceFiles/intro/intro.cpp b/Telegram/SourceFiles/intro/intro.cpp index b1bd08aab..c71a7d5d7 100644 --- a/Telegram/SourceFiles/intro/intro.cpp +++ b/Telegram/SourceFiles/intro/intro.cpp @@ -65,6 +65,7 @@ visibilityChanging(0), _callTimeout(60), _registered(false), _hasRecovery(false), +_codeByTelegram(false), _back(this, st::setClose), _backFrom(0), _backTo(0) { setGeometry(QRect(0, st::titleHeight, wnd->width(), wnd->height() - st::titleHeight)); @@ -335,6 +336,11 @@ void IntroWidget::setPwdHint(const QString &hint) { _pwdHint = hint; } +void IntroWidget::setCodeByTelegram(bool byTelegram) { + _codeByTelegram = byTelegram; + if (code) code->updateDescText(); +} + void IntroWidget::setCallTimeout(int32 callTimeout) { _callTimeout = callTimeout; } @@ -367,6 +373,10 @@ const QString &IntroWidget::getPwdHint() const { return _pwdHint; } +bool IntroWidget::codeByTelegram() const { + return _codeByTelegram; +} + void IntroWidget::resizeEvent(QResizeEvent *e) { QRect r(innerRect()); if (steps) steps->setGeometry(r); diff --git a/Telegram/SourceFiles/intro/intro.h b/Telegram/SourceFiles/intro/intro.h index dd59066a5..af7f11d0f 100644 --- a/Telegram/SourceFiles/intro/intro.h +++ b/Telegram/SourceFiles/intro/intro.h @@ -52,6 +52,7 @@ public: void setPwdSalt(const QByteArray &salt); void setHasRecovery(bool hasRecovery); void setPwdHint(const QString &hint); + void setCodeByTelegram(bool byTelegram); const QString &getPhone() const; const QString &getPhoneHash() const; @@ -60,6 +61,7 @@ public: const QByteArray &getPwdSalt() const; bool getHasRecovery() const; const QString &getPwdHint() const; + bool codeByTelegram() const; void finish(const MTPUser &user, const QImage &photo = QImage()); @@ -114,7 +116,7 @@ private: QString _code; QByteArray _pwdSalt; - bool _hasRecovery; + bool _hasRecovery, _codeByTelegram; QString _pwdHint; QString _firstname, _lastname; diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index b9dc0bf57..9b8848b88 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -69,6 +69,9 @@ void CodeInput::correctValue(QKeyEvent *e, const QString &was) { IntroCode::IntroCode(IntroWidget *parent) : IntroStage(parent), errorAlpha(0), next(this, lang(lng_intro_next), st::btnIntroNext), + _desc(st::introTextSize.width()), + _noTelegramCode(this, lang(lng_code_no_telegram), st::introLink), + _noTelegramCodeRequestId(0), code(this, st::inpIntroCode, lang(lng_code_ph)), waitTillCall(intro()->getCallTimeout()) { setVisible(false); setGeometry(parent->innerRect()); @@ -78,6 +81,24 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStage(parent), errorAlpha(0), connect(&code, SIGNAL(changed()), this, SLOT(onInputChange())); connect(&callTimer, SIGNAL(timeout()), this, SLOT(onSendCall())); connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); + connect(&_noTelegramCode, SIGNAL(clicked()), this, SLOT(onNoTelegramCode())); + + updateDescText(); +} + +void IntroCode::updateDescText() { + _desc.setRichText(st::introFont, lang(intro()->codeByTelegram() ? lng_code_telegram : lng_code_desc)); + if (intro()->codeByTelegram()) { + _noTelegramCode.show(); + callTimer.stop(); + } else { + _noTelegramCode.hide(); + waitTillCall = intro()->getCallTimeout(); + if (!callTimer.isActive()) { + callTimer.start(1000); + } + } + update(); } void IntroCode::paintEvent(QPaintEvent *e) { @@ -87,21 +108,25 @@ void IntroCode::paintEvent(QPaintEvent *e) { if (!trivial) { p.setClipRect(e->rect()); } + bool codeByTelegram = intro()->codeByTelegram(); if (trivial || e->rect().intersects(textRect)) { p.setFont(st::introHeaderFont->f); p.drawText(textRect, intro()->getPhone(), style::al_top); p.setFont(st::introFont->f); - p.drawText(textRect, lang(lng_code_desc), style::al_bottom); + _desc.draw(p, textRect.x(), textRect.y() + textRect.height() - 2 * st::introFont->height, textRect.width(), style::al_top); } - QString callText = lang(lng_code_calling); - if (waitTillCall >= 3600) { - callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(waitTillCall / 3600).arg((waitTillCall / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(waitTillCall % 60, 2, 10, QChar('0'))); - } else if (waitTillCall > 0) { - callText = lng_code_call(lt_minutes, QString::number(waitTillCall / 60), lt_seconds, qsl("%1").arg(waitTillCall % 60, 2, 10, QChar('0'))); - } else if (waitTillCall < 0) { - callText = lang(lng_code_called); + if (codeByTelegram) { + } else { + QString callText = lang(lng_code_calling); + if (waitTillCall >= 3600) { + callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(waitTillCall / 3600).arg((waitTillCall / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(waitTillCall % 60, 2, 10, QChar('0'))); + } else if (waitTillCall > 0) { + callText = lng_code_call(lt_minutes, QString::number(waitTillCall / 60), lt_seconds, qsl("%1").arg(waitTillCall % 60, 2, 10, QChar('0'))); + } else if (waitTillCall < 0) { + callText = lang(lng_code_called); + } + p.drawText(QRect(textRect.left(), code.y() + code.height() + st::introCallSkip, st::introTextSize.width(), st::introErrHeight), callText, style::al_center); } - p.drawText(QRect(textRect.left(), code.y() + code.height() + st::introCallSkip, st::introTextSize.width(), st::introErrHeight), callText, style::al_center); if (animating() || error.length()) { p.setOpacity(errorAlpha.current()); p.setFont(st::introErrFont->f); @@ -116,6 +141,7 @@ void IntroCode::resizeEvent(QResizeEvent *e) { code.move((width() - code.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); } textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); + _noTelegramCode.move(textRect.left() + (st::introTextSize.width() - _noTelegramCode.width()) / 2, code.y() + code.height() + st::introCallSkip + (st::introErrHeight - _noTelegramCode.height()) / 2); } void IntroCode::showError(const QString &err) { @@ -150,7 +176,9 @@ bool IntroCode::animStep(float64 ms) { void IntroCode::activate() { waitTillCall = intro()->getCallTimeout(); - callTimer.start(1000); + if (!intro()->codeByTelegram()) { + callTimer.start(1000); + } error = ""; errorAlpha = anim::fvalue(0); sentCode = QString(); @@ -300,6 +328,31 @@ void IntroCode::onSubmitCode(bool force) { sentRequest = MTP::send(MTPauth_SignIn(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(sentCode)), rpcDone(&IntroCode::codeSubmitDone), rpcFail(&IntroCode::codeSubmitFail)); } +void IntroCode::onNoTelegramCode() { + if (_noTelegramCodeRequestId) return; + _noTelegramCodeRequestId = MTP::send(MTPauth_SendSms(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())), rpcDone(&IntroCode::noTelegramCodeDone), rpcFail(&IntroCode::noTelegramCodeFail)); +} + +void IntroCode::noTelegramCodeDone(const MTPBool &result) { + intro()->setCodeByTelegram(false); + updateDescText(); +} + +bool IntroCode::noTelegramCodeFail(const RPCError &error) { + if (error.type().startsWith(qsl("FLOOD_WAIT_"))) { + showError(lang(lng_flood_error)); + code.setFocus(); + return true; + } + if (cDebug()) { // internal server error + showError(error.type() + ": " + error.description()); + } else { + showError(lang(lng_server_error)); + } + code.setFocus(); + return false; +} + void IntroCode::onNext() { onSubmitCode(); } diff --git a/Telegram/SourceFiles/intro/introcode.h b/Telegram/SourceFiles/intro/introcode.h index 6e44aa827..b171d0574 100644 --- a/Telegram/SourceFiles/intro/introcode.h +++ b/Telegram/SourceFiles/intro/introcode.h @@ -64,9 +64,12 @@ public: void codeSubmitDone(const MTPauth_Authorization &result); bool codeSubmitFail(const RPCError &error); + void updateDescText(); + public slots: void onSubmitCode(bool force = false); + void onNoTelegramCode(); void onInputChange(); void onSendCall(); void onCheckRequest(); @@ -84,8 +87,14 @@ private: FlatButton next; + Text _desc; + LinkButton _noTelegramCode; + mtpRequestId _noTelegramCodeRequestId; QRect textRect; + void noTelegramCodeDone(const MTPBool &result); + bool noTelegramCodeFail(const RPCError &result); + CodeInput code; QString sentCode; mtpRequestId sentRequest; diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 7c968bb3d..9c1196067 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -231,7 +231,7 @@ void IntroPhone::phoneCheckDone(const MTPauth_CheckedPhone &result) { checkRequest.start(1000); - sentRequest = MTP::send(MTPauth_SendCode(MTP_string(sentPhone), MTP_int(0), MTP_int(ApiId), MTP_string(ApiHash), MTP_string(Application::language())), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); + sentRequest = MTP::send(MTPauth_SendCode(MTP_string(sentPhone), MTP_int(5), MTP_int(ApiId), MTP_string(ApiHash), MTP_string(Application::language())), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); } else { showError(lang(lng_bad_phone_noreg), true); enableAll(true); @@ -250,6 +250,7 @@ void IntroPhone::phoneSubmitDone(const MTPauth_SentCode &result) { const MTPDauth_sentAppCode &d(result.c_auth_sentAppCode()); intro()->setPhone(sentPhone, d.vphone_code_hash.c_string().v.c_str(), d.vphone_registered.v); intro()->setCallTimeout(d.vsend_call_timeout.v); + intro()->setCodeByTelegram(true); } intro()->onIntroNext(); } diff --git a/Telegram/SourceFiles/lang.h b/Telegram/SourceFiles/lang.h index 7cb0fea1d..e99c42dca 100644 --- a/Telegram/SourceFiles/lang.h +++ b/Telegram/SourceFiles/lang.h @@ -78,7 +78,13 @@ LangString langCounted(ushort key0, ushort tag, float64 value); const char *langKeyName(LangKey key); inline LangString langDayOfMonth(const QDate &date) { - int32 month = date.month(), day = date.day(); + QDate c(QDate::currentDate()); + int32 month = date.month(), day = date.day(), year = date.year(), cyear = c.year(), cmonth = c.month(); + if (year != cyear) { + if (year > cyear + 1 || cyear > year + 1 || (year == cyear + 1 && month + 12 > cmonth + 3) || (cyear == year + 1 && cmonth + 12 > month + 3)) { + return (month > 0 && month <= 12) ? lng_month_day_year(lt_month, lang(LangKey(lng_month1 + month - 1)), lt_day, QString::number(day), lt_year, QString::number(year)) : qsl("MONTH_ERR"); + } + } return (month > 0 && month <= 12) ? lng_month_day(lt_month, lang(LangKey(lng_month1 + month - 1)), lt_day, QString::number(day)) : qsl("MONTH_ERR"); } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 55b6d43e6..43884eeaa 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1064,6 +1064,7 @@ void MainWidget::sendPreparedText(History *hist, const QString &text, MsgId repl } else if (webPageId) { WebPageData *page = App::webPage(webPageId); media = MTP_messageMediaWebPage(MTP_webPagePending(MTP_long(page->id), MTP_int(page->pendingTill))); + flags |= MTPDmessage::flag_media; } MTPVector localEntities = linksToMTP(textParseLinks(sendingText, itemTextParseOptions(hist, App::self()).flags)); hist->addToBack(MTP_message(MTP_int(flags), MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(hist->peer->id), MTPint(), MTPint(), MTP_int(replyTo), MTP_int(unixtime()), msgText, media, MTPnullMarkup, localEntities));