Better setChatMemberStatus.

GitOrigin-RevId: eda67ca9fc959c9b94184ca952af8186aaf8d2de
This commit is contained in:
levlam 2019-01-02 00:14:03 +03:00
parent 9f7b5fe258
commit da8d4ceab1
3 changed files with 27 additions and 3 deletions

View File

@ -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()) {

View File

@ -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;
}

View File

@ -3150,10 +3150,13 @@ class CliClient final : public Actor {
status = make_tl_object<td_api::chatMemberStatusAdministrator>(true, false, false, false, false, false, false,
false, false);
} else if (status_str == "rest") {
status = make_tl_object<td_api::chatMemberStatusRestricted>(true, static_cast<int32>(60 + std::time(nullptr)),
status = make_tl_object<td_api::chatMemberStatusRestricted>(true, static_cast<int32>(120 + std::time(nullptr)),
false, false, false, false);
} else if (status_str == "restkick") {
status = make_tl_object<td_api::chatMemberStatusRestricted>(false, static_cast<int32>(60 + std::time(nullptr)),
status = make_tl_object<td_api::chatMemberStatusRestricted>(false, static_cast<int32>(120 + std::time(nullptr)),
true, false, false, false);
} else if (status_str == "restunkick") {
status = make_tl_object<td_api::chatMemberStatusRestricted>(true, static_cast<int32>(120 + std::time(nullptr)),
true, false, false, false);
} else if (status_str == "unrest") {
status = make_tl_object<td_api::chatMemberStatusRestricted>(true, 0, true, true, true, true);