mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Don't use MTP* for ReplyMarkup flags.
This commit is contained in:
parent
bbbcd37b8f
commit
22e77bf3af
8 changed files with 53 additions and 66 deletions
|
@ -242,9 +242,9 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) {
|
||||||
_wasForMsgId = FullMsgId(to->channelId(), to->id);
|
_wasForMsgId = FullMsgId(to->channelId(), to->id);
|
||||||
|
|
||||||
auto markupFlags = to->replyKeyboardFlags();
|
auto markupFlags = to->replyKeyboardFlags();
|
||||||
_forceReply = markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
|
_forceReply = markupFlags & ReplyMarkupFlag::ForceReply;
|
||||||
_maximizeSize = !(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_resize);
|
_maximizeSize = !(markupFlags & ReplyMarkupFlag::Resize);
|
||||||
_singleUse = _forceReply || (markupFlags & MTPDreplyKeyboardMarkup::Flag::f_single_use);
|
_singleUse = _forceReply || (markupFlags & ReplyMarkupFlag::SingleUse);
|
||||||
|
|
||||||
if (const auto markup = to->Get<HistoryMessageReplyMarkup>()) {
|
if (const auto markup = to->Get<HistoryMessageReplyMarkup>()) {
|
||||||
_placeholder = markup->placeholder;
|
_placeholder = markup->placeholder;
|
||||||
|
|
|
@ -781,7 +781,7 @@ not_null<HistoryItem*> History::addNewToBack(
|
||||||
}
|
}
|
||||||
if (item->definesReplyKeyboard()) {
|
if (item->definesReplyKeyboard()) {
|
||||||
auto markupFlags = item->replyKeyboardFlags();
|
auto markupFlags = item->replyKeyboardFlags();
|
||||||
if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective)
|
if (!(markupFlags & ReplyMarkupFlag::Selective)
|
||||||
|| item->mentionsMe()) {
|
|| item->mentionsMe()) {
|
||||||
auto getMarkupSenders = [this]() -> base::flat_set<not_null<PeerData*>>* {
|
auto getMarkupSenders = [this]() -> base::flat_set<not_null<PeerData*>>* {
|
||||||
if (auto chat = peer->asChat()) {
|
if (auto chat = peer->asChat()) {
|
||||||
|
@ -794,7 +794,8 @@ not_null<HistoryItem*> History::addNewToBack(
|
||||||
if (auto markupSenders = getMarkupSenders()) {
|
if (auto markupSenders = getMarkupSenders()) {
|
||||||
markupSenders->insert(item->from());
|
markupSenders->insert(item->from());
|
||||||
}
|
}
|
||||||
if (markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero) { // zero markup means replyKeyboardHide
|
if (markupFlags & ReplyMarkupFlag::None) {
|
||||||
|
// None markup means replyKeyboardHide.
|
||||||
if (lastKeyboardFrom == item->from()->id
|
if (lastKeyboardFrom == item->from()->id
|
||||||
|| (!lastKeyboardInited
|
|| (!lastKeyboardInited
|
||||||
&& !peer->isChat()
|
&& !peer->isChat()
|
||||||
|
@ -1294,13 +1295,13 @@ void History::addItemsToLists(
|
||||||
if (item->author()->id) {
|
if (item->author()->id) {
|
||||||
if (markupSenders) { // chats with bots
|
if (markupSenders) { // chats with bots
|
||||||
if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) {
|
if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) {
|
||||||
auto markupFlags = item->replyKeyboardFlags();
|
const auto markupFlags = item->replyKeyboardFlags();
|
||||||
if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective) || item->mentionsMe()) {
|
if (!(markupFlags & ReplyMarkupFlag::Selective) || item->mentionsMe()) {
|
||||||
bool wasKeyboardHide = markupSenders->contains(item->author());
|
bool wasKeyboardHide = markupSenders->contains(item->author());
|
||||||
if (!wasKeyboardHide) {
|
if (!wasKeyboardHide) {
|
||||||
markupSenders->insert(item->author());
|
markupSenders->insert(item->author());
|
||||||
}
|
}
|
||||||
if (!(markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero)) {
|
if (!(markupFlags & ReplyMarkupFlag::None)) {
|
||||||
if (!lastKeyboardInited) {
|
if (!lastKeyboardInited) {
|
||||||
bool botNotInChat = false;
|
bool botNotInChat = false;
|
||||||
if (peer->isChat()) {
|
if (peer->isChat()) {
|
||||||
|
@ -1321,9 +1322,9 @@ void History::addItemsToLists(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) { // conversations with bots
|
} else if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) { // conversations with bots
|
||||||
MTPDreplyKeyboardMarkup::Flags markupFlags = item->replyKeyboardFlags();
|
const auto markupFlags = item->replyKeyboardFlags();
|
||||||
if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective) || item->mentionsMe()) {
|
if (!(markupFlags & ReplyMarkupFlag::Selective) || item->mentionsMe()) {
|
||||||
if (markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero) {
|
if (markupFlags & ReplyMarkupFlag::None) {
|
||||||
clearLastKeyboard();
|
clearLastKeyboard();
|
||||||
} else {
|
} else {
|
||||||
lastKeyboardInited = true;
|
lastKeyboardInited = true;
|
||||||
|
|
|
@ -231,7 +231,7 @@ void HistoryItem::setGroupId(MessageGroupId groupId) {
|
||||||
|
|
||||||
HistoryMessageReplyMarkup *HistoryItem::inlineReplyMarkup() {
|
HistoryMessageReplyMarkup *HistoryItem::inlineReplyMarkup() {
|
||||||
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
||||||
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) {
|
if (markup->flags & ReplyMarkupFlag::Inline) {
|
||||||
return markup;
|
return markup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ void HistoryItem::setIsPinned(bool pinned) {
|
||||||
|
|
||||||
bool HistoryItem::definesReplyKeyboard() const {
|
bool HistoryItem::definesReplyKeyboard() const {
|
||||||
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
||||||
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) {
|
if (markup->flags & ReplyMarkupFlag::Inline) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -390,7 +390,7 @@ bool HistoryItem::definesReplyKeyboard() const {
|
||||||
return (_flags & MTPDmessage::Flag::f_reply_markup);
|
return (_flags & MTPDmessage::Flag::f_reply_markup);
|
||||||
}
|
}
|
||||||
|
|
||||||
MTPDreplyKeyboardMarkup::Flags HistoryItem::replyKeyboardFlags() const {
|
ReplyMarkupFlags HistoryItem::replyKeyboardFlags() const {
|
||||||
Expects(definesReplyKeyboard());
|
Expects(definesReplyKeyboard());
|
||||||
|
|
||||||
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
||||||
|
@ -399,7 +399,7 @@ MTPDreplyKeyboardMarkup::Flags HistoryItem::replyKeyboardFlags() const {
|
||||||
|
|
||||||
// optimization: don't create markup component for the case
|
// optimization: don't create markup component for the case
|
||||||
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
||||||
return MTPDreplyKeyboardMarkup_ClientFlag::f_zero | 0;
|
return ReplyMarkupFlag::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryItem::addLogEntryOriginal(
|
void HistoryItem::addLogEntryOriginal(
|
||||||
|
|
|
@ -57,6 +57,18 @@ class ElementDelegate;
|
||||||
struct HiddenSenderInfo;
|
struct HiddenSenderInfo;
|
||||||
class History;
|
class History;
|
||||||
|
|
||||||
|
enum class ReplyMarkupFlag : uint32 {
|
||||||
|
None = (1U << 0),
|
||||||
|
ForceReply = (1U << 1),
|
||||||
|
HasSwitchInlineButton = (1U << 2),
|
||||||
|
Inline = (1U << 3),
|
||||||
|
Resize = (1U << 4),
|
||||||
|
SingleUse = (1U << 5),
|
||||||
|
Selective = (1U << 6),
|
||||||
|
};
|
||||||
|
inline constexpr bool is_flag_type(ReplyMarkupFlag) { return true; }
|
||||||
|
using ReplyMarkupFlags = base::flags<ReplyMarkupFlag>;
|
||||||
|
|
||||||
class HistoryItem : public RuntimeComposer<HistoryItem> {
|
class HistoryItem : public RuntimeComposer<HistoryItem> {
|
||||||
public:
|
public:
|
||||||
static not_null<HistoryItem*> Create(
|
static not_null<HistoryItem*> Create(
|
||||||
|
@ -149,7 +161,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool definesReplyKeyboard() const;
|
[[nodiscard]] bool definesReplyKeyboard() const;
|
||||||
[[nodiscard]] MTPDreplyKeyboardMarkup::Flags replyKeyboardFlags() const;
|
[[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const;
|
||||||
|
|
||||||
[[nodiscard]] bool hasSwitchInlineButton() const {
|
[[nodiscard]] bool hasSwitchInlineButton() const {
|
||||||
return _clientFlags & MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
return _clientFlags & MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
||||||
|
|
|
@ -887,7 +887,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows(
|
||||||
if (type == Type::SwitchInline) {
|
if (type == Type::SwitchInline) {
|
||||||
// Optimization flag.
|
// Optimization flag.
|
||||||
// Fast check on all new messages if there is a switch button to auto-click it.
|
// Fast check on all new messages if there is a switch button to auto-click it.
|
||||||
flags |= MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button;
|
flags |= ReplyMarkupFlag::HasSwitchInlineButton;
|
||||||
}
|
}
|
||||||
}, [&](const MTPDkeyboardButtonGame &data) {
|
}, [&](const MTPDkeyboardButtonGame &data) {
|
||||||
row.emplace_back(Type::Game, qs(data.vtext()));
|
row.emplace_back(Type::Game, qs(data.vtext()));
|
||||||
|
@ -932,35 +932,26 @@ void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) {
|
||||||
rows.clear();
|
rows.clear();
|
||||||
inlineKeyboard = nullptr;
|
inlineKeyboard = nullptr;
|
||||||
|
|
||||||
switch (markup.type()) {
|
using Flag = ReplyMarkupFlag;
|
||||||
case mtpc_replyKeyboardMarkup: {
|
markup.match([&](const MTPDreplyKeyboardMarkup &data) {
|
||||||
auto &d = markup.c_replyKeyboardMarkup();
|
flags = (data.is_resize() ? Flag::Resize : Flag())
|
||||||
flags = d.vflags().v;
|
| (data.is_selective() ? Flag::Selective : Flag())
|
||||||
placeholder = d.vplaceholder() ? qs(*d.vplaceholder()) : QString();
|
| (data.is_single_use() ? Flag::SingleUse : Flag());
|
||||||
|
placeholder = qs(data.vplaceholder().value_or_empty());
|
||||||
createFromButtonRows(d.vrows().v);
|
createFromButtonRows(data.vrows().v);
|
||||||
} break;
|
}, [&](const MTPDreplyInlineMarkup &data) {
|
||||||
|
flags = Flag::Inline;
|
||||||
case mtpc_replyInlineMarkup: {
|
|
||||||
auto &d = markup.c_replyInlineMarkup();
|
|
||||||
flags = MTPDreplyKeyboardMarkup::Flags(0) | MTPDreplyKeyboardMarkup_ClientFlag::f_inline;
|
|
||||||
placeholder = QString();
|
placeholder = QString();
|
||||||
|
createFromButtonRows(data.vrows().v);
|
||||||
createFromButtonRows(d.vrows().v);
|
}, [&](const MTPDreplyKeyboardHide &data) {
|
||||||
} break;
|
flags = Flag::None | (data.is_selective() ? Flag::Selective : Flag());
|
||||||
|
|
||||||
case mtpc_replyKeyboardHide: {
|
|
||||||
auto &d = markup.c_replyKeyboardHide();
|
|
||||||
flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_zero;
|
|
||||||
placeholder = QString();
|
placeholder = QString();
|
||||||
} break;
|
}, [&](const MTPDreplyKeyboardForceReply &data) {
|
||||||
|
flags = Flag::ForceReply
|
||||||
case mtpc_replyKeyboardForceReply: {
|
| (data.is_selective() ? Flag::Selective : Flag())
|
||||||
auto &d = markup.c_replyKeyboardForceReply();
|
| (data.is_single_use() ? Flag::SingleUse : Flag());
|
||||||
flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
|
placeholder = qs(data.vplaceholder().value_or_empty());
|
||||||
placeholder = d.vplaceholder() ? qs(*d.vplaceholder()) : QString();
|
});
|
||||||
} break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryMessageReplyMarkup::create(
|
void HistoryMessageReplyMarkup::create(
|
||||||
|
|
|
@ -225,18 +225,19 @@ struct HistoryMessageMarkupButton {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HistoryMessageReplyMarkup : public RuntimeComponent<HistoryMessageReplyMarkup, HistoryItem> {
|
struct HistoryMessageReplyMarkup
|
||||||
|
: public RuntimeComponent<HistoryMessageReplyMarkup, HistoryItem> {
|
||||||
using Button = HistoryMessageMarkupButton;
|
using Button = HistoryMessageMarkupButton;
|
||||||
|
|
||||||
HistoryMessageReplyMarkup() = default;
|
HistoryMessageReplyMarkup() = default;
|
||||||
HistoryMessageReplyMarkup(MTPDreplyKeyboardMarkup::Flags f) : flags(f) {
|
HistoryMessageReplyMarkup(ReplyMarkupFlags flags) : flags(flags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void create(const MTPReplyMarkup &markup);
|
void create(const MTPReplyMarkup &markup);
|
||||||
void create(const HistoryMessageReplyMarkup &markup);
|
void create(const HistoryMessageReplyMarkup &markup);
|
||||||
|
|
||||||
std::vector<std::vector<Button>> rows;
|
std::vector<std::vector<Button>> rows;
|
||||||
MTPDreplyKeyboardMarkup::Flags flags = 0;
|
ReplyMarkupFlags flags = 0;
|
||||||
QString placeholder;
|
QString placeholder;
|
||||||
|
|
||||||
std::unique_ptr<ReplyKeyboard> inlineKeyboard;
|
std::unique_ptr<ReplyKeyboard> inlineKeyboard;
|
||||||
|
|
|
@ -1132,7 +1132,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
|
||||||
} else if (config.inlineMarkup) {
|
} else if (config.inlineMarkup) {
|
||||||
markup->create(*config.inlineMarkup);
|
markup->create(*config.inlineMarkup);
|
||||||
}
|
}
|
||||||
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button) {
|
if (markup->flags & ReplyMarkupFlag::HasSwitchInlineButton) {
|
||||||
_clientFlags |= MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
_clientFlags |= MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,21 +76,3 @@ enum class MTPDmessage_ClientFlag : uint32 {
|
||||||
};
|
};
|
||||||
inline constexpr bool is_flag_type(MTPDmessage_ClientFlag) { return true; }
|
inline constexpr bool is_flag_type(MTPDmessage_ClientFlag) { return true; }
|
||||||
using MTPDmessage_ClientFlags = base::flags<MTPDmessage_ClientFlag>;
|
using MTPDmessage_ClientFlags = base::flags<MTPDmessage_ClientFlag>;
|
||||||
|
|
||||||
enum class MTPDreplyKeyboardMarkup_ClientFlag : uint32 {
|
|
||||||
// none (zero) markup
|
|
||||||
f_zero = (1U << 30),
|
|
||||||
|
|
||||||
// markup just wants a text reply
|
|
||||||
f_force_reply = (1U << 29),
|
|
||||||
|
|
||||||
// markup keyboard is inline
|
|
||||||
f_inline = (1U << 28),
|
|
||||||
|
|
||||||
// markup has a switch inline keyboard button
|
|
||||||
f_has_switch_inline_button = (1U << 27),
|
|
||||||
|
|
||||||
// update this when adding new client side flags
|
|
||||||
MIN_FIELD = (1U << 27),
|
|
||||||
};
|
|
||||||
DEFINE_MTP_CLIENT_FLAGS(MTPDreplyKeyboardMarkup)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue