Various fixes.

Copy inline keyboard when forwarding messages with a game.
Don't show "Deleted Message" in service message with scores.
Improved tiny web page previews. Ignore right button in emoji panel.
This commit is contained in:
John Preston 2016-10-07 10:58:34 +03:00
parent 16ce28f4d2
commit eb47b9468c
9 changed files with 104 additions and 38 deletions

View File

@ -590,6 +590,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_action_pinned_media_game" = "the game «{game}»";
"lng_action_game_score" = "{from} scored {count:#|#|#} in {game}";
"lng_action_game_you_scored" = "You scored {count:#|#|#} in {game}";
"lng_action_game_score_no_game" = "{from} scored {count:#|#|#}";
"lng_action_game_you_scored_no_game" = "You scored {count:#|#|#}";
"lng_profile_migrate_reached" = "{count:_not_used_|# member|# members} limit reached";
"lng_profile_migrate_body" = "To get over this limit, you can upgrade your group to a supergroup.";

View File

@ -359,7 +359,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows(const QVector<MTPKeyboardBu
if (!b.isEmpty()) {
ButtonRow buttonRow;
buttonRow.reserve(b.size());
for_const (const auto &button, b) {
for_const (auto &button, b) {
switch (button.type()) {
case mtpc_keyboardButton: {
buttonRow.push_back({ Button::Type::Default, qs(button.c_keyboardButton().vtext), QByteArray(), 0 });
@ -408,31 +408,46 @@ void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) {
switch (markup.type()) {
case mtpc_replyKeyboardMarkup: {
const auto &d(markup.c_replyKeyboardMarkup());
auto &d = markup.c_replyKeyboardMarkup();
flags = d.vflags.v;
createFromButtonRows(d.vrows.c_vector().v);
} break;
case mtpc_replyInlineMarkup: {
const auto &d(markup.c_replyInlineMarkup());
auto &d = markup.c_replyInlineMarkup();
flags = MTPDreplyKeyboardMarkup::Flags(0) | MTPDreplyKeyboardMarkup_ClientFlag::f_inline;
createFromButtonRows(d.vrows.c_vector().v);
} break;
case mtpc_replyKeyboardHide: {
const auto &d(markup.c_replyKeyboardHide());
auto &d = markup.c_replyKeyboardHide();
flags = mtpCastFlags(d.vflags) | MTPDreplyKeyboardMarkup_ClientFlag::f_zero;
} break;
case mtpc_replyKeyboardForceReply: {
const auto &d(markup.c_replyKeyboardForceReply());
auto &d = markup.c_replyKeyboardForceReply();
flags = mtpCastFlags(d.vflags) | MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
} break;
}
}
void HistoryMessageReplyMarkup::create(const HistoryMessageReplyMarkup &markup) {
flags = markup.flags;
inlineKeyboard = nullptr;
rows.clear();
for_const (auto &row, markup.rows) {
ButtonRow buttonRow;
buttonRow.reserve(row.size());
for_const (auto &button, row) {
buttonRow.push_back({ button.type, button.text, button.data, 0 });
}
if (!buttonRow.isEmpty()) rows.push_back(buttonRow);
}
}
void HistoryMessageUnreadBar::init(int count) {
if (_freezed) return;
_text = lng_unread_bar(lt_count, count);

View File

@ -199,6 +199,7 @@ struct HistoryMessageReplyMarkup : public RuntimeComponent<HistoryMessageReplyMa
}
void create(const MTPReplyMarkup &markup);
void create(const HistoryMessageReplyMarkup &markup);
struct Button {
enum class Type {
@ -758,13 +759,13 @@ public:
}
PeerData *fromOriginal() const {
if (const HistoryMessageForwarded *fwd = Get<HistoryMessageForwarded>()) {
if (auto fwd = Get<HistoryMessageForwarded>()) {
return fwd->_fromOriginal;
}
return from();
}
PeerData *authorOriginal() const {
if (const HistoryMessageForwarded *fwd = Get<HistoryMessageForwarded>()) {
if (auto fwd = Get<HistoryMessageForwarded>()) {
return fwd->_authorOriginal;
}
return author();
@ -898,6 +899,12 @@ protected:
void recountAttachToPrevious();
const HistoryMessageReplyMarkup *inlineReplyMarkup() const {
return const_cast<HistoryItem*>(this)->inlineReplyMarkup();
}
const ReplyKeyboard *inlineReplyKeyboard() const {
return const_cast<HistoryItem*>(this)->inlineReplyKeyboard();
}
HistoryMessageReplyMarkup *inlineReplyMarkup() {
if (auto markup = Get<HistoryMessageReplyMarkup>()) {
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) {
return markup;
@ -905,18 +912,12 @@ protected:
}
return nullptr;
}
const ReplyKeyboard *inlineReplyKeyboard() const {
ReplyKeyboard *inlineReplyKeyboard() {
if (auto markup = inlineReplyMarkup()) {
return markup->inlineKeyboard.get();
}
return nullptr;
}
HistoryMessageReplyMarkup *inlineReplyMarkup() {
return const_cast<HistoryMessageReplyMarkup*>(static_cast<const HistoryItem*>(this)->inlineReplyMarkup());
}
ReplyKeyboard *inlineReplyKeyboard() {
return const_cast<ReplyKeyboard*>(static_cast<const HistoryItem*>(this)->inlineReplyKeyboard());
}
TextSelection toMediaSelection(TextSelection selection) const {
return internal::unshiftSelection(selection, _text);

View File

@ -2562,7 +2562,7 @@ int HistoryWebPage::resizeGetHeight(int width) {
return _height;
}
_width = width = qMin(width, _maxw);
_width = width/* = qMin(width, _maxw)*/;
width -= st::msgPadding.left() + st::webPageLeft + st::msgPadding.right();
int32 linesMax = 5;
@ -2686,9 +2686,9 @@ void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, u
} else {
pix = _data->photo->thumb->pixBlurredSingle(ImageRoundRadius::Small, pixw, pixh, pw, ph);
}
p.drawPixmapLeft(padding.left() + width - pw, 0, _width, pix);
p.drawPixmapLeft(padding.left() + width - pw, tshift, _width, pix);
if (selected) {
App::roundRect(p, rtlrect(padding.left() + width - pw, 0, pw, _pixh, _width), textstyleCurrent()->selectOverlay, SelectedOverlaySmallCorners);
App::roundRect(p, rtlrect(padding.left() + width - pw, tshift, pw, _pixh, _width), textstyleCurrent()->selectOverlay, SelectedOverlaySmallCorners);
}
width -= pw + st::webPagePhotoDelta;
}

View File

@ -366,7 +366,7 @@ HistoryMessage::HistoryMessage(History *history, const MTPDmessage &msg)
CreateConfig config;
if (msg.has_fwd_from() && msg.vfwd_from.type() == mtpc_messageFwdHeader) {
const auto &f(msg.vfwd_from.c_messageFwdHeader());
auto &f = msg.vfwd_from.c_messageFwdHeader();
if (f.has_from_id() || f.has_channel_id()) {
config.authorIdOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id);
config.fromIdOriginal = f.has_from_id() ? peerFromUser(f.vfrom_id) : peerFromChannel(f.vchannel_id);
@ -376,7 +376,7 @@ HistoryMessage::HistoryMessage(History *history, const MTPDmessage &msg)
if (msg.has_reply_to_msg_id()) config.replyTo = msg.vreply_to_msg_id.v;
if (msg.has_via_bot_id()) config.viaBotId = msg.vvia_bot_id.v;
if (msg.has_views()) config.viewsCount = msg.vviews.v;
if (msg.has_reply_markup()) config.markup = &msg.vreply_markup;
if (msg.has_reply_markup()) config.mtpMarkup = &msg.vreply_markup;
if (msg.has_edit_date()) config.editDate = ::date(msg.vedit_date);
createComponents(config);
@ -435,9 +435,15 @@ HistoryMessage::HistoryMessage(History *history, MsgId id, MTPDmessage::Flags fl
config.viewsCount = 1;
}
// Copy inline keyboard when forwarding messages with a game.
auto mediaOriginal = fwd->getMedia();
if (mediaOriginal && mediaOriginal->type() == MediaTypeGame) {
config.inlineMarkup = fwd->inlineReplyMarkup();
}
createComponents(config);
if (HistoryMedia *mediaOriginal = fwd->getMedia()) {
if (mediaOriginal) {
_media.reset(mediaOriginal->clone(this));
}
setText(fwd->originalText());
@ -479,7 +485,7 @@ void HistoryMessage::createComponentsHelper(MTPDmessage::Flags flags, MsgId repl
if (flags & MTPDmessage::Flag::f_via_bot_id) config.viaBotId = viaBotId;
if (flags & MTPDmessage::Flag::f_reply_to_msg_id) config.replyTo = replyTo;
if (flags & MTPDmessage::Flag::f_reply_markup) config.markup = &markup;
if (flags & MTPDmessage::Flag::f_reply_markup) config.mtpMarkup = &markup;
if (isPost()) config.viewsCount = 1;
createComponents(config);
@ -518,8 +524,10 @@ void HistoryMessage::updateMediaInBubbleState() {
_media->setInBubbleState(computeState());
}
bool HistoryMessage::displayEditedBadge(bool hasViaBot) const {
if (!(_flags & MTPDmessage::Flag::f_edit_date)) {
bool HistoryMessage::displayEditedBadge(bool hasViaBotOrInlineMarkup) const {
if (hasViaBotOrInlineMarkup) {
return false;
} else if (!(_flags & MTPDmessage::Flag::f_edit_date)) {
return false;
}
if (auto fromUser = from()->asUser()) {
@ -527,9 +535,6 @@ bool HistoryMessage::displayEditedBadge(bool hasViaBot) const {
return false;
}
}
if (hasViaBot) {
return false;
}
return true;
}
@ -548,20 +553,31 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
if (isPost() && _from->isUser()) {
mask |= HistoryMessageSigned::Bit();
}
if (displayEditedBadge(config.viaBotId != 0)) {
auto hasViaBot = (config.viaBotId != 0);
auto hasInlineMarkup = [&config] {
if (config.mtpMarkup) {
return (config.mtpMarkup->type() == mtpc_replyInlineMarkup);
}
return (config.inlineMarkup != nullptr);
};
if (displayEditedBadge(hasViaBot || hasInlineMarkup())) {
mask |= HistoryMessageEdited::Bit();
}
if (config.authorIdOriginal && config.fromIdOriginal) {
mask |= HistoryMessageForwarded::Bit();
}
if (config.markup) {
if (config.mtpMarkup) {
// optimization: don't create markup component for the case
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
if (config.markup->type() != mtpc_replyKeyboardHide || config.markup->c_replyKeyboardHide().vflags.v != 0) {
if (config.mtpMarkup->type() != mtpc_replyKeyboardHide || config.mtpMarkup->c_replyKeyboardHide().vflags.v != 0) {
mask |= HistoryMessageReplyMarkup::Bit();
}
} else if (config.inlineMarkup) {
mask |= HistoryMessageReplyMarkup::Bit();
}
UpdateComponents(mask);
if (auto reply = Get<HistoryMessageReply>()) {
reply->replyToMsgId = config.replyTo;
if (!reply->updateData(this) && App::api()) {
@ -586,7 +602,11 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
fwd->_originalId = config.originalId;
}
if (auto markup = Get<HistoryMessageReplyMarkup>()) {
markup->create(*config.markup);
if (config.mtpMarkup) {
markup->create(*config.mtpMarkup);
} else if (config.inlineMarkup) {
markup->create(*config.inlineMarkup);
}
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button) {
_flags |= MTPDmessage_ClientFlag::f_has_switch_inline_button;
}
@ -829,7 +849,9 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
if (message.has_edit_date()) {
_flags |= MTPDmessage::Flag::f_edit_date;
if (displayEditedBadge(Has<HistoryMessageVia>())) {
auto hasViaBotId = Has<HistoryMessageVia>();
auto hasInlineMarkup = (inlineReplyMarkup() != nullptr);
if (displayEditedBadge(hasViaBotId || hasInlineMarkup)) {
if (!Has<HistoryMessageEdited>()) {
AddComponents(HistoryMessageEdited::Bit());
}
@ -2009,13 +2031,21 @@ bool HistoryService::prepareGameScoreText(const QString &from, QString *outText,
gameTitle = lang(lng_contacts_loading);
result = true;
} else {
gameTitle = lang(lng_deleted_message);
gameTitle = QString();
}
auto scoreNumber = gamescore ? gamescore->score : 0;
if (_from->isSelf()) {
*outText = lng_action_game_you_scored(lt_count, scoreNumber, lt_game, gameTitle);
if (gameTitle.isEmpty()) {
*outText = lng_action_game_you_scored_no_game(lt_count, scoreNumber);
} else {
*outText = lng_action_game_you_scored(lt_count, scoreNumber, lt_game, gameTitle);
}
} else {
*outText = lng_action_game_score(lt_from, from, lt_count, scoreNumber, lt_game, gameTitle);
if (gameTitle.isEmpty()) {
*outText = lng_action_game_score_no_game(lt_from, from, lt_count, scoreNumber);
} else {
*outText = lng_action_game_score(lt_from, from, lt_count, scoreNumber, lt_game, gameTitle);
}
}
if (second) {
outLinks->push_back(second);

View File

@ -63,7 +63,7 @@ public:
return (!emptyText() || !_media || !_media->isDisplayed() || Has<HistoryMessageReply>() || Has<HistoryMessageForwarded>() || viaBot() || !_media->hideFromName());
}
bool displayEditedBadge(bool hasViaBot) const;
bool displayEditedBadge(bool hasViaBotOrInlineMarkup) const;
bool uploading() const {
return _media && _media->uploading();
}
@ -191,7 +191,12 @@ private:
PeerId fromIdOriginal = 0;
MsgId originalId = 0;
QDateTime editDate;
const MTPReplyMarkup *markup = nullptr;
// For messages created from MTP structs.
const MTPReplyMarkup *mtpMarkup = nullptr;
// For messages created from existing messages (forwarded).
const HistoryMessageReplyMarkup *inlineMarkup = nullptr;
};
void createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, const MTPReplyMarkup &markup);
void createComponents(const CreateConfig &config);

View File

@ -31,6 +31,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "mainwidget.h"
#include "mainwindow.h"
#include "lang.h"
#include "application.h"
#include "playerwidget.h"
#include "apiwrap.h"
@ -1078,6 +1079,9 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version) {
if (!_checkStreamStatus(stream)) return false;
cSetAutoUpdate(v == 1);
if (!cAutoUpdate()) {
Sandbox::stopUpdate();
}
} break;
case dbiLastUpdateCheck: {

View File

@ -193,6 +193,9 @@ void GeneralWidget::refreshControls() {
style::margins marginLink(st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip);
addChildRow(_updateRow, marginLink, slidedPadding);
connect(_updateRow->entity(), SIGNAL(restart()), this, SLOT(onRestart()));
if (!cAutoUpdate()) {
_updateRow->hideFast();
}
#endif // TDESKTOP_DISABLE_AUTOUPDATE
if (cPlatform() == dbipWindows || cSupportTray()) {

View File

@ -116,6 +116,9 @@ void EmojiColorPicker::leaveEvent(QEvent *e) {
}
void EmojiColorPicker::mousePressEvent(QMouseEvent *e) {
if (e->button() != Qt::LeftButton) {
return;
}
_lastMousePos = e->globalPos();
updateSelected();
_pressedSel = _selected;
@ -411,7 +414,7 @@ bool EmojiPanInner::checkPickerHide() {
void EmojiPanInner::mousePressEvent(QMouseEvent *e) {
_lastMousePos = e->globalPos();
updateSelected();
if (checkPickerHide()) {
if (checkPickerHide() || e->button() != Qt::LeftButton) {
return;
}
_pressedSel = _selected;
@ -1160,6 +1163,9 @@ QRect StickerPanInner::featuredAddRect(int index) const {
}
void StickerPanInner::mousePressEvent(QMouseEvent *e) {
if (e->button() != Qt::LeftButton) {
return;
}
_lastMousePos = e->globalPos();
updateSelected();
@ -2895,7 +2901,7 @@ void EmojiPan::otherLeave() {
}
void EmojiPan::mousePressEvent(QMouseEvent *e) {
if (!_stickersShown) return;
if (!_stickersShown || e->button() != Qt::LeftButton) return;
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
updateSelected();