Locally fix until_date before sending it to the server.
This commit is contained in:
parent
bb0908504b
commit
c0eb211476
@ -15330,6 +15330,7 @@ void ContactsManager::ban_dialog_participant(DialogId dialog_id, DialogId partic
|
||||
return delete_chat_participant(dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), revoke_messages,
|
||||
std::move(promise));
|
||||
case DialogType::Channel:
|
||||
// must use td_api::chatMemberStatusBanned to properly fix banned_until_date
|
||||
return set_channel_participant_status(dialog_id.get_channel_id(), participant_dialog_id,
|
||||
td_api::make_object<td_api::chatMemberStatusBanned>(banned_until_date),
|
||||
std::move(promise));
|
||||
|
@ -569,6 +569,20 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant
|
||||
DialogParticipantStatus get_dialog_participant_status(const td_api::object_ptr<td_api::ChatMemberStatus> &status,
|
||||
ChannelType channel_type) {
|
||||
auto constructor_id = status == nullptr ? td_api::chatMemberStatusMember::ID : status->get_id();
|
||||
auto fix_until_date = [](int32 until_date) {
|
||||
if (until_date == 0) {
|
||||
// fast path
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if user is restricted for more than 366 days or less than 30 seconds from the current time,
|
||||
// they are considered to be restricted forever
|
||||
auto unix_time = G()->unix_time();
|
||||
if (until_date < unix_time + 30 || until_date > unix_time + 366 * 86400) {
|
||||
return 0;
|
||||
}
|
||||
return until_date;
|
||||
};
|
||||
switch (constructor_id) {
|
||||
case td_api::chatMemberStatusCreator::ID: {
|
||||
auto st = static_cast<const td_api::chatMemberStatusCreator *>(status.get());
|
||||
@ -592,13 +606,13 @@ DialogParticipantStatus get_dialog_participant_status(const td_api::object_ptr<t
|
||||
case td_api::chatMemberStatusRestricted::ID: {
|
||||
auto st = static_cast<const td_api::chatMemberStatusRestricted *>(status.get());
|
||||
return DialogParticipantStatus::Restricted(RestrictedRights(st->permissions_), st->is_member_,
|
||||
st->restricted_until_date_);
|
||||
fix_until_date(st->restricted_until_date_));
|
||||
}
|
||||
case td_api::chatMemberStatusLeft::ID:
|
||||
return DialogParticipantStatus::Left();
|
||||
case td_api::chatMemberStatusBanned::ID: {
|
||||
auto st = static_cast<const td_api::chatMemberStatusBanned *>(status.get());
|
||||
return DialogParticipantStatus::Banned(st->banned_until_date_);
|
||||
return DialogParticipantStatus::Banned(fix_until_date(st->banned_until_date_));
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
|
Loading…
Reference in New Issue
Block a user