From da8d4ceab1599c0280deaac9ddc6f176482ea957 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 2 Jan 2019 00:14:03 +0300 Subject: [PATCH] Better setChatMemberStatus. GitOrigin-RevId: eda67ca9fc959c9b94184ca952af8186aaf8d2de --- td/telegram/ContactsManager.cpp | 15 ++++++++++++++- td/telegram/DialogParticipant.h | 8 ++++++++ td/telegram/cli.cpp | 7 +++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index a919e662..1e1041d7 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4338,7 +4338,20 @@ void ContactsManager::change_channel_participant_status_impl(ChannelId channel_i } else if (status.is_administrator()) { need_promote = true; } else if (!status.is_member() || status.is_restricted()) { - need_restrict = true; + if (status.is_member() && !old_status.is_member()) { + // TODO there is no way in server API to invite someone and change restrictions + // we need to first add user and change restrictions again after that + // but if restrictions aren't changed, then adding is enough + auto copy_old_status = old_status; + copy_old_status.set_is_member(true); + if (copy_old_status == status) { + need_add = true; + } else { + need_restrict = true; + } + } else { + need_restrict = true; + } } else { // regular member if (old_status.is_administrator()) { diff --git a/td/telegram/DialogParticipant.h b/td/telegram/DialogParticipant.h index e48431b6..b4ba2007 100644 --- a/td/telegram/DialogParticipant.h +++ b/td/telegram/DialogParticipant.h @@ -166,6 +166,14 @@ class DialogParticipantStatus { return (flags_ & CAN_ADD_WEB_PAGE_PREVIEWS) != 0; } + void set_is_member(bool is_member) { + if (is_member) { + flags_ |= IS_MEMBER; + } else { + flags_ &= ~IS_MEMBER; + } + } + bool is_member() const { return (flags_ & IS_MEMBER) != 0; } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index b2ef81d6..3b9b2ba2 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3150,10 +3150,13 @@ class CliClient final : public Actor { status = make_tl_object(true, false, false, false, false, false, false, false, false); } else if (status_str == "rest") { - status = make_tl_object(true, static_cast(60 + std::time(nullptr)), + status = make_tl_object(true, static_cast(120 + std::time(nullptr)), false, false, false, false); } else if (status_str == "restkick") { - status = make_tl_object(false, static_cast(60 + std::time(nullptr)), + status = make_tl_object(false, static_cast(120 + std::time(nullptr)), + true, false, false, false); + } else if (status_str == "restunkick") { + status = make_tl_object(true, static_cast(120 + std::time(nullptr)), true, false, false, false); } else if (status_str == "unrest") { status = make_tl_object(true, 0, true, true, true, true);