mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +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);
|
||||
|
||||
auto markupFlags = to->replyKeyboardFlags();
|
||||
_forceReply = markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
|
||||
_maximizeSize = !(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_resize);
|
||||
_singleUse = _forceReply || (markupFlags & MTPDreplyKeyboardMarkup::Flag::f_single_use);
|
||||
_forceReply = markupFlags & ReplyMarkupFlag::ForceReply;
|
||||
_maximizeSize = !(markupFlags & ReplyMarkupFlag::Resize);
|
||||
_singleUse = _forceReply || (markupFlags & ReplyMarkupFlag::SingleUse);
|
||||
|
||||
if (const auto markup = to->Get<HistoryMessageReplyMarkup>()) {
|
||||
_placeholder = markup->placeholder;
|
||||
|
|
|
@ -781,7 +781,7 @@ not_null<HistoryItem*> History::addNewToBack(
|
|||
}
|
||||
if (item->definesReplyKeyboard()) {
|
||||
auto markupFlags = item->replyKeyboardFlags();
|
||||
if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective)
|
||||
if (!(markupFlags & ReplyMarkupFlag::Selective)
|
||||
|| item->mentionsMe()) {
|
||||
auto getMarkupSenders = [this]() -> base::flat_set<not_null<PeerData*>>* {
|
||||
if (auto chat = peer->asChat()) {
|
||||
|
@ -794,7 +794,8 @@ not_null<HistoryItem*> History::addNewToBack(
|
|||
if (auto markupSenders = getMarkupSenders()) {
|
||||
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
|
||||
|| (!lastKeyboardInited
|
||||
&& !peer->isChat()
|
||||
|
@ -1294,13 +1295,13 @@ void History::addItemsToLists(
|
|||
if (item->author()->id) {
|
||||
if (markupSenders) { // chats with bots
|
||||
if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) {
|
||||
auto markupFlags = item->replyKeyboardFlags();
|
||||
if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective) || item->mentionsMe()) {
|
||||
const auto markupFlags = item->replyKeyboardFlags();
|
||||
if (!(markupFlags & ReplyMarkupFlag::Selective) || item->mentionsMe()) {
|
||||
bool wasKeyboardHide = markupSenders->contains(item->author());
|
||||
if (!wasKeyboardHide) {
|
||||
markupSenders->insert(item->author());
|
||||
}
|
||||
if (!(markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero)) {
|
||||
if (!(markupFlags & ReplyMarkupFlag::None)) {
|
||||
if (!lastKeyboardInited) {
|
||||
bool botNotInChat = false;
|
||||
if (peer->isChat()) {
|
||||
|
@ -1321,9 +1322,9 @@ void History::addItemsToLists(
|
|||
}
|
||||
}
|
||||
} else if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) { // conversations with bots
|
||||
MTPDreplyKeyboardMarkup::Flags markupFlags = item->replyKeyboardFlags();
|
||||
if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective) || item->mentionsMe()) {
|
||||
if (markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero) {
|
||||
const auto markupFlags = item->replyKeyboardFlags();
|
||||
if (!(markupFlags & ReplyMarkupFlag::Selective) || item->mentionsMe()) {
|
||||
if (markupFlags & ReplyMarkupFlag::None) {
|
||||
clearLastKeyboard();
|
||||
} else {
|
||||
lastKeyboardInited = true;
|
||||
|
|
|
@ -231,7 +231,7 @@ void HistoryItem::setGroupId(MessageGroupId groupId) {
|
|||
|
||||
HistoryMessageReplyMarkup *HistoryItem::inlineReplyMarkup() {
|
||||
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
||||
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) {
|
||||
if (markup->flags & ReplyMarkupFlag::Inline) {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ void HistoryItem::setIsPinned(bool pinned) {
|
|||
|
||||
bool HistoryItem::definesReplyKeyboard() const {
|
||||
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
||||
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) {
|
||||
if (markup->flags & ReplyMarkupFlag::Inline) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -390,7 +390,7 @@ bool HistoryItem::definesReplyKeyboard() const {
|
|||
return (_flags & MTPDmessage::Flag::f_reply_markup);
|
||||
}
|
||||
|
||||
MTPDreplyKeyboardMarkup::Flags HistoryItem::replyKeyboardFlags() const {
|
||||
ReplyMarkupFlags HistoryItem::replyKeyboardFlags() const {
|
||||
Expects(definesReplyKeyboard());
|
||||
|
||||
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
||||
|
@ -399,7 +399,7 @@ MTPDreplyKeyboardMarkup::Flags HistoryItem::replyKeyboardFlags() const {
|
|||
|
||||
// optimization: don't create markup component for the case
|
||||
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
||||
return MTPDreplyKeyboardMarkup_ClientFlag::f_zero | 0;
|
||||
return ReplyMarkupFlag::None;
|
||||
}
|
||||
|
||||
void HistoryItem::addLogEntryOriginal(
|
||||
|
|
|
@ -57,6 +57,18 @@ class ElementDelegate;
|
|||
struct HiddenSenderInfo;
|
||||
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> {
|
||||
public:
|
||||
static not_null<HistoryItem*> Create(
|
||||
|
@ -149,7 +161,7 @@ public:
|
|||
}
|
||||
|
||||
[[nodiscard]] bool definesReplyKeyboard() const;
|
||||
[[nodiscard]] MTPDreplyKeyboardMarkup::Flags replyKeyboardFlags() const;
|
||||
[[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const;
|
||||
|
||||
[[nodiscard]] bool hasSwitchInlineButton() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
||||
|
|
|
@ -887,7 +887,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows(
|
|||
if (type == Type::SwitchInline) {
|
||||
// Optimization flag.
|
||||
// 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) {
|
||||
row.emplace_back(Type::Game, qs(data.vtext()));
|
||||
|
@ -932,35 +932,26 @@ void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) {
|
|||
rows.clear();
|
||||
inlineKeyboard = nullptr;
|
||||
|
||||
switch (markup.type()) {
|
||||
case mtpc_replyKeyboardMarkup: {
|
||||
auto &d = markup.c_replyKeyboardMarkup();
|
||||
flags = d.vflags().v;
|
||||
placeholder = d.vplaceholder() ? qs(*d.vplaceholder()) : QString();
|
||||
|
||||
createFromButtonRows(d.vrows().v);
|
||||
} break;
|
||||
|
||||
case mtpc_replyInlineMarkup: {
|
||||
auto &d = markup.c_replyInlineMarkup();
|
||||
flags = MTPDreplyKeyboardMarkup::Flags(0) | MTPDreplyKeyboardMarkup_ClientFlag::f_inline;
|
||||
using Flag = ReplyMarkupFlag;
|
||||
markup.match([&](const MTPDreplyKeyboardMarkup &data) {
|
||||
flags = (data.is_resize() ? Flag::Resize : Flag())
|
||||
| (data.is_selective() ? Flag::Selective : Flag())
|
||||
| (data.is_single_use() ? Flag::SingleUse : Flag());
|
||||
placeholder = qs(data.vplaceholder().value_or_empty());
|
||||
createFromButtonRows(data.vrows().v);
|
||||
}, [&](const MTPDreplyInlineMarkup &data) {
|
||||
flags = Flag::Inline;
|
||||
placeholder = QString();
|
||||
|
||||
createFromButtonRows(d.vrows().v);
|
||||
} break;
|
||||
|
||||
case mtpc_replyKeyboardHide: {
|
||||
auto &d = markup.c_replyKeyboardHide();
|
||||
flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_zero;
|
||||
createFromButtonRows(data.vrows().v);
|
||||
}, [&](const MTPDreplyKeyboardHide &data) {
|
||||
flags = Flag::None | (data.is_selective() ? Flag::Selective : Flag());
|
||||
placeholder = QString();
|
||||
} break;
|
||||
|
||||
case mtpc_replyKeyboardForceReply: {
|
||||
auto &d = markup.c_replyKeyboardForceReply();
|
||||
flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
|
||||
placeholder = d.vplaceholder() ? qs(*d.vplaceholder()) : QString();
|
||||
} break;
|
||||
}
|
||||
}, [&](const MTPDreplyKeyboardForceReply &data) {
|
||||
flags = Flag::ForceReply
|
||||
| (data.is_selective() ? Flag::Selective : Flag())
|
||||
| (data.is_single_use() ? Flag::SingleUse : Flag());
|
||||
placeholder = qs(data.vplaceholder().value_or_empty());
|
||||
});
|
||||
}
|
||||
|
||||
void HistoryMessageReplyMarkup::create(
|
||||
|
|
|
@ -225,18 +225,19 @@ struct HistoryMessageMarkupButton {
|
|||
|
||||
};
|
||||
|
||||
struct HistoryMessageReplyMarkup : public RuntimeComponent<HistoryMessageReplyMarkup, HistoryItem> {
|
||||
struct HistoryMessageReplyMarkup
|
||||
: public RuntimeComponent<HistoryMessageReplyMarkup, HistoryItem> {
|
||||
using Button = HistoryMessageMarkupButton;
|
||||
|
||||
HistoryMessageReplyMarkup() = default;
|
||||
HistoryMessageReplyMarkup(MTPDreplyKeyboardMarkup::Flags f) : flags(f) {
|
||||
HistoryMessageReplyMarkup(ReplyMarkupFlags flags) : flags(flags) {
|
||||
}
|
||||
|
||||
void create(const MTPReplyMarkup &markup);
|
||||
void create(const HistoryMessageReplyMarkup &markup);
|
||||
|
||||
std::vector<std::vector<Button>> rows;
|
||||
MTPDreplyKeyboardMarkup::Flags flags = 0;
|
||||
ReplyMarkupFlags flags = 0;
|
||||
QString placeholder;
|
||||
|
||||
std::unique_ptr<ReplyKeyboard> inlineKeyboard;
|
||||
|
|
|
@ -1132,7 +1132,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
|
|||
} else if (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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,21 +76,3 @@ enum class MTPDmessage_ClientFlag : uint32 {
|
|||
};
|
||||
inline constexpr bool is_flag_type(MTPDmessage_ClientFlag) { return true; }
|
||||
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