mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Update FullMsgId context in HistoryMedia links.
This commit is contained in:
parent
ddf4a36bdc
commit
546766fb13
11 changed files with 149 additions and 54 deletions
|
@ -309,24 +309,20 @@ private:
|
|||
VoiceWaveform documentWaveformDecode(const QByteArray &encoded5bit);
|
||||
QByteArray documentWaveformEncode5bit(const VoiceWaveform &waveform);
|
||||
|
||||
class DocumentClickHandler : public LeftButtonClickHandler {
|
||||
class DocumentClickHandler : public FileClickHandler {
|
||||
public:
|
||||
DocumentClickHandler(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context = FullMsgId())
|
||||
: _document(document)
|
||||
, _context(context) {
|
||||
: FileClickHandler(context)
|
||||
, _document(document) {
|
||||
}
|
||||
not_null<DocumentData*> document() const {
|
||||
return _document;
|
||||
}
|
||||
FullMsgId context() const {
|
||||
return _context;
|
||||
}
|
||||
|
||||
private:
|
||||
not_null<DocumentData*> _document;
|
||||
FullMsgId _context;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -70,14 +70,14 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class PhotoClickHandler : public LeftButtonClickHandler {
|
||||
class PhotoClickHandler : public FileClickHandler {
|
||||
public:
|
||||
PhotoClickHandler(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context = FullMsgId(),
|
||||
PeerData *peer = nullptr)
|
||||
: _photo(photo)
|
||||
, _context(context)
|
||||
: FileClickHandler(context)
|
||||
, _photo(photo)
|
||||
, _peer(peer) {
|
||||
}
|
||||
not_null<PhotoData*> photo() const {
|
||||
|
@ -86,13 +86,9 @@ public:
|
|||
PeerData *peer() const {
|
||||
return _peer;
|
||||
}
|
||||
FullMsgId context() const {
|
||||
return _context;
|
||||
}
|
||||
|
||||
private:
|
||||
not_null<PhotoData*> _photo;
|
||||
FullMsgId _context;
|
||||
PeerData *_peer = nullptr;
|
||||
|
||||
};
|
||||
|
|
|
@ -390,3 +390,21 @@ struct SendAction {
|
|||
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;
|
||||
|
||||
};
|
||||
|
|
|
@ -69,10 +69,13 @@ HistoryTextState::HistoryTextState(
|
|||
, link(link) {
|
||||
}
|
||||
|
||||
ReplyMarkupClickHandler::ReplyMarkupClickHandler(const HistoryItem *item, int row, int col)
|
||||
: _itemId(item->fullId())
|
||||
ReplyMarkupClickHandler::ReplyMarkupClickHandler(
|
||||
int row,
|
||||
int column,
|
||||
FullMsgId context)
|
||||
: _itemId(context)
|
||||
, _row(row)
|
||||
, _col(col) {
|
||||
, _column(column) {
|
||||
}
|
||||
|
||||
// Copy to clipboard support.
|
||||
|
@ -104,9 +107,9 @@ const HistoryMessageReplyMarkup::Button *ReplyMarkupClickHandler::getButton() co
|
|||
if (auto item = App::histItemById(_itemId)) {
|
||||
if (auto markup = item->Get<HistoryMessageReplyMarkup>()) {
|
||||
if (_row < markup->rows.size()) {
|
||||
auto &row = markup->rows.at(_row);
|
||||
if (_col < row.size()) {
|
||||
return &row.at(_col);
|
||||
auto &row = markup->rows[_row];
|
||||
if (_column < row.size()) {
|
||||
return &row[_column];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +119,7 @@ const HistoryMessageReplyMarkup::Button *ReplyMarkupClickHandler::getButton() co
|
|||
|
||||
void ReplyMarkupClickHandler::onClickImpl() const {
|
||||
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))
|
||||
, _st(std::move(s)) {
|
||||
if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) {
|
||||
_rows.reserve(markup->rows.size());
|
||||
for (auto i = 0, l = int(markup->rows.size()); i != l; ++i) {
|
||||
auto &row = markup->rows.at(i);
|
||||
int s = row.size();
|
||||
const auto context = _item->fullId();
|
||||
const auto rowCount = int(markup->rows.size());
|
||||
_rows.reserve(rowCount);
|
||||
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>();
|
||||
newRow.reserve(s);
|
||||
for (int j = 0; j != s; ++j) {
|
||||
newRow.reserve(rowSize);
|
||||
for (auto j = 0; j != rowSize; ++j) {
|
||||
auto button = Button();
|
||||
auto str = row.at(j).text;
|
||||
const auto text = row[j].text;
|
||||
button.type = row.at(j).type;
|
||||
button.link = std::make_shared<ReplyMarkupClickHandler>(item, i, j);
|
||||
button.text.setText(_st->textStyle(), TextUtilities::SingleLine(str), _textPlainOptions);
|
||||
button.characters = str.isEmpty() ? 1 : str.size();
|
||||
button.link = std::make_shared<ReplyMarkupClickHandler>(
|
||||
i,
|
||||
j,
|
||||
context);
|
||||
button.text.setText(
|
||||
_st->textStyle(),
|
||||
TextUtilities::SingleLine(text),
|
||||
_textPlainOptions);
|
||||
button.characters = text.isEmpty() ? 1 : text.size();
|
||||
newRow.push_back(std::move(button));
|
||||
}
|
||||
_rows.push_back(std::move(newRow));
|
||||
|
@ -924,7 +935,14 @@ void HistoryItem::setId(MsgId newId) {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ private:
|
|||
|
||||
class ReplyMarkupClickHandler : public LeftButtonClickHandler {
|
||||
public:
|
||||
ReplyMarkupClickHandler(const HistoryItem *item, int row, int col);
|
||||
ReplyMarkupClickHandler(int row, int column, FullMsgId context);
|
||||
|
||||
QString tooltip() const override {
|
||||
return _fullDisplayed ? QString() : buttonText();
|
||||
|
@ -300,7 +300,8 @@ protected:
|
|||
|
||||
private:
|
||||
FullMsgId _itemId;
|
||||
int _row, _col;
|
||||
int _row = 0;
|
||||
int _column = 0;
|
||||
bool _fullDisplayed = true;
|
||||
|
||||
// Returns the full text of the corresponding button.
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
virtual void initDimensions() = 0;
|
||||
virtual void updateMessageId() {
|
||||
virtual void refreshParentId(not_null<HistoryItem*> realParent) {
|
||||
}
|
||||
virtual int resizeGetHeight(int width) {
|
||||
_width = qMin(width, _maxw);
|
||||
|
|
|
@ -151,6 +151,13 @@ int HistoryGroupedMedia::resizeGetHeight(int width) {
|
|||
return _height;
|
||||
}
|
||||
|
||||
void HistoryGroupedMedia::refreshParentId(
|
||||
not_null<HistoryItem*> realParent) {
|
||||
for (const auto &element : _elements) {
|
||||
element.content->refreshParentId(element.item);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryGroupedMedia::draw(
|
||||
Painter &p,
|
||||
const QRect &clip,
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
void refreshParentId(not_null<HistoryItem*> realParent) override;
|
||||
|
||||
void draw(
|
||||
Painter &p,
|
||||
|
|
|
@ -215,14 +215,21 @@ void HistoryFileMedia::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool
|
|||
}
|
||||
|
||||
void HistoryFileMedia::setLinks(
|
||||
ClickHandlerPtr &&openl,
|
||||
ClickHandlerPtr &&savel,
|
||||
ClickHandlerPtr &&cancell) {
|
||||
FileClickHandlerPtr &&openl,
|
||||
FileClickHandlerPtr &&savel,
|
||||
FileClickHandlerPtr &&cancell) {
|
||||
_openl = std::move(openl);
|
||||
_savel = std::move(savel);
|
||||
_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 {
|
||||
_statusSize = newSize;
|
||||
if (_statusSize == FileStatusSizeReady) {
|
||||
|
@ -3846,6 +3853,12 @@ int HistoryWebPage::resizeGetHeight(int width) {
|
|||
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 {
|
||||
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
||||
int32 skipx = 0, skipy = 0, width = _width, height = _height;
|
||||
|
@ -4175,8 +4188,13 @@ HistoryGame::HistoryGame(
|
|||
void HistoryGame::initDimensions() {
|
||||
auto lineHeight = unitedLineHeight();
|
||||
|
||||
if (!_openl && _parent->id > 0) {
|
||||
_openl = std::make_shared<ReplyMarkupClickHandler>(_parent, 0, 0);
|
||||
if (!_openl && IsServerMsgId(_parent->id)) {
|
||||
const auto row = 0;
|
||||
const auto column = 0;
|
||||
_openl = std::make_shared<ReplyMarkupClickHandler>(
|
||||
row,
|
||||
column,
|
||||
_parent->fullId());
|
||||
}
|
||||
|
||||
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) {
|
||||
_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;
|
||||
}
|
||||
|
||||
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 {
|
||||
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
||||
int32 width = _width, height = _height;
|
||||
|
|
|
@ -63,6 +63,8 @@ public:
|
|||
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
||||
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
|
||||
|
||||
void refreshParentId(not_null<HistoryItem*> realParent) override;
|
||||
|
||||
bool allowsFastShare() const override {
|
||||
return true;
|
||||
}
|
||||
|
@ -70,13 +72,18 @@ public:
|
|||
~HistoryFileMedia();
|
||||
|
||||
protected:
|
||||
ClickHandlerPtr _openl, _savel, _cancell;
|
||||
void setLinks(ClickHandlerPtr &&openl, ClickHandlerPtr &&savel, ClickHandlerPtr &&cancell);
|
||||
using FileClickHandlerPtr = std::shared_ptr<FileClickHandler>;
|
||||
FileClickHandlerPtr _openl, _savel, _cancell;
|
||||
|
||||
void setLinks(
|
||||
FileClickHandlerPtr &&openl,
|
||||
FileClickHandlerPtr &&savel,
|
||||
FileClickHandlerPtr &&cancell);
|
||||
void setDocumentLinks(
|
||||
not_null<DocumentData*> document,
|
||||
not_null<HistoryItem*> realParent,
|
||||
bool inlinegif = false) {
|
||||
ClickHandlerPtr open, save;
|
||||
FileClickHandlerPtr open, save;
|
||||
const auto context = realParent->fullId();
|
||||
if (inlinegif) {
|
||||
open = std::make_shared<GifOpenClickHandler>(document, context);
|
||||
|
@ -944,6 +951,7 @@ public:
|
|||
|
||||
void initDimensions() 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;
|
||||
HistoryTextState getState(QPoint point, HistoryStateRequest request) const override;
|
||||
|
@ -1060,7 +1068,7 @@ public:
|
|||
|
||||
void initDimensions() 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;
|
||||
HistoryTextState getState(QPoint point, HistoryStateRequest request) const override;
|
||||
|
@ -1148,7 +1156,7 @@ private:
|
|||
int bottomInfoPadding() const;
|
||||
|
||||
not_null<GameData*> _data;
|
||||
ClickHandlerPtr _openl;
|
||||
std::shared_ptr<ReplyMarkupClickHandler> _openl;
|
||||
std::unique_ptr<HistoryMedia> _attach;
|
||||
|
||||
int32 _titleLines, _descriptionLines;
|
||||
|
@ -1181,6 +1189,7 @@ public:
|
|||
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
void refreshParentId(not_null<HistoryItem*> realParent) override;
|
||||
|
||||
MsgId getReceiptMsgId() const {
|
||||
return _receiptMsgId;
|
||||
|
|
|
@ -357,9 +357,15 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
|
|||
|
||||
auto computeGameTitle = [gamescore, &result]() -> QString {
|
||||
if (gamescore && gamescore->msg) {
|
||||
if (auto media = gamescore->msg->getMedia()) {
|
||||
if (const auto media = gamescore->msg->getMedia()) {
|
||||
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;
|
||||
return textcmdLink(result.links.size(), titleText);
|
||||
}
|
||||
|
@ -371,21 +377,37 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
|
|||
return QString();
|
||||
};
|
||||
|
||||
auto scoreNumber = gamescore ? gamescore->score : 0;
|
||||
const auto scoreNumber = gamescore ? gamescore->score : 0;
|
||||
if (_from->isSelf()) {
|
||||
auto gameTitle = computeGameTitle();
|
||||
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 {
|
||||
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 {
|
||||
result.links.push_back(fromLink());
|
||||
auto gameTitle = computeGameTitle();
|
||||
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 {
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue