Some bugfixes. Closed beta 9040127.

Crash fix when trying to reply to a bot message which hides the keyboard.
Counting button widths better (more padding, use exact width when avail).
Hiding inline bot results fixed when switched to emoji before hiding.
This commit is contained in:
John Preston 2016-04-11 00:59:07 +04:00
parent 460e2ec0ac
commit 418e06052c
11 changed files with 60 additions and 39 deletions

View File

@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
static const int32 AppVersion = 9040;
static const wchar_t *AppVersionStr = L"0.9.40";
static const bool DevVersion = false;
#define BETA_VERSION (9040126ULL) // just comment this line to build public version
#define BETA_VERSION (9040127ULL) // just comment this line to build public version
static const wchar_t *AppNameOld = L"Telegram Win (Unofficial)";
static const wchar_t *AppName = L"Telegram Desktop";

View File

@ -3835,7 +3835,7 @@ int32 EmojiPan::showInlineRows(bool newResults) {
if (clear) {
if (!hidden && hideOnNoInlineResults()) {
hideAnimated();
} else {
} else if (!_hiding) {
_cache = QPixmap(); // clear after refreshInlineRows()
}
} else {

View File

@ -87,7 +87,17 @@ namespace App {
case HistoryMessageReplyMarkup::Button::SwitchInline: {
if (MainWidget *m = App::main()) {
if (UserData *bot = msg->history()->peer->asUser()) {
m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data));
auto tryFastSwitch = [bot, &button]() -> bool {
if (bot->botInfo && bot->botInfo->inlineReturnPeerId) {
if (Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data))) {
return true;
}
}
return false;
};
if (!tryFastSwitch()) {
m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data));
}
}
}
} break;
@ -280,10 +290,11 @@ namespace Notify {
}
}
void switchInlineBotButtonReceived(const QString &query) {
bool switchInlineBotButtonReceived(const QString &query) {
if (MainWidget *m = App::main()) {
m->notify_switchInlineBotButtonReceived(query);
return m->notify_switchInlineBotButtonReceived(query);
}
return false;
}
void migrateUpdated(PeerData *peer) {

View File

@ -104,7 +104,7 @@ namespace Notify {
void inlineBotRequesting(bool requesting);
void replyMarkupUpdated(const HistoryItem *item);
void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop);
void switchInlineBotButtonReceived(const QString &query);
bool switchInlineBotButtonReceived(const QString &query);
void migrateUpdated(PeerData *peer);

View File

@ -2574,16 +2574,20 @@ void ReplyKeyboard::resize(int width, int height) {
for (ButtonRow &row : _rows) {
int s = row.size();
float64 widthForText = _width - ((s - 1) * _st->buttonSkip() + s * 2 * _st->buttonPadding()), widthOfText = 0.;
int widthForText = _width - ((s - 1) * _st->buttonSkip());
int widthOfText = 0;
for_const (const Button &button, row) {
widthOfText += qMax(button.text.maxWidth(), 1);
widthForText -= _st->minButtonWidth(button.type);
}
bool exact = (widthForText == widthOfText);
float64 x = 0, coef = widthForText / widthOfText;
float64 x = 0;
for (Button &button : row) {
float64 tw = widthForText / float64(s), w = 2 * _st->buttonPadding() + tw;
int buttonw = qMax(button.text.maxWidth(), 1);
float64 textw = exact ? buttonw : (widthForText / float64(s));
float64 minw = _st->minButtonWidth(button.type);
if (w < minw) w = minw;
float64 w = minw + qMax(textw, 0.);
int rectx = static_cast<int>(std::floor(x));
int rectw = static_cast<int>(std::floor(x + w)) - rectx;
@ -2591,7 +2595,7 @@ void ReplyKeyboard::resize(int width, int height) {
if (rtl()) button.rect.setX(_width - button.rect.x() - button.rect.width());
x += w + _st->buttonSkip();
button.link->setFullDisplayed(tw >= button.text.maxWidth());
button.link->setFullDisplayed(textw >= buttonw);
}
y += buttonHeight;
}
@ -2625,9 +2629,9 @@ int ReplyKeyboard::naturalWidth() const {
auto markup = _item->Get<HistoryMessageReplyMarkup>();
for_const (const ButtonRow &row, _rows) {
int rowSize = row.size();
int rowWidth = (rowSize - 1) * _st->buttonSkip() + rowSize * 2 * _st->buttonPadding();
for_const(const Button &button, row) {
rowWidth += qMax(button.text.maxWidth(), 1);
int rowWidth = (rowSize - 1) * _st->buttonSkip();
for_const (const Button &button, row) {
rowWidth += qMax(button.text.maxWidth(), 1) + _st->minButtonWidth(button.type);
}
if (rowWidth > result) {
result = rowWidth;
@ -2753,7 +2757,7 @@ void ReplyKeyboard::Style::paintButton(Painter &p, const ReplyKeyboard::Button &
}
int tx = rect.x(), tw = rect.width();
if (tw > st::botKbFont->elidew + _st->padding * 2) {
if (tw >= st::botKbFont->elidew + _st->padding * 2) {
tx += _st->padding;
tw -= _st->padding * 2;
} else if (tw > st::botKbFont->elidew) {
@ -6510,7 +6514,7 @@ int HistoryMessage::KeyboardStyle::minButtonWidth(HistoryMessageReplyMarkup::But
case Button::Callback: iconWidth = st::msgInvSendingImg.pxWidth(); break;
}
if (iconWidth > 0) {
result = std::min(result, iconWidth + 2 * int(st::msgBotKbIconPadding));
result = std::max(result, 2 * iconWidth + 4 * int(st::msgBotKbIconPadding));
}
return result;
}

View File

@ -2265,12 +2265,17 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) {
_wasForMsgId = FullMsgId(to->channelId(), to->id);
clearSelection();
auto markup = to->Get<HistoryMessageReplyMarkup>();
_forceReply = markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
_maximizeSize = !(markup->flags & MTPDreplyKeyboardMarkup::Flag::f_resize);
_singleUse = _forceReply || (markup->flags & MTPDreplyKeyboardMarkup::Flag::f_single_use);
auto markupFlags = to->replyKeyboardFlags();
_forceReply = markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
_maximizeSize = !(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_resize);
_singleUse = _forceReply || (markupFlags & MTPDreplyKeyboardMarkup::Flag::f_single_use);
_impl.reset(markup->rows.isEmpty() ? nullptr : new ReplyKeyboard(to, std_::make_unique<Style>(this, *_st)));
_impl = nullptr;
if (auto markup = to->Get<HistoryMessageReplyMarkup>()) {
if (!markup->rows.isEmpty()) {
_impl.reset(new ReplyKeyboard(to, std_::make_unique<Style>(this, *_st)));
}
}
updateStyle();
_height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0);
@ -3229,23 +3234,24 @@ void HistoryWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldK
}
}
void HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query) {
if (!_peer) {
return;
}
if (UserData *bot = _peer->asUser()) {
if (!bot->botInfo || !bot->botInfo->inlineReturnPeerId) {
return;
bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query) {
if (UserData *bot = _peer ? _peer->asUser() : nullptr) {
PeerId toPeerId = bot->botInfo ? bot->botInfo->inlineReturnPeerId : 0;
if (!toPeerId) {
return false;
}
History *h = App::history(bot->botInfo->inlineReturnPeerId);
bot->botInfo->inlineReturnPeerId = 0;
History *h = App::history(toPeerId);
auto text = '@' + bot->username + ' ' + query;
h->setMsgDraft(std_::make_unique<HistoryDraft>(text, 0, MessageCursor(text.size(), text.size(), QFIXED_MAX), false));
if (h == _history) {
applyDraft();
} else {
Ui::showPeerHistory(bot->botInfo->inlineReturnPeerId, ShowAtUnreadMsgId);
Ui::showPeerHistory(toPeerId, ShowAtUnreadMsgId);
}
return true;
}
return false;
}
void HistoryWidget::notify_userIsBotChanged(UserData *user) {

View File

@ -685,7 +685,7 @@ public:
void notify_inlineBotRequesting(bool requesting);
void notify_replyMarkupUpdated(const HistoryItem *item);
void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop);
void notify_switchInlineBotButtonReceived(const QString &query);
bool notify_switchInlineBotButtonReceived(const QString &query);
void notify_userIsBotChanged(UserData *user);
void notify_migrateUpdated(PeerData *peer);
void notify_clipStopperHidden(ClipStopperType type);

View File

@ -780,8 +780,8 @@ void MainWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyb
history.notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop);
}
void MainWidget::notify_switchInlineBotButtonReceived(const QString &query) {
history.notify_switchInlineBotButtonReceived(query);
bool MainWidget::notify_switchInlineBotButtonReceived(const QString &query) {
return history.notify_switchInlineBotButtonReceived(query);
}
void MainWidget::notify_userIsBotChanged(UserData *bot) {

View File

@ -459,7 +459,7 @@ public:
void notify_inlineBotRequesting(bool requesting);
void notify_replyMarkupUpdated(const HistoryItem *item);
void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop);
void notify_switchInlineBotButtonReceived(const QString &query);
bool notify_switchInlineBotButtonReceived(const QString &query);
void notify_userIsBotChanged(UserData *bot);
void notify_userIsContactChanged(UserData *user, bool fromThisApp);
void notify_migrateUpdated(PeerData *peer);

View File

@ -34,8 +34,8 @@ IDI_ICON1 ICON "Resources\\art\\icon256.ico"
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,9,40,126
PRODUCTVERSION 0,9,40,126
FILEVERSION 0,9,40,127
PRODUCTVERSION 0,9,40,127
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -51,10 +51,10 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Telegram Messenger LLP"
VALUE "FileVersion", "0.9.40.126"
VALUE "FileVersion", "0.9.40.127"
VALUE "LegalCopyright", "Copyright (C) 2014-2016"
VALUE "ProductName", "Telegram Desktop"
VALUE "ProductVersion", "0.9.40.126"
VALUE "ProductVersion", "0.9.40.127"
END
END
BLOCK "VarFileInfo"

View File

@ -3,4 +3,4 @@ AppVersionStrMajor 0.9
AppVersionStrSmall 0.9.40
AppVersionStr 0.9.40
DevChannel 0
BetaVersion 9040126
BetaVersion 9040127