Update FullMsgId context in HistoryMedia links.

This commit is contained in:
John Preston 2017-12-18 17:13:41 +04:00
parent ddf4a36bdc
commit 546766fb13
11 changed files with 149 additions and 54 deletions

View File

@ -309,24 +309,20 @@ private:
VoiceWaveform documentWaveformDecode(const QByteArray &encoded5bit); VoiceWaveform documentWaveformDecode(const QByteArray &encoded5bit);
QByteArray documentWaveformEncode5bit(const VoiceWaveform &waveform); QByteArray documentWaveformEncode5bit(const VoiceWaveform &waveform);
class DocumentClickHandler : public LeftButtonClickHandler { class DocumentClickHandler : public FileClickHandler {
public: public:
DocumentClickHandler( DocumentClickHandler(
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context = FullMsgId()) FullMsgId context = FullMsgId())
: _document(document) : FileClickHandler(context)
, _context(context) { , _document(document) {
} }
not_null<DocumentData*> document() const { not_null<DocumentData*> document() const {
return _document; return _document;
} }
FullMsgId context() const {
return _context;
}
private: private:
not_null<DocumentData*> _document; not_null<DocumentData*> _document;
FullMsgId _context;
}; };

View File

@ -70,14 +70,14 @@ private:
}; };
class PhotoClickHandler : public LeftButtonClickHandler { class PhotoClickHandler : public FileClickHandler {
public: public:
PhotoClickHandler( PhotoClickHandler(
not_null<PhotoData*> photo, not_null<PhotoData*> photo,
FullMsgId context = FullMsgId(), FullMsgId context = FullMsgId(),
PeerData *peer = nullptr) PeerData *peer = nullptr)
: _photo(photo) : FileClickHandler(context)
, _context(context) , _photo(photo)
, _peer(peer) { , _peer(peer) {
} }
not_null<PhotoData*> photo() const { not_null<PhotoData*> photo() const {
@ -86,13 +86,9 @@ public:
PeerData *peer() const { PeerData *peer() const {
return _peer; return _peer;
} }
FullMsgId context() const {
return _context;
}
private: private:
not_null<PhotoData*> _photo; not_null<PhotoData*> _photo;
FullMsgId _context;
PeerData *_peer = nullptr; PeerData *_peer = nullptr;
}; };

View File

@ -390,3 +390,21 @@ struct SendAction {
int progress = 0; int progress = 0;
}; };
class FileClickHandler : public LeftButtonClickHandler {
public:
FileClickHandler(FullMsgId context) : _context(context) {
}
void setMessageId(FullMsgId context) {
_context = context;
}
FullMsgId context() const {
return _context;
}
private:
FullMsgId _context;
};

View File

@ -69,10 +69,13 @@ HistoryTextState::HistoryTextState(
, link(link) { , link(link) {
} }
ReplyMarkupClickHandler::ReplyMarkupClickHandler(const HistoryItem *item, int row, int col) ReplyMarkupClickHandler::ReplyMarkupClickHandler(
: _itemId(item->fullId()) int row,
int column,
FullMsgId context)
: _itemId(context)
, _row(row) , _row(row)
, _col(col) { , _column(column) {
} }
// Copy to clipboard support. // Copy to clipboard support.
@ -104,9 +107,9 @@ const HistoryMessageReplyMarkup::Button *ReplyMarkupClickHandler::getButton() co
if (auto item = App::histItemById(_itemId)) { if (auto item = App::histItemById(_itemId)) {
if (auto markup = item->Get<HistoryMessageReplyMarkup>()) { if (auto markup = item->Get<HistoryMessageReplyMarkup>()) {
if (_row < markup->rows.size()) { if (_row < markup->rows.size()) {
auto &row = markup->rows.at(_row); auto &row = markup->rows[_row];
if (_col < row.size()) { if (_column < row.size()) {
return &row.at(_col); return &row[_column];
} }
} }
} }
@ -116,7 +119,7 @@ const HistoryMessageReplyMarkup::Button *ReplyMarkupClickHandler::getButton() co
void ReplyMarkupClickHandler::onClickImpl() const { void ReplyMarkupClickHandler::onClickImpl() const {
if (auto item = App::histItemById(_itemId)) { if (auto item = App::histItemById(_itemId)) {
App::activateBotCommand(item, _row, _col); App::activateBotCommand(item, _row, _column);
} }
} }
@ -141,19 +144,27 @@ ReplyKeyboard::ReplyKeyboard(
, _a_selected(animation(this, &ReplyKeyboard::step_selected)) , _a_selected(animation(this, &ReplyKeyboard::step_selected))
, _st(std::move(s)) { , _st(std::move(s)) {
if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) { if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) {
_rows.reserve(markup->rows.size()); const auto context = _item->fullId();
for (auto i = 0, l = int(markup->rows.size()); i != l; ++i) { const auto rowCount = int(markup->rows.size());
auto &row = markup->rows.at(i); _rows.reserve(rowCount);
int s = row.size(); for (auto i = 0; i != rowCount; ++i) {
const auto &row = markup->rows.at(i);
const auto rowSize = int(row.size());
auto newRow = std::vector<Button>(); auto newRow = std::vector<Button>();
newRow.reserve(s); newRow.reserve(rowSize);
for (int j = 0; j != s; ++j) { for (auto j = 0; j != rowSize; ++j) {
auto button = Button(); auto button = Button();
auto str = row.at(j).text; const auto text = row[j].text;
button.type = row.at(j).type; button.type = row.at(j).type;
button.link = std::make_shared<ReplyMarkupClickHandler>(item, i, j); button.link = std::make_shared<ReplyMarkupClickHandler>(
button.text.setText(_st->textStyle(), TextUtilities::SingleLine(str), _textPlainOptions); i,
button.characters = str.isEmpty() ? 1 : str.size(); j,
context);
button.text.setText(
_st->textStyle(),
TextUtilities::SingleLine(text),
_textPlainOptions);
button.characters = text.isEmpty() ? 1 : text.size();
newRow.push_back(std::move(button)); newRow.push_back(std::move(button));
} }
_rows.push_back(std::move(newRow)); _rows.push_back(std::move(newRow));
@ -924,7 +935,14 @@ void HistoryItem::setId(MsgId newId) {
} }
if (_media) { if (_media) {
_media->updateMessageId(); _media->refreshParentId(this);
if (const auto group = Get<HistoryMessageGroup>()) {
if (group->leader != this) {
if (const auto media = group->leader->getMedia()) {
media->refreshParentId(group->leader);
}
}
}
} }
} }

View File

@ -269,7 +269,7 @@ private:
class ReplyMarkupClickHandler : public LeftButtonClickHandler { class ReplyMarkupClickHandler : public LeftButtonClickHandler {
public: public:
ReplyMarkupClickHandler(const HistoryItem *item, int row, int col); ReplyMarkupClickHandler(int row, int column, FullMsgId context);
QString tooltip() const override { QString tooltip() const override {
return _fullDisplayed ? QString() : buttonText(); return _fullDisplayed ? QString() : buttonText();
@ -300,7 +300,8 @@ protected:
private: private:
FullMsgId _itemId; FullMsgId _itemId;
int _row, _col; int _row = 0;
int _column = 0;
bool _fullDisplayed = true; bool _fullDisplayed = true;
// Returns the full text of the corresponding button. // Returns the full text of the corresponding button.

View File

@ -75,7 +75,7 @@ public:
return false; return false;
} }
virtual void initDimensions() = 0; virtual void initDimensions() = 0;
virtual void updateMessageId() { virtual void refreshParentId(not_null<HistoryItem*> realParent) {
} }
virtual int resizeGetHeight(int width) { virtual int resizeGetHeight(int width) {
_width = qMin(width, _maxw); _width = qMin(width, _maxw);

View File

@ -151,6 +151,13 @@ int HistoryGroupedMedia::resizeGetHeight(int width) {
return _height; return _height;
} }
void HistoryGroupedMedia::refreshParentId(
not_null<HistoryItem*> realParent) {
for (const auto &element : _elements) {
element.content->refreshParentId(element.item);
}
}
void HistoryGroupedMedia::draw( void HistoryGroupedMedia::draw(
Painter &p, Painter &p,
const QRect &clip, const QRect &clip,

View File

@ -41,6 +41,7 @@ public:
void initDimensions() override; void initDimensions() override;
int resizeGetHeight(int width) override; int resizeGetHeight(int width) override;
void refreshParentId(not_null<HistoryItem*> realParent) override;
void draw( void draw(
Painter &p, Painter &p,

View File

@ -215,14 +215,21 @@ void HistoryFileMedia::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool
} }
void HistoryFileMedia::setLinks( void HistoryFileMedia::setLinks(
ClickHandlerPtr &&openl, FileClickHandlerPtr &&openl,
ClickHandlerPtr &&savel, FileClickHandlerPtr &&savel,
ClickHandlerPtr &&cancell) { FileClickHandlerPtr &&cancell) {
_openl = std::move(openl); _openl = std::move(openl);
_savel = std::move(savel); _savel = std::move(savel);
_cancell = std::move(cancell); _cancell = std::move(cancell);
} }
void HistoryFileMedia::refreshParentId(not_null<HistoryItem*> realParent) {
const auto contextId = realParent->fullId();
_openl->setMessageId(contextId);
_savel->setMessageId(contextId);
_cancell->setMessageId(contextId);
}
void HistoryFileMedia::setStatusSize(int32 newSize, int32 fullSize, int32 duration, qint64 realDuration) const { void HistoryFileMedia::setStatusSize(int32 newSize, int32 fullSize, int32 duration, qint64 realDuration) const {
_statusSize = newSize; _statusSize = newSize;
if (_statusSize == FileStatusSizeReady) { if (_statusSize == FileStatusSizeReady) {
@ -3846,6 +3853,12 @@ int HistoryWebPage::resizeGetHeight(int width) {
return _height; return _height;
} }
void HistoryWebPage::refreshParentId(not_null<HistoryItem*> realParent) {
if (_attach) {
_attach->refreshParentId(realParent);
}
}
void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const { void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const {
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
int32 skipx = 0, skipy = 0, width = _width, height = _height; int32 skipx = 0, skipy = 0, width = _width, height = _height;
@ -4175,8 +4188,13 @@ HistoryGame::HistoryGame(
void HistoryGame::initDimensions() { void HistoryGame::initDimensions() {
auto lineHeight = unitedLineHeight(); auto lineHeight = unitedLineHeight();
if (!_openl && _parent->id > 0) { if (!_openl && IsServerMsgId(_parent->id)) {
_openl = std::make_shared<ReplyMarkupClickHandler>(_parent, 0, 0); const auto row = 0;
const auto column = 0;
_openl = std::make_shared<ReplyMarkupClickHandler>(
row,
column,
_parent->fullId());
} }
auto title = TextUtilities::SingleLine(_data->title); auto title = TextUtilities::SingleLine(_data->title);
@ -4256,9 +4274,12 @@ void HistoryGame::initDimensions() {
} }
} }
void HistoryGame::updateMessageId() { void HistoryGame::refreshParentId(not_null<HistoryItem*> realParent) {
if (_openl) { if (_openl) {
_openl = std::make_shared<ReplyMarkupClickHandler>(_parent, 0, 0); _openl->setMessageId(_parent->fullId());
}
if (_attach) {
_attach->refreshParentId(realParent);
} }
} }
@ -4758,6 +4779,12 @@ int HistoryInvoice::resizeGetHeight(int width) {
return _height; return _height;
} }
void HistoryInvoice::refreshParentId(not_null<HistoryItem*> realParent) {
if (_attach) {
_attach->refreshParentId(realParent);
}
}
void HistoryInvoice::draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const { void HistoryInvoice::draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const {
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return; if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
int32 width = _width, height = _height; int32 width = _width, height = _height;

View File

@ -63,6 +63,8 @@ public:
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
void refreshParentId(not_null<HistoryItem*> realParent) override;
bool allowsFastShare() const override { bool allowsFastShare() const override {
return true; return true;
} }
@ -70,13 +72,18 @@ public:
~HistoryFileMedia(); ~HistoryFileMedia();
protected: protected:
ClickHandlerPtr _openl, _savel, _cancell; using FileClickHandlerPtr = std::shared_ptr<FileClickHandler>;
void setLinks(ClickHandlerPtr &&openl, ClickHandlerPtr &&savel, ClickHandlerPtr &&cancell); FileClickHandlerPtr _openl, _savel, _cancell;
void setLinks(
FileClickHandlerPtr &&openl,
FileClickHandlerPtr &&savel,
FileClickHandlerPtr &&cancell);
void setDocumentLinks( void setDocumentLinks(
not_null<DocumentData*> document, not_null<DocumentData*> document,
not_null<HistoryItem*> realParent, not_null<HistoryItem*> realParent,
bool inlinegif = false) { bool inlinegif = false) {
ClickHandlerPtr open, save; FileClickHandlerPtr open, save;
const auto context = realParent->fullId(); const auto context = realParent->fullId();
if (inlinegif) { if (inlinegif) {
open = std::make_shared<GifOpenClickHandler>(document, context); open = std::make_shared<GifOpenClickHandler>(document, context);
@ -944,6 +951,7 @@ public:
void initDimensions() override; void initDimensions() override;
int resizeGetHeight(int width) override; int resizeGetHeight(int width) override;
void refreshParentId(not_null<HistoryItem*> realParent) override;
void draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const override; void draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const override;
HistoryTextState getState(QPoint point, HistoryStateRequest request) const override; HistoryTextState getState(QPoint point, HistoryStateRequest request) const override;
@ -1060,7 +1068,7 @@ public:
void initDimensions() override; void initDimensions() override;
int resizeGetHeight(int width) override; int resizeGetHeight(int width) override;
void updateMessageId() override; void refreshParentId(not_null<HistoryItem*> realParent) override;
void draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const override; void draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const override;
HistoryTextState getState(QPoint point, HistoryStateRequest request) const override; HistoryTextState getState(QPoint point, HistoryStateRequest request) const override;
@ -1148,7 +1156,7 @@ private:
int bottomInfoPadding() const; int bottomInfoPadding() const;
not_null<GameData*> _data; not_null<GameData*> _data;
ClickHandlerPtr _openl; std::shared_ptr<ReplyMarkupClickHandler> _openl;
std::unique_ptr<HistoryMedia> _attach; std::unique_ptr<HistoryMedia> _attach;
int32 _titleLines, _descriptionLines; int32 _titleLines, _descriptionLines;
@ -1181,6 +1189,7 @@ public:
void initDimensions() override; void initDimensions() override;
int resizeGetHeight(int width) override; int resizeGetHeight(int width) override;
void refreshParentId(not_null<HistoryItem*> realParent) override;
MsgId getReceiptMsgId() const { MsgId getReceiptMsgId() const {
return _receiptMsgId; return _receiptMsgId;

View File

@ -357,9 +357,15 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
auto computeGameTitle = [gamescore, &result]() -> QString { auto computeGameTitle = [gamescore, &result]() -> QString {
if (gamescore && gamescore->msg) { if (gamescore && gamescore->msg) {
if (auto media = gamescore->msg->getMedia()) { if (const auto media = gamescore->msg->getMedia()) {
if (media->type() == MediaTypeGame) { if (media->type() == MediaTypeGame) {
result.links.push_back(std::make_shared<ReplyMarkupClickHandler>(gamescore->msg, 0, 0)); const auto row = 0;
const auto column = 0;
result.links.push_back(
std::make_shared<ReplyMarkupClickHandler>(
row,
column,
gamescore->msg->fullId()));
auto titleText = static_cast<HistoryGame*>(media)->game()->title; auto titleText = static_cast<HistoryGame*>(media)->game()->title;
return textcmdLink(result.links.size(), titleText); return textcmdLink(result.links.size(), titleText);
} }
@ -371,21 +377,37 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
return QString(); return QString();
}; };
auto scoreNumber = gamescore ? gamescore->score : 0; const auto scoreNumber = gamescore ? gamescore->score : 0;
if (_from->isSelf()) { if (_from->isSelf()) {
auto gameTitle = computeGameTitle(); auto gameTitle = computeGameTitle();
if (gameTitle.isEmpty()) { if (gameTitle.isEmpty()) {
result.text = lng_action_game_you_scored_no_game(lt_count, scoreNumber); result.text = lng_action_game_you_scored_no_game(
lt_count,
scoreNumber);
} else { } else {
result.text = lng_action_game_you_scored(lt_count, scoreNumber, lt_game, gameTitle); result.text = lng_action_game_you_scored(
lt_count,
scoreNumber,
lt_game,
gameTitle);
} }
} else { } else {
result.links.push_back(fromLink()); result.links.push_back(fromLink());
auto gameTitle = computeGameTitle(); auto gameTitle = computeGameTitle();
if (gameTitle.isEmpty()) { if (gameTitle.isEmpty()) {
result.text = lng_action_game_score_no_game(lt_count, scoreNumber, lt_from, fromLinkText()); result.text = lng_action_game_score_no_game(
lt_count,
scoreNumber,
lt_from,
fromLinkText());
} else { } else {
result.text = lng_action_game_score(lt_count, scoreNumber, lt_from, fromLinkText(), lt_game, gameTitle); result.text = lng_action_game_score(
lt_count,
scoreNumber,
lt_from,
fromLinkText(),
lt_game,
gameTitle);
} }
} }
return result; return result;