mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Forward some inline keyboards.
This commit is contained in:
parent
6b9675a5b1
commit
87caa58456
3 changed files with 41 additions and 19 deletions
|
@ -296,6 +296,15 @@ public:
|
||||||
|
|
||||||
MessageGroupId groupId() const;
|
MessageGroupId groupId() const;
|
||||||
|
|
||||||
|
const HistoryMessageReplyMarkup *inlineReplyMarkup() const {
|
||||||
|
return const_cast<HistoryItem*>(this)->inlineReplyMarkup();
|
||||||
|
}
|
||||||
|
const ReplyKeyboard *inlineReplyKeyboard() const {
|
||||||
|
return const_cast<HistoryItem*>(this)->inlineReplyKeyboard();
|
||||||
|
}
|
||||||
|
HistoryMessageReplyMarkup *inlineReplyMarkup();
|
||||||
|
ReplyKeyboard *inlineReplyKeyboard();
|
||||||
|
|
||||||
virtual std::unique_ptr<HistoryView::Element> createView(
|
virtual std::unique_ptr<HistoryView::Element> createView(
|
||||||
not_null<HistoryView::ElementDelegate*> delegate) = 0;
|
not_null<HistoryView::ElementDelegate*> delegate) = 0;
|
||||||
|
|
||||||
|
@ -319,14 +328,6 @@ protected:
|
||||||
not_null<PeerData*> _from;
|
not_null<PeerData*> _from;
|
||||||
MTPDmessage::Flags _flags = 0;
|
MTPDmessage::Flags _flags = 0;
|
||||||
|
|
||||||
const HistoryMessageReplyMarkup *inlineReplyMarkup() const {
|
|
||||||
return const_cast<HistoryItem*>(this)->inlineReplyMarkup();
|
|
||||||
}
|
|
||||||
const ReplyKeyboard *inlineReplyKeyboard() const {
|
|
||||||
return const_cast<HistoryItem*>(this)->inlineReplyKeyboard();
|
|
||||||
}
|
|
||||||
HistoryMessageReplyMarkup *inlineReplyMarkup();
|
|
||||||
ReplyKeyboard *inlineReplyKeyboard();
|
|
||||||
void invalidateChatListEntry();
|
void invalidateChatListEntry();
|
||||||
|
|
||||||
void setGroupId(MessageGroupId groupId);
|
void setGroupId(MessageGroupId groupId);
|
||||||
|
|
|
@ -860,12 +860,16 @@ void HistoryMessageReplyMarkup::create(
|
||||||
|
|
||||||
rows.clear();
|
rows.clear();
|
||||||
rows.reserve(markup.rows.size());
|
rows.reserve(markup.rows.size());
|
||||||
|
using Type = HistoryMessageMarkupButton::Type;
|
||||||
for (const auto &existing : markup.rows) {
|
for (const auto &existing : markup.rows) {
|
||||||
auto row = std::vector<Button>();
|
auto row = std::vector<Button>();
|
||||||
row.reserve(existing.size());
|
row.reserve(existing.size());
|
||||||
for (const auto &button : existing) {
|
for (const auto &button : existing) {
|
||||||
|
const auto newType = (button.type != Type::SwitchInlineSame)
|
||||||
|
? button.type
|
||||||
|
: Type::SwitchInline;
|
||||||
row.emplace_back(
|
row.emplace_back(
|
||||||
button.type,
|
newType,
|
||||||
button.text,
|
button.text,
|
||||||
button.data,
|
button.data,
|
||||||
button.buttonId);
|
button.buttonId);
|
||||||
|
|
|
@ -71,6 +71,31 @@ MTPDmessage::Flags NewForwardedFlags(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
|
||||||
|
auto mediaOriginal = item->media();
|
||||||
|
if (mediaOriginal && mediaOriginal->game()) {
|
||||||
|
// Copy inline keyboard when forwarding messages with a game.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const auto markup = item->inlineReplyMarkup();
|
||||||
|
if (!markup) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using Type = HistoryMessageMarkupButton::Type;
|
||||||
|
for (const auto &row : markup->rows) {
|
||||||
|
for (const auto &button : row) {
|
||||||
|
const auto switchInline = (button.type == Type::SwitchInline)
|
||||||
|
|| (button.type == Type::SwitchInlineSame);
|
||||||
|
const auto url = (button.type == Type::Url)
|
||||||
|
|| (button.type == Type::Auth);
|
||||||
|
if ((!switchInline || !item->viaBot()) && !url) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool HasInlineItems(const HistoryItemsList &items) {
|
bool HasInlineItems(const HistoryItemsList &items) {
|
||||||
for (const auto item : items) {
|
for (const auto item : items) {
|
||||||
if (item->viaBot()) {
|
if (item->viaBot()) {
|
||||||
|
@ -435,9 +460,8 @@ HistoryMessage::HistoryMessage(
|
||||||
config.viewsCount = 1;
|
config.viewsCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy inline keyboard when forwarding messages with a game.
|
const auto mediaOriginal = original->media();
|
||||||
auto mediaOriginal = original->media();
|
if (CopyMarkupToForward(original)) {
|
||||||
if (mediaOriginal && mediaOriginal->game()) {
|
|
||||||
config.inlineMarkup = original->inlineReplyMarkup();
|
config.inlineMarkup = original->inlineReplyMarkup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,13 +688,6 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
|
||||||
if (!config.author.isEmpty()) {
|
if (!config.author.isEmpty()) {
|
||||||
mask |= HistoryMessageSigned::Bit();
|
mask |= HistoryMessageSigned::Bit();
|
||||||
}
|
}
|
||||||
auto hasViaBot = (config.viaBotId != 0);
|
|
||||||
auto hasInlineMarkup = [&config] {
|
|
||||||
if (config.mtpMarkup) {
|
|
||||||
return (config.mtpMarkup->type() == mtpc_replyInlineMarkup);
|
|
||||||
}
|
|
||||||
return (config.inlineMarkup != nullptr);
|
|
||||||
};
|
|
||||||
if (config.editDate != TimeId(0)) {
|
if (config.editDate != TimeId(0)) {
|
||||||
mask |= HistoryMessageEdited::Bit();
|
mask |= HistoryMessageEdited::Bit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue