mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Save admins in legacy groups.
This commit is contained in:
parent
dba9ca2084
commit
07e010dfb5
@ -272,10 +272,11 @@ void AddSpecialBoxController::prepareChatRows(not_null<ChatData*> chat) {
|
|||||||
|
|
||||||
using UpdateFlag = Notify::PeerUpdate::Flag;
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
||||||
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(
|
||||||
UpdateFlag::MembersChanged,
|
UpdateFlag::MembersChanged | UpdateFlag::AdminsChanged,
|
||||||
[=](const Notify::PeerUpdate &update) {
|
[=](const Notify::PeerUpdate &update) {
|
||||||
if (update.flags & UpdateFlag::MembersChanged) {
|
if (update.peer == chat) {
|
||||||
if (update.peer == chat) {
|
_additional.fillFromPeer();
|
||||||
|
if (update.flags & UpdateFlag::MembersChanged) {
|
||||||
rebuildChatRows(chat);
|
rebuildChatRows(chat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,21 +506,16 @@ void AddSpecialBoxController::showAdmin(
|
|||||||
: MTPChatAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
: MTPChatAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||||
auto box = Box<EditAdminBox>(_peer, user, currentRights);
|
auto box = Box<EditAdminBox>(_peer, user, currentRights);
|
||||||
if (_additional.canAddOrEditAdmin(user)) {
|
if (_additional.canAddOrEditAdmin(user)) {
|
||||||
if (chat) {
|
const auto done = crl::guard(this, [=](
|
||||||
// #TODO groups autoconv
|
const MTPChatAdminRights &newRights) {
|
||||||
} else {
|
editAdminDone(user, newRights);
|
||||||
const auto done = crl::guard(this, [=](
|
});
|
||||||
const MTPChatAdminRights &newRights) {
|
const auto fail = crl::guard(this, [=] {
|
||||||
editAdminDone(user, newRights);
|
if (_editBox) {
|
||||||
});
|
_editBox->closeBox();
|
||||||
const auto fail = crl::guard(this, [=] {
|
}
|
||||||
if (_editBox) {
|
});
|
||||||
_editBox->closeBox();
|
box->setSaveCallback(SaveAdminCallback(_peer, user, done, fail));
|
||||||
}
|
|
||||||
});
|
|
||||||
box->setSaveCallback(
|
|
||||||
SaveAdminCallback(channel, user, done, fail));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
@ -604,9 +600,7 @@ void AddSpecialBoxController::showRestricted(
|
|||||||
user,
|
user,
|
||||||
_additional.adminRights(user).has_value(),
|
_additional.adminRights(user).has_value(),
|
||||||
currentRights);
|
currentRights);
|
||||||
if (chat) {
|
if (_additional.canRestrictUser(user)) {
|
||||||
// #TODO groups autoconv
|
|
||||||
} else {
|
|
||||||
const auto done = crl::guard(this, [=](
|
const auto done = crl::guard(this, [=](
|
||||||
const MTPChatBannedRights &newRights) {
|
const MTPChatBannedRights &newRights) {
|
||||||
editRestrictedDone(user, newRights);
|
editRestrictedDone(user, newRights);
|
||||||
@ -617,7 +611,7 @@ void AddSpecialBoxController::showRestricted(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
box->setSaveCallback(
|
box->setSaveCallback(
|
||||||
SaveRestrictedCallback(channel, user, done, fail));
|
SaveRestrictedCallback(_peer, user, done, fail));
|
||||||
}
|
}
|
||||||
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ void RemoveAdmin(
|
|||||||
not_null<ChannelData*> channel,
|
not_null<ChannelData*> channel,
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
const MTPChatAdminRights &oldRights,
|
const MTPChatAdminRights &oldRights,
|
||||||
Fn<void()> onDone) {
|
Fn<void()> onDone,
|
||||||
|
Fn<void()> onFail) {
|
||||||
const auto newRights = MTP_chatAdminRights(MTP_flags(0));
|
const auto newRights = MTP_chatAdminRights(MTP_flags(0));
|
||||||
channel->session().api().request(MTPchannels_EditAdmin(
|
channel->session().api().request(MTPchannels_EditAdmin(
|
||||||
channel->inputChannel,
|
channel->inputChannel,
|
||||||
@ -46,22 +47,102 @@ void RemoveAdmin(
|
|||||||
)).done([=](const MTPUpdates &result) {
|
)).done([=](const MTPUpdates &result) {
|
||||||
channel->session().api().applyUpdates(result);
|
channel->session().api().applyUpdates(result);
|
||||||
channel->applyEditAdmin(user, oldRights, newRights);
|
channel->applyEditAdmin(user, oldRights, newRights);
|
||||||
onDone();
|
if (const auto done = onDone) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
if (const auto fail = onFail) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditChatAdmin(
|
void SaveChatAdmin(
|
||||||
not_null<ChatData*> chat,
|
not_null<ChatData*> chat,
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
bool isAdmin,
|
bool isAdmin,
|
||||||
Fn<void()> onDone) {
|
Fn<void()> onDone,
|
||||||
|
Fn<void()> onFail) {
|
||||||
chat->session().api().request(MTPmessages_EditChatAdmin(
|
chat->session().api().request(MTPmessages_EditChatAdmin(
|
||||||
chat->inputChat,
|
chat->inputChat,
|
||||||
user->inputUser,
|
user->inputUser,
|
||||||
MTP_bool(isAdmin)
|
MTP_bool(isAdmin)
|
||||||
)).done([=](const MTPBool &result) {
|
)).done([=](const MTPBool &result) {
|
||||||
chat->applyEditAdmin(user, isAdmin);
|
chat->applyEditAdmin(user, isAdmin);
|
||||||
onDone();
|
if (const auto done = onDone) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
if (const auto fail = onFail) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SaveChannelAdmin(
|
||||||
|
not_null<ChannelData*> channel,
|
||||||
|
not_null<UserData*> user,
|
||||||
|
const MTPChatAdminRights &oldRights,
|
||||||
|
const MTPChatAdminRights &newRights,
|
||||||
|
Fn<void()> onDone,
|
||||||
|
Fn<void()> onFail) {
|
||||||
|
channel->session().api().request(MTPchannels_EditAdmin(
|
||||||
|
channel->inputChannel,
|
||||||
|
user->inputUser,
|
||||||
|
newRights
|
||||||
|
)).done([=](const MTPUpdates &result) {
|
||||||
|
channel->session().api().applyUpdates(result);
|
||||||
|
channel->applyEditAdmin(user, oldRights, newRights);
|
||||||
|
if (const auto done = onDone) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) {
|
||||||
|
Ui::show(
|
||||||
|
Box<InformBox>(PeerFloodErrorText(
|
||||||
|
channel->isMegagroup()
|
||||||
|
? PeerFloodType::InviteGroup
|
||||||
|
: PeerFloodType::InviteChannel)),
|
||||||
|
LayerOption::KeepOther);
|
||||||
|
} else if (error.type() == qstr("BOT_GROUPS_BLOCKED")) {
|
||||||
|
Ui::show(
|
||||||
|
Box<InformBox>(lang(lng_error_cant_add_bot)),
|
||||||
|
LayerOption::KeepOther);
|
||||||
|
} else if (error.type() == qstr("ADMINS_TOO_MUCH")) {
|
||||||
|
Ui::show(
|
||||||
|
Box<InformBox>(lang(channel->isMegagroup()
|
||||||
|
? lng_error_admin_limit
|
||||||
|
: lng_error_admin_limit_channel)),
|
||||||
|
LayerOption::KeepOther);
|
||||||
|
}
|
||||||
|
if (const auto fail = onFail) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SaveChannelRestriction(
|
||||||
|
not_null<ChannelData*> channel,
|
||||||
|
not_null<UserData*> user,
|
||||||
|
const MTPChatBannedRights &oldRights,
|
||||||
|
const MTPChatBannedRights &newRights,
|
||||||
|
Fn<void()> onDone,
|
||||||
|
Fn<void()> onFail) {
|
||||||
|
channel->session().api().request(MTPchannels_EditBanned(
|
||||||
|
channel->inputChannel,
|
||||||
|
user->inputUser,
|
||||||
|
newRights
|
||||||
|
)).done([=](const MTPUpdates &result) {
|
||||||
|
const auto done = onDone;
|
||||||
|
channel->session().api().applyUpdates(result);
|
||||||
|
channel->applyEditBanned(user, oldRights, newRights);
|
||||||
|
if (const auto done = onDone) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
if (const auto fail = onFail) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,82 +151,75 @@ void EditChatAdmin(
|
|||||||
Fn<void(
|
Fn<void(
|
||||||
const MTPChatAdminRights &oldRights,
|
const MTPChatAdminRights &oldRights,
|
||||||
const MTPChatAdminRights &newRights)> SaveAdminCallback(
|
const MTPChatAdminRights &newRights)> SaveAdminCallback(
|
||||||
not_null<ChannelData*> channel,
|
not_null<PeerData*> peer,
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
Fn<void(const MTPChatAdminRights &newRights)> onDone,
|
Fn<void(const MTPChatAdminRights &newRights)> onDone,
|
||||||
Fn<void()> onFail) {
|
Fn<void()> onFail) {
|
||||||
return [=](
|
return [=](
|
||||||
const MTPChatAdminRights &oldRights,
|
const MTPChatAdminRights &oldRights,
|
||||||
const MTPChatAdminRights &newRights) {
|
const MTPChatAdminRights &newRights) {
|
||||||
auto done = [=](const MTPUpdates &result) {
|
const auto done = [=] { onDone(newRights); };
|
||||||
channel->session().api().applyUpdates(result);
|
if (const auto chat = peer->asChat()) {
|
||||||
channel->applyEditAdmin(user, oldRights, newRights);
|
const auto saveChatAdmin = [&](bool isAdmin) {
|
||||||
onDone(newRights);
|
SaveChatAdmin(chat, user, isAdmin, done, onFail);
|
||||||
};
|
};
|
||||||
auto fail = [=](const RPCError &error) {
|
const auto flags = newRights.match([](
|
||||||
if (MTP::isDefaultHandledError(error)) {
|
const MTPDchatAdminRights &data) {
|
||||||
return false;
|
return data.vflags.v;
|
||||||
|
});
|
||||||
|
if (flags == ChatData::DefaultAdminRights()) {
|
||||||
|
saveChatAdmin(true);
|
||||||
|
} else if (!flags) {
|
||||||
|
saveChatAdmin(false);
|
||||||
|
} else {
|
||||||
|
// #TODO groups autoconv
|
||||||
}
|
}
|
||||||
if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) {
|
} else if (const auto channel = peer->asChannel()) {
|
||||||
Ui::show(
|
SaveChannelAdmin(
|
||||||
Box<InformBox>(PeerFloodErrorText(
|
channel,
|
||||||
channel->isMegagroup()
|
user,
|
||||||
? PeerFloodType::InviteGroup
|
oldRights,
|
||||||
: PeerFloodType::InviteChannel)),
|
newRights,
|
||||||
LayerOption::KeepOther);
|
done,
|
||||||
} else if (error.type() == qstr("BOT_GROUPS_BLOCKED")) {
|
onFail);
|
||||||
Ui::show(
|
} else {
|
||||||
Box<InformBox>(lang(lng_error_cant_add_bot)),
|
Unexpected("Peer in SaveAdminCallback.");
|
||||||
LayerOption::KeepOther);
|
}
|
||||||
} else if (error.type() == qstr("ADMINS_TOO_MUCH")) {
|
|
||||||
Ui::show(
|
|
||||||
Box<InformBox>(lang(channel->isMegagroup()
|
|
||||||
? lng_error_admin_limit
|
|
||||||
: lng_error_admin_limit_channel)),
|
|
||||||
LayerOption::KeepOther);
|
|
||||||
}
|
|
||||||
onFail();
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
MTP::send(
|
|
||||||
MTPchannels_EditAdmin(
|
|
||||||
channel->inputChannel,
|
|
||||||
user->inputUser,
|
|
||||||
newRights),
|
|
||||||
rpcDone(std::move(done)),
|
|
||||||
rpcFail(std::move(fail)));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Fn<void(
|
Fn<void(
|
||||||
const MTPChatBannedRights &oldRights,
|
const MTPChatBannedRights &oldRights,
|
||||||
const MTPChatBannedRights &newRights)> SaveRestrictedCallback(
|
const MTPChatBannedRights &newRights)> SaveRestrictedCallback(
|
||||||
not_null<ChannelData*> channel,
|
not_null<PeerData*> peer,
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
Fn<void(const MTPChatBannedRights &newRights)> onDone,
|
Fn<void(const MTPChatBannedRights &newRights)> onDone,
|
||||||
Fn<void()> onFail) {
|
Fn<void()> onFail) {
|
||||||
return [=](
|
return [=](
|
||||||
const MTPChatBannedRights &oldRights,
|
const MTPChatBannedRights &oldRights,
|
||||||
const MTPChatBannedRights &newRights) {
|
const MTPChatBannedRights &newRights) {
|
||||||
auto done = [=](const MTPUpdates &result) {
|
const auto done = [=] { onDone(newRights); };
|
||||||
channel->session().api().applyUpdates(result);
|
if (const auto chat = peer->asChat()) {
|
||||||
channel->applyEditBanned(user, oldRights, newRights);
|
const auto flags = newRights.match([](
|
||||||
onDone(newRights);
|
const MTPDchatBannedRights &data) {
|
||||||
};
|
return data.vflags.v;
|
||||||
auto fail = [=](const RPCError &error) {
|
});
|
||||||
if (MTP::isDefaultHandledError(error)) {
|
if (!flags) {
|
||||||
return false;
|
done();
|
||||||
|
} else {
|
||||||
|
// #TODO groups autoconv
|
||||||
}
|
}
|
||||||
onFail();
|
} else if (const auto channel = peer->asChannel()) {
|
||||||
return true;
|
SaveChannelRestriction(
|
||||||
};
|
channel,
|
||||||
MTP::send(
|
user,
|
||||||
MTPchannels_EditBanned(
|
oldRights,
|
||||||
channel->inputChannel,
|
newRights,
|
||||||
user->inputUser,
|
done,
|
||||||
newRights),
|
onFail);
|
||||||
rpcDone(std::move(done)),
|
} else {
|
||||||
rpcFail(std::move(fail)));
|
Unexpected("Peer in SaveAdminCallback.");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,13 +228,7 @@ ParticipantsAdditionalData::ParticipantsAdditionalData(
|
|||||||
Role role)
|
Role role)
|
||||||
: _peer(peer)
|
: _peer(peer)
|
||||||
, _role(role) {
|
, _role(role) {
|
||||||
if (const auto chat = _peer->asChat()) {
|
fillFromPeer();
|
||||||
_creator = chat->owner().userLoaded(chat->creator);
|
|
||||||
} else if (const auto channel = _peer->asChannel()) {
|
|
||||||
if (channel->mgInfo) {
|
|
||||||
_creator = channel->mgInfo->creator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParticipantsAdditionalData::infoLoaded(not_null<UserData*> user) const {
|
bool ParticipantsAdditionalData::infoLoaded(not_null<UserData*> user) const {
|
||||||
@ -294,6 +362,9 @@ void ParticipantsAdditionalData::fillFromPeer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantsAdditionalData::fillFromChat(not_null<ChatData*> chat) {
|
void ParticipantsAdditionalData::fillFromChat(not_null<ChatData*> chat) {
|
||||||
|
if (const auto creator = chat->owner().userLoaded(chat->creator)) {
|
||||||
|
_creator = creator;
|
||||||
|
}
|
||||||
if (chat->participants.empty()) {
|
if (chat->participants.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -404,6 +475,10 @@ UserData *ParticipantsAdditionalData::applyAdmin(
|
|||||||
const auto user = _peer->owner().userLoaded(data.vuser_id.v);
|
const auto user = _peer->owner().userLoaded(data.vuser_id.v);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
} else if (const auto chat = _peer->asChat()) {
|
||||||
|
// This can come from saveAdmin callback.
|
||||||
|
_admins.emplace(user);
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
_infoNotLoaded.erase(user);
|
_infoNotLoaded.erase(user);
|
||||||
@ -434,6 +509,10 @@ UserData *ParticipantsAdditionalData::applyRegular(MTPint userId) {
|
|||||||
const auto user = _peer->owner().userLoaded(userId.v);
|
const auto user = _peer->owner().userLoaded(userId.v);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
} else if (const auto chat = _peer->asChat()) {
|
||||||
|
// This can come from saveAdmin or saveRestricted callback.
|
||||||
|
_admins.erase(user);
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
_infoNotLoaded.erase(user);
|
_infoNotLoaded.erase(user);
|
||||||
@ -883,18 +962,16 @@ void ParticipantsBoxController::prepareChatRows(not_null<ChatData*> chat) {
|
|||||||
UpdateFlag::MembersChanged
|
UpdateFlag::MembersChanged
|
||||||
| UpdateFlag::AdminsChanged,
|
| UpdateFlag::AdminsChanged,
|
||||||
[=](const Notify::PeerUpdate &update) {
|
[=](const Notify::PeerUpdate &update) {
|
||||||
if (update.flags & UpdateFlag::MembersChanged) {
|
if (update.peer != chat) {
|
||||||
if (update.peer == chat) {
|
return;
|
||||||
rebuildChatRows(chat);
|
}
|
||||||
}
|
_additional.fillFromPeer();
|
||||||
} else if (update.flags & UpdateFlag::AdminsChanged) {
|
if ((update.flags & UpdateFlag::MembersChanged)
|
||||||
if (update.peer == chat) {
|
|| (_role == Role::Admins)) {
|
||||||
if (_role == Role::Members || _role == Role::Profile) {
|
rebuildChatRows(chat);
|
||||||
rebuildRowTypes();
|
}
|
||||||
} else if (_role == Role::Admins) {
|
if (update.flags & UpdateFlag::AdminsChanged) {
|
||||||
rebuildChatRows(chat);
|
rebuildRowTypes();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -905,7 +982,7 @@ void ParticipantsBoxController::rebuildChatRows(not_null<ChatData*> chat) {
|
|||||||
case Role::Members: return rebuildChatParticipants(chat);
|
case Role::Members: return rebuildChatParticipants(chat);
|
||||||
case Role::Admins: return rebuildChatAdmins(chat);
|
case Role::Admins: return rebuildChatAdmins(chat);
|
||||||
case Role::Restricted:
|
case Role::Restricted:
|
||||||
case Role::Kicked: return;
|
case Role::Kicked: return chatListReady();
|
||||||
}
|
}
|
||||||
Unexpected("Role in ParticipantsBoxController::rebuildChatRows");
|
Unexpected("Role in ParticipantsBoxController::rebuildChatRows");
|
||||||
}
|
}
|
||||||
@ -942,7 +1019,7 @@ void ParticipantsBoxController::rebuildChatParticipants(
|
|||||||
_onlineSorter->sort();
|
_onlineSorter->sort();
|
||||||
|
|
||||||
delegate()->peerListRefreshRows();
|
delegate()->peerListRefreshRows();
|
||||||
setNonEmptyDescription();
|
chatListReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantsBoxController::rebuildChatAdmins(
|
void ParticipantsBoxController::rebuildChatAdmins(
|
||||||
@ -992,10 +1069,25 @@ void ParticipantsBoxController::rebuildChatAdmins(
|
|||||||
}
|
}
|
||||||
|
|
||||||
delegate()->peerListRefreshRows();
|
delegate()->peerListRefreshRows();
|
||||||
setNonEmptyDescription();
|
chatListReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticipantsBoxController::chatListReady() {
|
||||||
|
if (_allLoaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_allLoaded = true;
|
||||||
|
if (delegate()->peerListFullRowsCount() > 0) {
|
||||||
|
setNonEmptyDescription();
|
||||||
|
} else {
|
||||||
|
setDescriptionText(lang(lng_blocked_list_not_found));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantsBoxController::rebuildRowTypes() {
|
void ParticipantsBoxController::rebuildRowTypes() {
|
||||||
|
if (_role != Role::Profile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto count = delegate()->peerListFullRowsCount();
|
const auto count = delegate()->peerListFullRowsCount();
|
||||||
for (auto i = 0; i != count; ++i) {
|
for (auto i = 0; i != count; ++i) {
|
||||||
const auto row = static_cast<Row*>(
|
const auto row = static_cast<Row*>(
|
||||||
@ -1220,21 +1312,16 @@ void ParticipantsBoxController::showAdmin(not_null<UserData*> user) {
|
|||||||
const auto chat = _peer->asChat();
|
const auto chat = _peer->asChat();
|
||||||
const auto channel = _peer->asChannel();
|
const auto channel = _peer->asChannel();
|
||||||
if (_additional.canAddOrEditAdmin(user)) {
|
if (_additional.canAddOrEditAdmin(user)) {
|
||||||
if (chat) {
|
const auto done = crl::guard(this, [=](
|
||||||
// #TODO groups autoconv
|
const MTPChatAdminRights &newRights) {
|
||||||
} else if (channel) {
|
editAdminDone(user, newRights);
|
||||||
const auto done = crl::guard(this, [=](
|
});
|
||||||
const MTPChatAdminRights &newRights) {
|
const auto fail = crl::guard(this, [=] {
|
||||||
editAdminDone(user, newRights);
|
if (_editBox) {
|
||||||
});
|
_editBox->closeBox();
|
||||||
const auto fail = crl::guard(this, [=] {
|
}
|
||||||
if (_editBox) {
|
});
|
||||||
_editBox->closeBox();
|
box->setSaveCallback(SaveAdminCallback(_peer, user, done, fail));
|
||||||
}
|
|
||||||
});
|
|
||||||
box->setSaveCallback(
|
|
||||||
SaveAdminCallback(channel, user, done, fail));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
@ -1293,21 +1380,17 @@ void ParticipantsBoxController::showRestricted(not_null<UserData*> user) {
|
|||||||
const auto chat = _peer->asChat();
|
const auto chat = _peer->asChat();
|
||||||
const auto channel = _peer->asChannel();
|
const auto channel = _peer->asChannel();
|
||||||
if (_additional.canRestrictUser(user)) {
|
if (_additional.canRestrictUser(user)) {
|
||||||
if (chat) {
|
const auto done = crl::guard(this, [=](
|
||||||
// #TODO groups autoconv
|
const MTPChatBannedRights &newRights) {
|
||||||
} else {
|
editRestrictedDone(user, newRights);
|
||||||
const auto done = crl::guard(this, [=](
|
});
|
||||||
const MTPChatBannedRights &newRights) {
|
const auto fail = crl::guard(this, [=] {
|
||||||
editRestrictedDone(user, newRights);
|
if (_editBox) {
|
||||||
});
|
_editBox->closeBox();
|
||||||
const auto fail = crl::guard(this, [=] {
|
}
|
||||||
if (_editBox) {
|
});
|
||||||
_editBox->closeBox();
|
box->setSaveCallback(
|
||||||
}
|
SaveRestrictedCallback(_peer, user, done, fail));
|
||||||
});
|
|
||||||
box->setSaveCallback(
|
|
||||||
SaveRestrictedCallback(channel, user, done, fail));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
@ -1415,9 +1498,9 @@ void ParticipantsBoxController::removeAdminSure(not_null<UserData*> user) {
|
|||||||
_editBox->closeBox();
|
_editBox->closeBox();
|
||||||
}
|
}
|
||||||
if (const auto chat = _peer->asChat()) {
|
if (const auto chat = _peer->asChat()) {
|
||||||
EditChatAdmin(chat, user, false, crl::guard(this, [=] {
|
SaveChatAdmin(chat, user, false, crl::guard(this, [=] {
|
||||||
editAdminDone(user, MTP_chatAdminRights(MTP_flags(0)));
|
editAdminDone(user, MTP_chatAdminRights(MTP_flags(0)));
|
||||||
}));
|
}), nullptr);
|
||||||
} else if (const auto channel = _peer->asChannel()) {
|
} else if (const auto channel = _peer->asChannel()) {
|
||||||
const auto adminRights = _additional.adminRights(user);
|
const auto adminRights = _additional.adminRights(user);
|
||||||
if (!adminRights) {
|
if (!adminRights) {
|
||||||
@ -1425,7 +1508,7 @@ void ParticipantsBoxController::removeAdminSure(not_null<UserData*> user) {
|
|||||||
}
|
}
|
||||||
RemoveAdmin(channel, user, *adminRights, crl::guard(this, [=] {
|
RemoveAdmin(channel, user, *adminRights, crl::guard(this, [=] {
|
||||||
editAdminDone(user, MTP_chatAdminRights(MTP_flags(0)));
|
editAdminDone(user, MTP_chatAdminRights(MTP_flags(0)));
|
||||||
}));
|
}), nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1530,7 +1613,7 @@ void ParticipantsBoxController::recomputeTypeFor(
|
|||||||
if (_role != Role::Profile) {
|
if (_role != Role::Profile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auto row = delegate()->peerListFindRow(user->id)) {
|
if (const auto row = delegate()->peerListFindRow(user->id)) {
|
||||||
static_cast<Row*>(row)->setType(computeType(user));
|
static_cast<Row*>(row)->setType(computeType(user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class Navigation;
|
|||||||
Fn<void(
|
Fn<void(
|
||||||
const MTPChatAdminRights &oldRights,
|
const MTPChatAdminRights &oldRights,
|
||||||
const MTPChatAdminRights &newRights)> SaveAdminCallback(
|
const MTPChatAdminRights &newRights)> SaveAdminCallback(
|
||||||
not_null<ChannelData*> channel,
|
not_null<PeerData*> peer,
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
Fn<void(const MTPChatAdminRights &newRights)> onDone,
|
Fn<void(const MTPChatAdminRights &newRights)> onDone,
|
||||||
Fn<void()> onFail);
|
Fn<void()> onFail);
|
||||||
@ -31,7 +31,7 @@ Fn<void(
|
|||||||
Fn<void(
|
Fn<void(
|
||||||
const MTPChatBannedRights &oldRights,
|
const MTPChatBannedRights &oldRights,
|
||||||
const MTPChatBannedRights &newRights)> SaveRestrictedCallback(
|
const MTPChatBannedRights &newRights)> SaveRestrictedCallback(
|
||||||
not_null<ChannelData*> channel,
|
not_null<PeerData*> peer,
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
Fn<void(const MTPChatBannedRights &newRights)> onDone,
|
Fn<void(const MTPChatBannedRights &newRights)> onDone,
|
||||||
Fn<void()> onFail);
|
Fn<void()> onFail);
|
||||||
@ -187,6 +187,7 @@ private:
|
|||||||
void rebuildChatRows(not_null<ChatData*> chat);
|
void rebuildChatRows(not_null<ChatData*> chat);
|
||||||
void rebuildChatParticipants(not_null<ChatData*> chat);
|
void rebuildChatParticipants(not_null<ChatData*> chat);
|
||||||
void rebuildChatAdmins(not_null<ChatData*> chat);
|
void rebuildChatAdmins(not_null<ChatData*> chat);
|
||||||
|
void chatListReady();
|
||||||
void rebuildRowTypes();
|
void rebuildRowTypes();
|
||||||
|
|
||||||
void addNewItem();
|
void addNewItem();
|
||||||
|
@ -104,15 +104,15 @@ void ChatMembersController::prepare() {
|
|||||||
| UpdateFlag::UserOnlineChanged
|
| UpdateFlag::UserOnlineChanged
|
||||||
| UpdateFlag::AdminsChanged,
|
| UpdateFlag::AdminsChanged,
|
||||||
[this](const Notify::PeerUpdate &update) {
|
[this](const Notify::PeerUpdate &update) {
|
||||||
if (update.flags & UpdateFlag::MembersChanged) {
|
if (update.peer == _chat) {
|
||||||
if (update.peer == _chat) {
|
if (update.flags & UpdateFlag::MembersChanged) {
|
||||||
rebuildRows();
|
rebuildRows();
|
||||||
}
|
}
|
||||||
} else if (update.flags & UpdateFlag::AdminsChanged) {
|
if (update.flags & UpdateFlag::AdminsChanged) {
|
||||||
if (update.peer == _chat) {
|
|
||||||
rebuildRowTypes();
|
rebuildRowTypes();
|
||||||
}
|
}
|
||||||
} else if (update.flags & UpdateFlag::UserOnlineChanged) {
|
}
|
||||||
|
if (update.flags & UpdateFlag::UserOnlineChanged) {
|
||||||
if (auto row = delegate()->peerListFindRow(
|
if (auto row = delegate()->peerListFindRow(
|
||||||
update.peer->id)) {
|
update.peer->id)) {
|
||||||
row->refreshStatus();
|
row->refreshStatus();
|
||||||
|
@ -198,7 +198,9 @@ rpl::producer<int> AdminsCountValue(not_null<PeerData*> peer) {
|
|||||||
chat,
|
chat,
|
||||||
Flag::AdminsChanged | Flag::RightsChanged
|
Flag::AdminsChanged | Flag::RightsChanged
|
||||||
) | rpl::map([=] {
|
) | rpl::map([=] {
|
||||||
return int(chat->admins.size());
|
return chat->participants.empty()
|
||||||
|
? 0
|
||||||
|
: int(chat->admins.size() + 1); // + creator
|
||||||
});
|
});
|
||||||
} else if (const auto channel = peer->asChannel()) {
|
} else if (const auto channel = peer->asChannel()) {
|
||||||
return Notify::PeerUpdateValue(
|
return Notify::PeerUpdateValue(
|
||||||
|
@ -109,13 +109,14 @@ void GroupMembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
|||||||
if (update.flags & UpdateFlag::MembersChanged) {
|
if (update.flags & UpdateFlag::MembersChanged) {
|
||||||
refreshMembers();
|
refreshMembers();
|
||||||
contentSizeUpdated();
|
contentSizeUpdated();
|
||||||
} else if (update.flags & UpdateFlag::AdminsChanged) {
|
}
|
||||||
if (auto chat = peer()->asChat()) {
|
if (update.flags & UpdateFlag::AdminsChanged) {
|
||||||
for_const (auto item, items()) {
|
if (const auto chat = peer()->asChat()) {
|
||||||
|
for (const auto item : items()) {
|
||||||
setItemFlags(getMember(item), chat);
|
setItemFlags(getMember(item), chat);
|
||||||
}
|
}
|
||||||
} else if (auto megagroup = peer()->asMegagroup()) {
|
} else if (const auto megagroup = peer()->asMegagroup()) {
|
||||||
for_const (auto item, items()) {
|
for (const auto item : items()) {
|
||||||
setItemFlags(getMember(item), megagroup);
|
setItemFlags(getMember(item), megagroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user