Fix switch button in outgoing msgs with keyboards.

Inline bot results panel behaviour improved.
Sent and deleted from hard drive GIFs now auto-re-download.
This commit is contained in:
John Preston 2016-04-20 15:27:38 +03:00
parent 10bd2b680d
commit 5caceefc2c
4 changed files with 65 additions and 41 deletions

View file

@ -2552,7 +2552,15 @@ void EmojiPanel::updateText() {
availw -= st::notifyClose.icon.pxWidth() + st::emojiPanHeaderLeft;
}
} else {
QString switchText = lang((_setId != Stickers::NoneSetId) ? lng_switch_emoji : (cSavedGifs().isEmpty() ? lng_switch_stickers : lng_switch_stickers_gifs));
auto switchText = ([this]() {
if (_setId != Stickers::NoneSetId) {
return lang(lng_switch_emoji);
}
if (cSavedGifs().isEmpty()) {
return lang(lng_switch_stickers);
}
return lang(lng_switch_stickers_gifs);
})();
availw -= st::emojiSwitchSkip + st::emojiPanHeaderFont->width(switchText);
}
_text = st::emojiPanHeaderFont->elided(_fullText, availw);
@ -2719,10 +2727,10 @@ EmojiPan::EmojiPan(QWidget *parent) : TWidget(parent)
connect(&e_inner, SIGNAL(disableScroll(bool)), &e_scroll, SLOT(disableScroll(bool)));
connect(&s_inner, SIGNAL(scrollToY(int)), &s_scroll, SLOT(scrollToY(int)));
connect(&s_inner, SIGNAL(scrollUpdated()), this, SLOT(onScroll()));
connect(&s_inner, SIGNAL(scrollUpdated()), this, SLOT(onScrollStickers()));
connect(&e_scroll, SIGNAL(scrolled()), this, SLOT(onScroll()));
connect(&s_scroll, SIGNAL(scrolled()), this, SLOT(onScroll()));
connect(&e_scroll, SIGNAL(scrolled()), this, SLOT(onScrollEmoji()));
connect(&s_scroll, SIGNAL(scrolled()), this, SLOT(onScrollStickers()));
connect(&e_inner, SIGNAL(selected(EmojiPtr)), this, SIGNAL(emojiSelected(EmojiPtr)));
connect(&s_inner, SIGNAL(selected(DocumentData*)), this, SIGNAL(stickerSelected(DocumentData*)));
@ -3503,39 +3511,42 @@ void EmojiPan::updatePanelsPositions(const QVector<internal::EmojiPanel*> &panel
}
}
void EmojiPan::onScroll() {
int st = e_scroll.scrollTop();
if (!_stickersShown) {
updatePanelsPositions(e_panels, st);
void EmojiPan::onScrollEmoji() {
auto st = e_scroll.scrollTop();
DBIEmojiTab tab = e_inner.currentTab(st);
FlatRadiobutton *check = 0;
switch (tab) {
case dbietRecent : check = &_recent ; break;
case dbietPeople : check = &_people ; break;
case dbietNature : check = &_nature ; break;
case dbietFood : check = &_food ; break;
case dbietActivity: check = &_activity; break;
case dbietTravel : check = &_travel ; break;
case dbietObjects : check = &_objects ; break;
case dbietSymbols : check = &_symbols ; break;
}
if (check && !check->checked()) {
_noTabUpdate = true;
check->setChecked(true);
_noTabUpdate = false;
}
updatePanelsPositions(e_panels, st);
auto tab = e_inner.currentTab(st);
FlatRadiobutton *check = nullptr;
switch (tab) {
case dbietRecent: check = &_recent; break;
case dbietPeople: check = &_people; break;
case dbietNature: check = &_nature; break;
case dbietFood: check = &_food; break;
case dbietActivity: check = &_activity; break;
case dbietTravel: check = &_travel; break;
case dbietObjects: check = &_objects; break;
case dbietSymbols: check = &_symbols; break;
}
if (check && !check->checked()) {
_noTabUpdate = true;
check->setChecked(true);
_noTabUpdate = false;
}
e_inner.setScrollTop(st);
}
st = s_scroll.scrollTop();
if (_stickersShown) {
updatePanelsPositions(s_panels, st);
validateSelectedIcon(true);
if (st + s_scroll.height() > s_scroll.scrollTopMax()) {
onInlineRequest();
}
void EmojiPan::onScrollStickers() {
auto st = s_scroll.scrollTop();
updatePanelsPositions(s_panels, st);
validateSelectedIcon(true);
if (st + s_scroll.height() > s_scroll.scrollTopMax()) {
onInlineRequest();
}
s_inner.setScrollTop(st);
}
@ -3699,7 +3710,7 @@ void EmojiPan::inlineResultsDone(const MTPmessages_BotResults &result) {
_inlineRequestId = 0;
Notify::inlineBotRequesting(false);
InlineCache::iterator it = _inlineCache.find(_inlineQuery);
auto it = _inlineCache.find(_inlineQuery);
bool adding = (it != _inlineCache.cend());
if (result.type() == mtpc_messages_botResults) {
@ -3738,7 +3749,7 @@ void EmojiPan::inlineResultsDone(const MTPmessages_BotResults &result) {
if (!showInlineRows(!adding)) {
it.value()->nextOffset = QString();
}
onScroll();
onScrollStickers();
}
bool EmojiPan::inlineResultsFail(const RPCError &error) {
@ -3771,7 +3782,7 @@ void EmojiPan::queryInlineBot(UserData *bot, PeerData *peer, QString query) {
}
if (_inlineCache.contains(query)) {
_inlineRequestTimer.stop();
_inlineQuery = query;
_inlineQuery = _inlineNextQuery = query;
showInlineRows(true);
} else {
_inlineNextQuery = query;
@ -3798,6 +3809,7 @@ void EmojiPan::onInlineRequest() {
void EmojiPan::onEmptyInlineRows() {
if (_shownFromInlineQuery || hideOnNoInlineResults()) {
hideAnimated();
s_inner.clearInlineRowsPanel();
} else if (!_inlineBot) {
s_inner.hideInlineRowsPanel();
} else {
@ -3825,7 +3837,7 @@ int32 EmojiPan::showInlineRows(bool newResults) {
bool clear = !refreshInlineRows(&added);
if (newResults) s_scroll.scrollToY(0);
e_switch.updateText(clear ? QString() : _inlineBot->username);
e_switch.updateText(s_inner.inlineResultsShown() ? _inlineBot->username : QString());
e_switch.moveToRight(0, 0, st::emojiPanWidth);
bool hidden = isHidden();

View file

@ -629,7 +629,8 @@ public slots:
void onWndActiveChanged();
void onTabChange();
void onScroll();
void onScrollEmoji();
void onScrollStickers();
void onSwitch();
void onRemoveSet(quint64 setId);

View file

@ -88,8 +88,16 @@ void activateBotCommand(const HistoryItem *msg, int row, int col) {
} break;
case HistoryMessageReplyMarkup::Button::SwitchInline: {
if (MainWidget *m = App::main()) {
if (UserData *bot = msg->history()->peer->asUser()) {
if (auto m = App::main()) {
auto getMessageBot = [msg]() -> UserData* {
if (auto bot = msg->viaBot()) {
return bot;
} else if (auto bot = msg->history()->peer->asUser()) {
return bot;
}
return nullptr;
};
if (auto bot = getMessageBot()) {
auto tryFastSwitch = [bot, &button]() -> bool {
if (bot->botInfo && bot->botInfo->inlineReturnPeerId) {
if (Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data))) {

View file

@ -4979,7 +4979,7 @@ ImagePtr HistoryGif::replyPreview() {
bool HistoryGif::playInline(bool autoplay) {
if (gif()) {
stopInline();
} else {
} else if (_data->loaded(DocumentData::FilePathResolveChecked)) {
if (!cAutoPlayGif()) {
App::stopGifItems();
}
@ -7635,12 +7635,15 @@ int HistoryMessage::performResizeGetHeight(int width) {
}
if (reply) {
int32 l = 0, w = 0;
countPositionAndSize(l, w);
if (emptyText() && !displayFromName() && !Has<HistoryMessageVia>()) {
_height += st::msgPadding.top() + st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom() + st::mediaHeaderSkip;
} else {
_height += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
}
reply->resize(width - st::msgPadding.left() - st::msgPadding.right());
reply->resize(w - st::msgPadding.left() - st::msgPadding.right());
}
} else {
_height = _media->resizeGetHeight(width);