Add QuickReplyShortcutId::is_server().

This commit is contained in:
levlam 2024-02-24 03:28:55 +03:00
parent 817a64ce0e
commit 5ef3562533
3 changed files with 21 additions and 2 deletions

View File

@ -564,7 +564,7 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts(
vector<QuickReplyShortcutId> deleted_shortcut_ids; vector<QuickReplyShortcutId> deleted_shortcut_ids;
for (auto &quick_reply : shortcuts->quick_replies_) { for (auto &quick_reply : shortcuts->quick_replies_) {
auto shortcut_id = QuickReplyShortcutId(quick_reply->shortcut_id_); auto shortcut_id = QuickReplyShortcutId(quick_reply->shortcut_id_);
if (!shortcut_id.is_valid() || quick_reply->shortcut_.empty() || quick_reply->count_ <= 0 || if (!shortcut_id.is_server() || quick_reply->shortcut_.empty() || quick_reply->count_ <= 0 ||
quick_reply->top_message_ <= 0) { quick_reply->top_message_ <= 0) {
LOG(ERROR) << "Receive " << to_string(quick_reply); LOG(ERROR) << "Receive " << to_string(quick_reply);
continue; continue;
@ -691,8 +691,19 @@ void QuickReplyManager::delete_quick_reply_shortcut(const string &name, Promise<
auto shortcut_id = s->shortcut_id_; auto shortcut_id = s->shortcut_id_;
td::remove_if(shortcuts_.shortcuts_, td::remove_if(shortcuts_.shortcuts_,
[shortcut_id](const unique_ptr<Shortcut> &shortcut) { return shortcut->shortcut_id_ == shortcut_id; }); [shortcut_id](const unique_ptr<Shortcut> &shortcut) { return shortcut->shortcut_id_ == shortcut_id; });
deleted_shortcut_ids_.insert(shortcut_id);
if (!shortcut_id.is_server()) {
return promise.set_value(Unit());
}
delete_quick_reply_shortcut_from_server(shortcut_id, std::move(promise));
}
void QuickReplyManager::delete_quick_reply_shortcut_from_server(QuickReplyShortcutId shortcut_id,
Promise<Unit> &&promise) {
CHECK(shortcut_id.is_server());
deleted_shortcut_ids_.insert(shortcut_id);
td_->create_handler<DeleteQuickReplyShortcutQuery>(std::move(promise))->send(shortcut_id); td_->create_handler<DeleteQuickReplyShortcutQuery>(std::move(promise))->send(shortcut_id);
} }

View File

@ -197,6 +197,8 @@ class QuickReplyManager final : public Actor {
void send_update_quick_reply_shortcuts(); void send_update_quick_reply_shortcuts();
void delete_quick_reply_shortcut_from_server(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
Shortcuts shortcuts_; Shortcuts shortcuts_;
FlatHashSet<QuickReplyShortcutId, QuickReplyShortcutIdHash> deleted_shortcut_ids_; FlatHashSet<QuickReplyShortcutId, QuickReplyShortcutIdHash> deleted_shortcut_ids_;

View File

@ -18,6 +18,8 @@ class QuickReplyShortcutId {
int32 id = 0; int32 id = 0;
public: public:
static constexpr int32 MAX_SERVER_SHORTCUT_ID = 1999999999;
QuickReplyShortcutId() = default; QuickReplyShortcutId() = default;
explicit constexpr QuickReplyShortcutId(int32 quick_reply_shortcut_id) : id(quick_reply_shortcut_id) { explicit constexpr QuickReplyShortcutId(int32 quick_reply_shortcut_id) : id(quick_reply_shortcut_id) {
@ -41,6 +43,10 @@ class QuickReplyShortcutId {
return id > 0; return id > 0;
} }
bool is_server() const {
return id > 0 && id <= MAX_SERVER_SHORTCUT_ID;
}
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const { void store(StorerT &storer) const {
storer.store_int(id); storer.store_int(id);