mirror of https://github.com/procxx/kepka.git
Unify permissions checks in participants boxes.
This commit is contained in:
parent
e1a2ab0d7e
commit
9a60e744d3
|
@ -87,7 +87,7 @@ void ShowAddParticipantsError(
|
||||||
const auto makeAdmin = [=] {
|
const auto makeAdmin = [=] {
|
||||||
const auto user = users.front();
|
const auto user = users.front();
|
||||||
const auto weak = std::make_shared<QPointer<EditAdminBox>>();
|
const auto weak = std::make_shared<QPointer<EditAdminBox>>();
|
||||||
const auto close = [=] {
|
const auto close = [=](auto&&...) {
|
||||||
if (*weak) {
|
if (*weak) {
|
||||||
(*weak)->closeBox();
|
(*weak)->closeBox();
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ void ShowAddParticipantsError(
|
||||||
const auto saveCallback = SaveAdminCallback(
|
const auto saveCallback = SaveAdminCallback(
|
||||||
channel,
|
channel,
|
||||||
user,
|
user,
|
||||||
[=](auto&&...) { close(); },
|
close,
|
||||||
close);
|
close);
|
||||||
auto box = Box<EditAdminBox>(
|
auto box = Box<EditAdminBox>(
|
||||||
channel,
|
channel,
|
||||||
|
|
|
@ -62,7 +62,7 @@ bool InviteSelectedUsers(
|
||||||
if (users.empty()) {
|
if (users.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Auth().api().addChatParticipants(chat, users);
|
chat->session().api().addChatParticipants(chat, users);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,11 @@ void AddParticipantsBoxController::Start(not_null<ChatData*> chat) {
|
||||||
});
|
});
|
||||||
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
|
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
|
||||||
};
|
};
|
||||||
Ui::show(Box<PeerListBox>(std::make_unique<AddParticipantsBoxController>(chat), std::move(initBox)));
|
Ui::show(
|
||||||
|
Box<PeerListBox>(
|
||||||
|
std::make_unique<AddParticipantsBoxController>(chat),
|
||||||
|
std::move(initBox)),
|
||||||
|
LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddParticipantsBoxController::Start(
|
void AddParticipantsBoxController::Start(
|
||||||
|
@ -192,7 +196,13 @@ void AddParticipantsBoxController::Start(
|
||||||
}, *subscription);
|
}, *subscription);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ui::show(Box<PeerListBox>(std::make_unique<AddParticipantsBoxController>(channel, std::move(alreadyIn)), std::move(initBox)));
|
Ui::show(
|
||||||
|
Box<PeerListBox>(
|
||||||
|
std::make_unique<AddParticipantsBoxController>(
|
||||||
|
channel,
|
||||||
|
std::move(alreadyIn)),
|
||||||
|
std::move(initBox)),
|
||||||
|
LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddParticipantsBoxController::Start(
|
void AddParticipantsBoxController::Start(
|
||||||
|
@ -215,9 +225,9 @@ AddSpecialBoxController::AddSpecialBoxController(
|
||||||
&_additional))
|
&_additional))
|
||||||
, _peer(peer)
|
, _peer(peer)
|
||||||
, _role(role)
|
, _role(role)
|
||||||
|
, _additional(peer, Role::Members)
|
||||||
, _adminDoneCallback(std::move(adminDoneCallback))
|
, _adminDoneCallback(std::move(adminDoneCallback))
|
||||||
, _bannedDoneCallback(std::move(bannedDoneCallback)) {
|
, _bannedDoneCallback(std::move(bannedDoneCallback)) {
|
||||||
_additional.fillCreator(_peer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<PeerListRow> AddSpecialBoxController::createSearchRow(not_null<PeerData*> peer) {
|
std::unique_ptr<PeerListRow> AddSpecialBoxController::createSearchRow(not_null<PeerData*> peer) {
|
||||||
|
@ -305,6 +315,7 @@ void AddSpecialBoxController::rebuildChatRows(not_null<ChatData*> chat) {
|
||||||
_onlineSorter->sort();
|
_onlineSorter->sort();
|
||||||
|
|
||||||
delegate()->peerListRefreshRows();
|
delegate()->peerListRefreshRows();
|
||||||
|
setDescriptionText(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSpecialBoxController::loadMoreRows() {
|
void AddSpecialBoxController::loadMoreRows() {
|
||||||
|
@ -329,17 +340,16 @@ void AddSpecialBoxController::loadMoreRows() {
|
||||||
MTP_int(participantsHash)
|
MTP_int(participantsHash)
|
||||||
)).done([=](const MTPchannels_ChannelParticipants &result) {
|
)).done([=](const MTPchannels_ChannelParticipants &result) {
|
||||||
_loadRequestId = 0;
|
_loadRequestId = 0;
|
||||||
|
auto &session = channel->session();
|
||||||
Auth().api().parseChannelParticipants(channel, result, [&](
|
session.api().parseChannelParticipants(channel, result, [&](
|
||||||
int availableCount,
|
int availableCount,
|
||||||
const QVector<MTPChannelParticipant> &list) {
|
const QVector<MTPChannelParticipant> &list) {
|
||||||
for (auto &participant : list) {
|
for (const auto &data : list) {
|
||||||
HandleParticipant(
|
if (const auto user = _additional.applyParticipant(data)) {
|
||||||
participant,
|
appendRow(user);
|
||||||
&_additional,
|
}
|
||||||
[&](auto user) { appendRow(user); });
|
|
||||||
}
|
}
|
||||||
if (auto size = list.size()) {
|
if (const auto size = list.size()) {
|
||||||
_offset += size;
|
_offset += size;
|
||||||
} else {
|
} else {
|
||||||
// To be sure - wait for a whole empty result list.
|
// To be sure - wait for a whole empty result list.
|
||||||
|
@ -372,9 +382,7 @@ template <typename Callback>
|
||||||
bool AddSpecialBoxController::checkInfoLoaded(
|
bool AddSpecialBoxController::checkInfoLoaded(
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
Callback callback) {
|
Callback callback) {
|
||||||
if (_peer->isChat()
|
if (_additional.infoLoaded(user)) {
|
||||||
|| (_additional.infoNotLoaded.find(user)
|
|
||||||
== _additional.infoNotLoaded.end())) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,15 +396,10 @@ bool AddSpecialBoxController::checkInfoLoaded(
|
||||||
|
|
||||||
const auto &participant = result.c_channels_channelParticipant();
|
const auto &participant = result.c_channels_channelParticipant();
|
||||||
App::feedUsers(participant.vusers);
|
App::feedUsers(participant.vusers);
|
||||||
HandleParticipant(
|
_additional.applyParticipant(participant.vparticipant);
|
||||||
participant.vparticipant,
|
|
||||||
&_additional,
|
|
||||||
[](not_null<UserData*>) {});
|
|
||||||
_additional.infoNotLoaded.erase(user);
|
|
||||||
callback();
|
callback();
|
||||||
}).fail([this, user, callback](const RPCError &error) {
|
}).fail([=](const RPCError &error) {
|
||||||
_additional.infoNotLoaded.erase(user);
|
_additional.setExternal(user);
|
||||||
_additional.external.emplace(user);
|
|
||||||
callback();
|
callback();
|
||||||
}).send();
|
}).send();
|
||||||
return false;
|
return false;
|
||||||
|
@ -416,6 +419,9 @@ void AddSpecialBoxController::showAdmin(
|
||||||
|
|
||||||
const auto chat = _peer->asChat();
|
const auto chat = _peer->asChat();
|
||||||
const auto channel = _peer->asChannel();
|
const auto channel = _peer->asChannel();
|
||||||
|
const auto showAdminSure = crl::guard(this, [=] {
|
||||||
|
showAdmin(user, true);
|
||||||
|
});
|
||||||
|
|
||||||
// Check restrictions.
|
// Check restrictions.
|
||||||
const auto canAddMembers = chat
|
const auto canAddMembers = chat
|
||||||
|
@ -424,24 +430,19 @@ void AddSpecialBoxController::showAdmin(
|
||||||
const auto canBanMembers = chat
|
const auto canBanMembers = chat
|
||||||
? chat->canBanMembers()
|
? chat->canBanMembers()
|
||||||
: channel->canBanMembers();
|
: channel->canBanMembers();
|
||||||
const auto weak = base::make_weak(this);
|
const auto adminRights = _additional.adminRights(user);
|
||||||
const auto alreadyIt = _additional.adminRights.find(user);
|
if (adminRights.has_value()) {
|
||||||
auto currentRights = (_additional.creator == user)
|
|
||||||
? MTP_chatAdminRights(MTP_flags(~MTPDchatAdminRights::Flag::f_add_admins | MTPDchatAdminRights::Flag::f_add_admins))
|
|
||||||
: MTP_chatAdminRights(MTP_flags(0));
|
|
||||||
if (alreadyIt != _additional.adminRights.end()) {
|
|
||||||
// The user is already an admin.
|
// The user is already an admin.
|
||||||
currentRights = alreadyIt->second;
|
} else if (_additional.isKicked(user)) {
|
||||||
} else if (_additional.kicked.find(user) != _additional.kicked.end()) {
|
|
||||||
// The user is banned.
|
// The user is banned.
|
||||||
if (canAddMembers) {
|
if (canAddMembers) {
|
||||||
if (canBanMembers) {
|
if (canBanMembers) {
|
||||||
if (!sure) {
|
if (!sure) {
|
||||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_add_admin_unban), [weak, user] {
|
_editBox = Ui::show(
|
||||||
if (weak) {
|
Box<ConfirmBox>(
|
||||||
weak->showAdmin(user, true);
|
lang(lng_sure_add_admin_unban),
|
||||||
}
|
showAdminSure),
|
||||||
}), LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -456,15 +457,15 @@ void AddSpecialBoxController::showAdmin(
|
||||||
LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (_additional.restrictedRights.find(user) != _additional.restrictedRights.end()) {
|
} else if (_additional.restrictedRights(user).has_value()) {
|
||||||
// The user is restricted.
|
// The user is restricted.
|
||||||
if (canBanMembers) {
|
if (canBanMembers) {
|
||||||
if (!sure) {
|
if (!sure) {
|
||||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_add_admin_unban), [weak, user] {
|
_editBox = Ui::show(
|
||||||
if (weak) {
|
Box<ConfirmBox>(
|
||||||
weak->showAdmin(user, true);
|
lang(lng_sure_add_admin_unban),
|
||||||
}
|
showAdminSure),
|
||||||
}), LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -473,7 +474,7 @@ void AddSpecialBoxController::showAdmin(
|
||||||
LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (_additional.external.find(user) != _additional.external.end()) {
|
} else if (_additional.isExternal(user)) {
|
||||||
// The user is not in the group yet.
|
// The user is not in the group yet.
|
||||||
if (canAddMembers) {
|
if (canAddMembers) {
|
||||||
if (!sure) {
|
if (!sure) {
|
||||||
|
@ -481,11 +482,11 @@ void AddSpecialBoxController::showAdmin(
|
||||||
((_peer->isChat() || _peer->isMegagroup())
|
((_peer->isChat() || _peer->isMegagroup())
|
||||||
? lng_sure_add_admin_invite
|
? lng_sure_add_admin_invite
|
||||||
: lng_sure_add_admin_invite_channel));
|
: lng_sure_add_admin_invite_channel));
|
||||||
_editBox = Ui::show(Box<ConfirmBox>(text, [=] {
|
_editBox = Ui::show(
|
||||||
if (weak) {
|
Box<ConfirmBox>(
|
||||||
weak->showAdmin(user, true);
|
text,
|
||||||
}
|
showAdminSure),
|
||||||
}), LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -497,24 +498,29 @@ void AddSpecialBoxController::showAdmin(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally show the admin.
|
// Finally show the admin.
|
||||||
auto canNotEdit = (_additional.creator == user)
|
const auto currentRights = _additional.isCreator(user)
|
||||||
|| ((alreadyIt != _additional.adminRights.end())
|
? MTPChatAdminRights(MTP_chatAdminRights(
|
||||||
&& (_additional.adminCanEdit.find(user) == _additional.adminCanEdit.end()));
|
MTP_flags(~MTPDchatAdminRights::Flag::f_add_admins
|
||||||
|
| MTPDchatAdminRights::Flag::f_add_admins)))
|
||||||
|
: adminRights
|
||||||
|
? *adminRights
|
||||||
|
: MTPChatAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||||
auto box = Box<EditAdminBox>(_peer, user, currentRights);
|
auto box = Box<EditAdminBox>(_peer, user, currentRights);
|
||||||
if (!canNotEdit) {
|
if (_additional.canAddOrEditAdmin(user)) {
|
||||||
if (chat) {
|
if (chat) {
|
||||||
// #TODO groups autoconv
|
// #TODO groups autoconv
|
||||||
} else {
|
} else {
|
||||||
box->setSaveCallback(SaveAdminCallback(channel, user, [=](
|
const auto done = crl::guard(this, [=](
|
||||||
const MTPChatAdminRights &newRights) {
|
const MTPChatAdminRights &newRights) {
|
||||||
if (weak) {
|
editAdminDone(user, newRights);
|
||||||
weak->editAdminDone(user, newRights);
|
});
|
||||||
|
const auto fail = crl::guard(this, [=] {
|
||||||
|
if (_editBox) {
|
||||||
|
_editBox->closeBox();
|
||||||
}
|
}
|
||||||
}, [=] {
|
});
|
||||||
if (weak && weak->_editBox) {
|
box->setSaveCallback(
|
||||||
weak->_editBox->closeBox();
|
SaveAdminCallback(channel, user, done, fail));
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
||||||
|
@ -524,24 +530,26 @@ void AddSpecialBoxController::editAdminDone(
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
const MTPChatAdminRights &rights) {
|
const MTPChatAdminRights &rights) {
|
||||||
if (_editBox) _editBox->closeBox();
|
if (_editBox) _editBox->closeBox();
|
||||||
_additional.restrictedRights.erase(user);
|
|
||||||
_additional.restrictedBy.erase(user);
|
const auto date = unixtime(); // Incorrect, but ignored.
|
||||||
_additional.kicked.erase(user);
|
|
||||||
_additional.external.erase(user);
|
|
||||||
if (rights.c_chatAdminRights().vflags.v == 0) {
|
if (rights.c_chatAdminRights().vflags.v == 0) {
|
||||||
_additional.adminRights.erase(user);
|
_additional.applyParticipant(MTP_channelParticipant(
|
||||||
_additional.adminPromotedBy.erase(user);
|
MTP_int(user->bareId()),
|
||||||
_additional.adminCanEdit.erase(user);
|
MTP_int(date)));
|
||||||
} else {
|
} else {
|
||||||
_additional.adminRights[user] = rights;
|
const auto alreadyPromotedBy = _additional.adminPromotedBy(user);
|
||||||
_additional.adminCanEdit.emplace(user);
|
_additional.applyParticipant(MTP_channelParticipantAdmin(
|
||||||
auto it = _additional.adminPromotedBy.find(user);
|
MTP_flags(MTPDchannelParticipantAdmin::Flag::f_can_edit),
|
||||||
if (it == _additional.adminPromotedBy.end()) {
|
MTP_int(user->bareId()),
|
||||||
_additional.adminPromotedBy.emplace(user, Auth().user());
|
MTPint(), // inviter_id
|
||||||
}
|
MTP_int(alreadyPromotedBy
|
||||||
|
? alreadyPromotedBy->bareId()
|
||||||
|
: user->session().userId()),
|
||||||
|
MTP_int(date),
|
||||||
|
rights));
|
||||||
}
|
}
|
||||||
if (_adminDoneCallback) {
|
if (const auto callback = _adminDoneCallback) {
|
||||||
_adminDoneCallback(user, rights);
|
callback(user, rights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,25 +567,24 @@ void AddSpecialBoxController::showRestricted(
|
||||||
|
|
||||||
const auto chat = _peer->asChat();
|
const auto chat = _peer->asChat();
|
||||||
const auto channel = _peer->asChannel();
|
const auto channel = _peer->asChannel();
|
||||||
|
const auto showRestrictedSure = crl::guard(this, [=] {
|
||||||
|
showRestricted(user, true);
|
||||||
|
});
|
||||||
|
|
||||||
// Check restrictions.
|
// Check restrictions.
|
||||||
const auto weak = base::make_weak(this);
|
const auto restrictedRights = _additional.restrictedRights(user);
|
||||||
const auto alreadyIt = _additional.restrictedRights.find(user);
|
if (restrictedRights.has_value()) {
|
||||||
auto currentRights = MTP_chatBannedRights(MTP_flags(0), MTP_int(0));
|
|
||||||
auto hasAdminRights = false;
|
|
||||||
if (alreadyIt != _additional.restrictedRights.end()) {
|
|
||||||
// The user is already banned or restricted.
|
// The user is already banned or restricted.
|
||||||
currentRights = alreadyIt->second;
|
} else if (_additional.adminRights(user).has_value()
|
||||||
} else if (_additional.adminRights.find(user) != _additional.adminRights.end() || _additional.creator == user) {
|
|| _additional.isCreator(user)) {
|
||||||
// The user is an admin or creator.
|
// The user is an admin or creator.
|
||||||
if (_additional.adminCanEdit.find(user) != _additional.adminCanEdit.end()) {
|
if (_additional.canEditAdmin(user)) {
|
||||||
hasAdminRights = true;
|
|
||||||
if (!sure) {
|
if (!sure) {
|
||||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_ban_admin), [weak, user] {
|
_editBox = Ui::show(
|
||||||
if (weak) {
|
Box<ConfirmBox>(
|
||||||
weak->showRestricted(user, true);
|
lang(lng_sure_ban_admin),
|
||||||
}
|
showRestrictedSure),
|
||||||
}), LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -589,20 +596,30 @@ void AddSpecialBoxController::showRestricted(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally edit the restricted.
|
// Finally edit the restricted.
|
||||||
auto box = Box<EditRestrictedBox>(_peer, user, hasAdminRights, currentRights);
|
const auto currentRights = restrictedRights
|
||||||
|
? *restrictedRights
|
||||||
|
: MTPChatBannedRights(MTP_chatBannedRights(
|
||||||
|
MTP_flags(0),
|
||||||
|
MTP_int(0)));
|
||||||
|
auto box = Box<EditRestrictedBox>(
|
||||||
|
_peer,
|
||||||
|
user,
|
||||||
|
_additional.adminRights(user).has_value(),
|
||||||
|
currentRights);
|
||||||
if (chat) {
|
if (chat) {
|
||||||
// #TODO groups autoconv
|
// #TODO groups autoconv
|
||||||
} else {
|
} else {
|
||||||
box->setSaveCallback(SaveRestrictedCallback(channel, user, [=](
|
const auto done = crl::guard(this, [=](
|
||||||
const MTPChatBannedRights &newRights) {
|
const MTPChatBannedRights &newRights) {
|
||||||
if (const auto strong = weak.get()) {
|
editRestrictedDone(user, newRights);
|
||||||
strong->editRestrictedDone(user, newRights);
|
});
|
||||||
|
const auto fail = crl::guard(this, [=] {
|
||||||
|
if (_editBox) {
|
||||||
|
_editBox->closeBox();
|
||||||
}
|
}
|
||||||
}, [=] {
|
});
|
||||||
if (weak && weak->_editBox) {
|
box->setSaveCallback(
|
||||||
weak->_editBox->closeBox();
|
SaveRestrictedCallback(channel, user, done, fail));
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
|
@ -611,24 +628,28 @@ void AddSpecialBoxController::editRestrictedDone(
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
const MTPChatBannedRights &rights) {
|
const MTPChatBannedRights &rights) {
|
||||||
if (_editBox) _editBox->closeBox();
|
if (_editBox) _editBox->closeBox();
|
||||||
_additional.adminRights.erase(user);
|
|
||||||
_additional.adminCanEdit.erase(user);
|
const auto date = unixtime(); // Incorrect, but ignored.
|
||||||
_additional.adminPromotedBy.erase(user);
|
|
||||||
if (rights.c_chatBannedRights().vflags.v == 0) {
|
if (rights.c_chatBannedRights().vflags.v == 0) {
|
||||||
_additional.restrictedRights.erase(user);
|
_additional.applyParticipant(MTP_channelParticipant(
|
||||||
_additional.restrictedBy.erase(user);
|
MTP_int(user->bareId()),
|
||||||
_additional.kicked.erase(user);
|
MTP_int(date)));
|
||||||
} else {
|
} else {
|
||||||
_additional.restrictedRights[user] = rights;
|
const auto kicked = rights.c_chatBannedRights().is_view_messages();
|
||||||
if (rights.c_chatBannedRights().vflags.v & MTPDchatBannedRights::Flag::f_view_messages) {
|
const auto alreadyRestrictedBy = _additional.restrictedBy(user);
|
||||||
_additional.kicked.emplace(user);
|
_additional.applyParticipant(MTP_channelParticipantBanned(
|
||||||
} else {
|
MTP_flags(kicked
|
||||||
_additional.kicked.erase(user);
|
? MTPDchannelParticipantBanned::Flag::f_left
|
||||||
}
|
: MTPDchannelParticipantBanned::Flag(0)),
|
||||||
_additional.restrictedBy.emplace(user, Auth().user());
|
MTP_int(user->bareId()),
|
||||||
|
MTP_int(alreadyRestrictedBy
|
||||||
|
? alreadyRestrictedBy->bareId()
|
||||||
|
: user->session().userId()),
|
||||||
|
MTP_int(date),
|
||||||
|
rights));
|
||||||
}
|
}
|
||||||
if (_bannedDoneCallback) {
|
if (const auto callback = _bannedDoneCallback) {
|
||||||
_bannedDoneCallback(user, rights);
|
callback(user, rights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,17 +660,21 @@ void AddSpecialBoxController::kickUser(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto kickUserSure = crl::guard(this, [=] {
|
||||||
|
kickUser(user, true);
|
||||||
|
});
|
||||||
|
|
||||||
// Check restrictions.
|
// Check restrictions.
|
||||||
auto weak = base::make_weak(this);
|
if (_additional.adminRights(user).has_value()
|
||||||
if (_additional.adminRights.find(user) != _additional.adminRights.end() || _additional.creator == user) {
|
|| _additional.isCreator(user)) {
|
||||||
// The user is an admin or creator.
|
// The user is an admin or creator.
|
||||||
if (_additional.adminCanEdit.find(user) != _additional.adminCanEdit.end()) {
|
if (_additional.canEditAdmin(user)) {
|
||||||
if (!sure) {
|
if (!sure) {
|
||||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_ban_admin), [weak, user] {
|
_editBox = Ui::show(
|
||||||
if (weak) {
|
Box<ConfirmBox>(
|
||||||
weak->kickUser(user, true);
|
lang(lng_sure_ban_admin),
|
||||||
}
|
kickUserSure),
|
||||||
}), LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -665,25 +690,22 @@ void AddSpecialBoxController::kickUser(
|
||||||
const auto text = ((_peer->isChat() || _peer->isMegagroup())
|
const auto text = ((_peer->isChat() || _peer->isMegagroup())
|
||||||
? lng_sure_ban_user_group
|
? lng_sure_ban_user_group
|
||||||
: lng_sure_ban_user_channel)(lt_user, App::peerName(user));
|
: lng_sure_ban_user_channel)(lt_user, App::peerName(user));
|
||||||
_editBox = Ui::show(Box<ConfirmBox>(text, [=] {
|
_editBox = Ui::show(
|
||||||
if (weak) {
|
Box<ConfirmBox>(text, kickUserSure),
|
||||||
weak->kickUser(user, true);
|
LayerOption::KeepOther);
|
||||||
}
|
|
||||||
}), LayerOption::KeepOther);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto currentRights = MTP_chatBannedRights(MTP_flags(0), MTP_int(0));
|
const auto restrictedRights = _additional.restrictedRights(user);
|
||||||
auto alreadyIt = _additional.restrictedRights.find(user);
|
const auto currentRights = restrictedRights
|
||||||
if (alreadyIt != _additional.restrictedRights.end()) {
|
? *restrictedRights
|
||||||
// The user is already banned or restricted.
|
: MTPChatBannedRights(MTP_chatBannedRights(
|
||||||
currentRights = alreadyIt->second;
|
MTP_flags(0),
|
||||||
}
|
MTP_int(0)));
|
||||||
|
auto &session = _peer->session();
|
||||||
if (const auto chat = _peer->asChat()) {
|
if (const auto chat = _peer->asChat()) {
|
||||||
// #TODO groups
|
session.api().kickParticipant(chat, user);
|
||||||
} else if (const auto channel = _peer->asChannel()) {
|
} else if (const auto channel = _peer->asChannel()) {
|
||||||
const auto callback = SaveRestrictedCallback(channel, user, [](
|
session.api().kickParticipant(channel, user, currentRights);
|
||||||
const MTPChatBannedRights &newRights) {}, [] {});
|
|
||||||
callback(currentRights, ChannelData::KickedRestrictedRights());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,90 +730,9 @@ std::unique_ptr<PeerListRow> AddSpecialBoxController::createRow(
|
||||||
return std::make_unique<PeerListRow>(user);
|
return std::make_unique<PeerListRow>(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Callback>
|
|
||||||
void AddSpecialBoxController::HandleParticipant(
|
|
||||||
const MTPChannelParticipant &participant,
|
|
||||||
not_null<Additional*> additional,
|
|
||||||
Callback callback) {
|
|
||||||
switch (participant.type()) {
|
|
||||||
case mtpc_channelParticipantAdmin: {
|
|
||||||
auto &admin = participant.c_channelParticipantAdmin();
|
|
||||||
if (auto user = App::userLoaded(admin.vuser_id.v)) {
|
|
||||||
additional->infoNotLoaded.erase(user);
|
|
||||||
additional->restrictedRights.erase(user);
|
|
||||||
additional->kicked.erase(user);
|
|
||||||
additional->restrictedBy.erase(user);
|
|
||||||
additional->adminRights[user] = admin.vadmin_rights;
|
|
||||||
if (admin.is_can_edit()) {
|
|
||||||
additional->adminCanEdit.emplace(user);
|
|
||||||
} else {
|
|
||||||
additional->adminCanEdit.erase(user);
|
|
||||||
}
|
|
||||||
if (auto promoted = App::userLoaded(admin.vpromoted_by.v)) {
|
|
||||||
auto it = additional->adminPromotedBy.find(user);
|
|
||||||
if (it == additional->adminPromotedBy.end()) {
|
|
||||||
additional->adminPromotedBy.emplace(user, promoted);
|
|
||||||
} else {
|
|
||||||
it->second = promoted;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG(("API Error: No user %1 for admin promoted by.").arg(admin.vpromoted_by.v));
|
|
||||||
}
|
|
||||||
callback(user);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case mtpc_channelParticipantCreator: {
|
|
||||||
auto &creator = participant.c_channelParticipantCreator();
|
|
||||||
if (auto user = App::userLoaded(creator.vuser_id.v)) {
|
|
||||||
additional->infoNotLoaded.erase(user);
|
|
||||||
additional->creator = user;
|
|
||||||
callback(user);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case mtpc_channelParticipantBanned: {
|
|
||||||
auto &banned = participant.c_channelParticipantBanned();
|
|
||||||
if (auto user = App::userLoaded(banned.vuser_id.v)) {
|
|
||||||
additional->infoNotLoaded.erase(user);
|
|
||||||
additional->adminRights.erase(user);
|
|
||||||
additional->adminCanEdit.erase(user);
|
|
||||||
additional->adminPromotedBy.erase(user);
|
|
||||||
if (banned.is_left()) {
|
|
||||||
additional->kicked.emplace(user);
|
|
||||||
} else {
|
|
||||||
additional->kicked.erase(user);
|
|
||||||
}
|
|
||||||
additional->restrictedRights[user] = banned.vbanned_rights;
|
|
||||||
if (auto kickedby = App::userLoaded(banned.vkicked_by.v)) {
|
|
||||||
auto it = additional->restrictedBy.find(user);
|
|
||||||
if (it == additional->restrictedBy.end()) {
|
|
||||||
additional->restrictedBy.emplace(user, kickedby);
|
|
||||||
} else {
|
|
||||||
it->second = kickedby;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
callback(user);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case mtpc_channelParticipant: {
|
|
||||||
auto &data = participant.c_channelParticipant();
|
|
||||||
if (auto user = App::userLoaded(data.vuser_id.v)) {
|
|
||||||
additional->infoNotLoaded.erase(user);
|
|
||||||
additional->adminRights.erase(user);
|
|
||||||
additional->adminCanEdit.erase(user);
|
|
||||||
additional->adminPromotedBy.erase(user);
|
|
||||||
additional->restrictedRights.erase(user);
|
|
||||||
additional->kicked.erase(user);
|
|
||||||
additional->restrictedBy.erase(user);
|
|
||||||
callback(user);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
default: Unexpected("Participant type in AddSpecialBoxController::HandleParticipant()");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AddSpecialBoxSearchController::AddSpecialBoxSearchController(
|
AddSpecialBoxSearchController::AddSpecialBoxSearchController(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
not_null<Additional*> additional)
|
not_null<ParticipantsAdditionalData*> additional)
|
||||||
: _peer(peer)
|
: _peer(peer)
|
||||||
, _additional(additional)
|
, _additional(additional)
|
||||||
, _timer([=] { searchOnServer(); }) {
|
, _timer([=] { searchOnServer(); }) {
|
||||||
|
@ -914,7 +855,8 @@ void AddSpecialBoxSearchController::searchParticipantsDone(
|
||||||
const auto channel = _peer->asChannel();
|
const auto channel = _peer->asChannel();
|
||||||
auto query = _query;
|
auto query = _query;
|
||||||
if (requestId) {
|
if (requestId) {
|
||||||
Auth().api().parseChannelParticipants(channel, result, [&](auto&&...) {
|
auto &session = channel->session();
|
||||||
|
session.api().parseChannelParticipants(channel, result, [&](auto&&...) {
|
||||||
auto it = _participantsQueries.find(requestId);
|
auto it = _participantsQueries.find(requestId);
|
||||||
if (it != _participantsQueries.cend()) {
|
if (it != _participantsQueries.cend()) {
|
||||||
query = it->second.text;
|
query = it->second.text;
|
||||||
|
@ -945,14 +887,10 @@ void AddSpecialBoxSearchController::searchParticipantsDone(
|
||||||
loadMoreRows();
|
loadMoreRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto addUser = [&](auto user) {
|
for (const auto &data : list) {
|
||||||
delegate()->peerListSearchAddRow(user);
|
if (const auto user = _additional->applyParticipant(data)) {
|
||||||
};
|
delegate()->peerListSearchAddRow(user);
|
||||||
for (auto &participant : list) {
|
}
|
||||||
AddSpecialBoxController::HandleParticipant(
|
|
||||||
participant,
|
|
||||||
_additional,
|
|
||||||
addUser);
|
|
||||||
}
|
}
|
||||||
_offset += list.size();
|
_offset += list.size();
|
||||||
}, [&](mtpTypeId type) {
|
}, [&](mtpTypeId type) {
|
||||||
|
@ -984,7 +922,9 @@ void AddSpecialBoxSearchController::requestGlobal() {
|
||||||
_globalQueries.emplace(_requestId, _query);
|
_globalQueries.emplace(_requestId, _query);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSpecialBoxSearchController::searchGlobalDone(mtpRequestId requestId, const MTPcontacts_Found &result) {
|
void AddSpecialBoxSearchController::searchGlobalDone(
|
||||||
|
mtpRequestId requestId,
|
||||||
|
const MTPcontacts_Found &result) {
|
||||||
Expects(result.type() == mtpc_contacts_found);
|
Expects(result.type() == mtpc_contacts_found);
|
||||||
|
|
||||||
auto &found = result.c_contacts_found();
|
auto &found = result.c_contacts_found();
|
||||||
|
@ -1001,20 +941,11 @@ void AddSpecialBoxSearchController::searchGlobalDone(mtpRequestId requestId, con
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto feedList = [&](const MTPVector<MTPPeer> &list) {
|
const auto feedList = [&](const MTPVector<MTPPeer> &list) {
|
||||||
const auto contains = [](const auto &map, const auto &value) {
|
|
||||||
return map.find(value) != map.end();
|
|
||||||
};
|
|
||||||
for (const auto &mtpPeer : list.v) {
|
for (const auto &mtpPeer : list.v) {
|
||||||
const auto peerId = peerFromMTP(mtpPeer);
|
const auto peerId = peerFromMTP(mtpPeer);
|
||||||
if (const auto peer = App::peerLoaded(peerId)) {
|
if (const auto peer = App::peerLoaded(peerId)) {
|
||||||
if (const auto user = peer->asUser()) {
|
if (const auto user = peer->asUser()) {
|
||||||
if (_additional->creator != user
|
_additional->checkForLoaded(user);
|
||||||
&& !contains(_additional->adminRights, user)
|
|
||||||
&& !contains(_additional->restrictedRights, user)
|
|
||||||
&& !contains(_additional->external, user)
|
|
||||||
&& !contains(_additional->kicked, user)) {
|
|
||||||
_additional->infoNotLoaded.emplace(user);
|
|
||||||
}
|
|
||||||
delegate()->peerListSearchAddRow(user);
|
delegate()->peerListSearchAddRow(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ class AddSpecialBoxController
|
||||||
, public base::has_weak_ptr {
|
, public base::has_weak_ptr {
|
||||||
public:
|
public:
|
||||||
using Role = ParticipantsBoxController::Role;
|
using Role = ParticipantsBoxController::Role;
|
||||||
using Additional = ParticipantsBoxController::Additional;
|
|
||||||
|
|
||||||
using AdminDoneCallback = Fn<void(
|
using AdminDoneCallback = Fn<void(
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
|
@ -80,13 +79,6 @@ public:
|
||||||
std::unique_ptr<PeerListRow> createSearchRow(
|
std::unique_ptr<PeerListRow> createSearchRow(
|
||||||
not_null<PeerData*> peer) override;
|
not_null<PeerData*> peer) override;
|
||||||
|
|
||||||
// Callback(not_null<UserData*>)
|
|
||||||
template <typename Callback>
|
|
||||||
static void HandleParticipant(
|
|
||||||
const MTPChannelParticipant &participant,
|
|
||||||
not_null<Additional*> additional,
|
|
||||||
Callback callback);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
bool checkInfoLoaded(not_null<UserData*> user, Callback callback);
|
bool checkInfoLoaded(not_null<UserData*> user, Callback callback);
|
||||||
|
@ -116,7 +108,7 @@ private:
|
||||||
int _offset = 0;
|
int _offset = 0;
|
||||||
mtpRequestId _loadRequestId = 0;
|
mtpRequestId _loadRequestId = 0;
|
||||||
bool _allLoaded = false;
|
bool _allLoaded = false;
|
||||||
Additional _additional;
|
ParticipantsAdditionalData _additional;
|
||||||
std::unique_ptr<ParticipantsOnlineSorter> _onlineSorter;
|
std::unique_ptr<ParticipantsOnlineSorter> _onlineSorter;
|
||||||
QPointer<BoxContent> _editBox;
|
QPointer<BoxContent> _editBox;
|
||||||
AdminDoneCallback _adminDoneCallback;
|
AdminDoneCallback _adminDoneCallback;
|
||||||
|
@ -130,11 +122,10 @@ class AddSpecialBoxSearchController
|
||||||
, private MTP::Sender {
|
, private MTP::Sender {
|
||||||
public:
|
public:
|
||||||
using Role = ParticipantsBoxController::Role;
|
using Role = ParticipantsBoxController::Role;
|
||||||
using Additional = ParticipantsBoxController::Additional;
|
|
||||||
|
|
||||||
AddSpecialBoxSearchController(
|
AddSpecialBoxSearchController(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
not_null<Additional*> additional);
|
not_null<ParticipantsAdditionalData*> additional);
|
||||||
|
|
||||||
void searchQuery(const QString &query) override;
|
void searchQuery(const QString &query) override;
|
||||||
bool isLoading() override;
|
bool isLoading() override;
|
||||||
|
@ -166,7 +157,7 @@ private:
|
||||||
void requestGlobal();
|
void requestGlobal();
|
||||||
|
|
||||||
not_null<PeerData*> _peer;
|
not_null<PeerData*> _peer;
|
||||||
not_null<Additional*> _additional;
|
not_null<ParticipantsAdditionalData*> _additional;
|
||||||
|
|
||||||
base::Timer _timer;
|
base::Timer _timer;
|
||||||
QString _query;
|
QString _query;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
#include "info/profile/info_profile_members_controllers.h"
|
#include "info/profile/info_profile_members_controllers.h"
|
||||||
|
|
||||||
|
struct MegagroupInfo;
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
class Navigation;
|
class Navigation;
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
@ -34,6 +36,14 @@ Fn<void(
|
||||||
Fn<void(const MTPChatBannedRights &newRights)> onDone,
|
Fn<void(const MTPChatBannedRights &newRights)> onDone,
|
||||||
Fn<void()> onFail);
|
Fn<void()> onFail);
|
||||||
|
|
||||||
|
enum class ParticipantsRole {
|
||||||
|
Profile,
|
||||||
|
Members,
|
||||||
|
Admins,
|
||||||
|
Restricted,
|
||||||
|
Kicked,
|
||||||
|
};
|
||||||
|
|
||||||
class ParticipantsOnlineSorter : private base::Subscriber {
|
class ParticipantsOnlineSorter : private base::Subscriber {
|
||||||
public:
|
public:
|
||||||
ParticipantsOnlineSorter(
|
ParticipantsOnlineSorter(
|
||||||
|
@ -54,6 +64,62 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ParticipantsAdditionalData {
|
||||||
|
public:
|
||||||
|
using Role = ParticipantsRole;
|
||||||
|
|
||||||
|
ParticipantsAdditionalData(not_null<PeerData*> peer, Role role);
|
||||||
|
|
||||||
|
UserData *applyParticipant(const MTPChannelParticipant &data);
|
||||||
|
UserData *applyParticipant(
|
||||||
|
const MTPChannelParticipant &data,
|
||||||
|
Role overrideRole);
|
||||||
|
void setExternal(not_null<UserData*> user);
|
||||||
|
void checkForLoaded(not_null<UserData*> user);
|
||||||
|
void fillFromPeer();
|
||||||
|
|
||||||
|
[[nodiscard]] bool infoLoaded(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] bool canEditAdmin(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] bool canAddOrEditAdmin(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] bool canRestrictUser(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] std::optional<MTPChatAdminRights> adminRights(
|
||||||
|
not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] std::optional<MTPChatBannedRights> restrictedRights(
|
||||||
|
not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] bool isCreator(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] bool isExternal(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] bool isKicked(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] UserData *adminPromotedBy(not_null<UserData*> user) const;
|
||||||
|
[[nodiscard]] UserData *restrictedBy(not_null<UserData*> user) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UserData *applyCreator(const MTPDchannelParticipantCreator &data);
|
||||||
|
UserData *applyAdmin(const MTPDchannelParticipantAdmin &data);
|
||||||
|
UserData *applyRegular(MTPint userId);
|
||||||
|
UserData *applyBanned(const MTPDchannelParticipantBanned &data);
|
||||||
|
void fillFromChat(not_null<ChatData*> chat);
|
||||||
|
void fillFromChannel(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
|
not_null<PeerData*> _peer;
|
||||||
|
Role _role = Role::Members;
|
||||||
|
UserData *_creator = nullptr;
|
||||||
|
|
||||||
|
// Data for chats.
|
||||||
|
base::flat_set<not_null<UserData*>> _members;
|
||||||
|
base::flat_set<not_null<UserData*>> _admins;
|
||||||
|
|
||||||
|
// Data for channels.
|
||||||
|
base::flat_map<not_null<UserData*>, MTPChatAdminRights> _adminRights;
|
||||||
|
base::flat_set<not_null<UserData*>> _adminCanEdit;
|
||||||
|
base::flat_map<not_null<UserData*>, not_null<UserData*>> _adminPromotedBy;
|
||||||
|
std::map<not_null<UserData*>, MTPChatBannedRights> _restrictedRights;
|
||||||
|
std::set<not_null<UserData*>> _kicked;
|
||||||
|
std::map<not_null<UserData*>, not_null<UserData*>> _restrictedBy;
|
||||||
|
std::set<not_null<UserData*>> _external;
|
||||||
|
std::set<not_null<UserData*>> _infoNotLoaded;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// Viewing admins, banned or restricted users list with search.
|
// Viewing admins, banned or restricted users list with search.
|
||||||
class ParticipantsBoxController
|
class ParticipantsBoxController
|
||||||
: public PeerListController
|
: public PeerListController
|
||||||
|
@ -61,32 +127,13 @@ class ParticipantsBoxController
|
||||||
, private MTP::Sender
|
, private MTP::Sender
|
||||||
, public base::has_weak_ptr {
|
, public base::has_weak_ptr {
|
||||||
public:
|
public:
|
||||||
enum class Role {
|
using Role = ParticipantsRole;
|
||||||
Profile,
|
|
||||||
Members,
|
|
||||||
Admins,
|
|
||||||
Restricted,
|
|
||||||
Kicked,
|
|
||||||
};
|
|
||||||
static void Start(
|
static void Start(
|
||||||
not_null<Window::Navigation*> navigation,
|
not_null<Window::Navigation*> navigation,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
Role role);
|
Role role);
|
||||||
|
|
||||||
struct Additional {
|
|
||||||
void fillCreator(not_null<PeerData*> peer);
|
|
||||||
|
|
||||||
std::map<not_null<UserData*>, MTPChatAdminRights> adminRights;
|
|
||||||
std::set<not_null<UserData*>> adminCanEdit;
|
|
||||||
std::map<not_null<UserData*>, not_null<UserData*>> adminPromotedBy;
|
|
||||||
std::map<not_null<UserData*>, MTPChatBannedRights> restrictedRights;
|
|
||||||
std::set<not_null<UserData*>> kicked;
|
|
||||||
std::map<not_null<UserData*>, not_null<UserData*>> restrictedBy;
|
|
||||||
std::set<not_null<UserData*>> external;
|
|
||||||
std::set<not_null<UserData*>> infoNotLoaded;
|
|
||||||
UserData *creator = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
ParticipantsBoxController(
|
ParticipantsBoxController(
|
||||||
not_null<Window::Navigation*> navigation,
|
not_null<Window::Navigation*> navigation,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
|
@ -109,14 +156,6 @@ public:
|
||||||
std::unique_ptr<PeerListState> saveState() const override;
|
std::unique_ptr<PeerListState> saveState() const override;
|
||||||
void restoreState(std::unique_ptr<PeerListState> state) override;
|
void restoreState(std::unique_ptr<PeerListState> state) override;
|
||||||
|
|
||||||
// Callback(not_null<UserData*>)
|
|
||||||
template <typename Callback>
|
|
||||||
static void HandleParticipant(
|
|
||||||
const MTPChannelParticipant &participant,
|
|
||||||
Role role,
|
|
||||||
not_null<Additional*> additional,
|
|
||||||
Callback callback);
|
|
||||||
|
|
||||||
rpl::producer<int> onlineCountValue() const override;
|
rpl::producer<int> onlineCountValue() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -128,22 +167,26 @@ private:
|
||||||
using Type = Row::Type;
|
using Type = Row::Type;
|
||||||
using Rights = Row::Rights;
|
using Rights = Row::Rights;
|
||||||
struct SavedState : SavedStateBase {
|
struct SavedState : SavedStateBase {
|
||||||
|
explicit SavedState(const ParticipantsAdditionalData &additional);
|
||||||
|
|
||||||
using SearchStateBase = PeerListSearchController::SavedStateBase;
|
using SearchStateBase = PeerListSearchController::SavedStateBase;
|
||||||
std::unique_ptr<SearchStateBase> searchState;
|
std::unique_ptr<SearchStateBase> searchState;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
bool allLoaded = false;
|
bool allLoaded = false;
|
||||||
bool wasLoading = false;
|
bool wasLoading = false;
|
||||||
Additional additional;
|
ParticipantsAdditionalData additional;
|
||||||
rpl::lifetime lifetime;
|
rpl::lifetime lifetime;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::unique_ptr<PeerListSearchController> CreateSearchController(
|
static std::unique_ptr<PeerListSearchController> CreateSearchController(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
Role role,
|
Role role,
|
||||||
not_null<Additional*> additional);
|
not_null<ParticipantsAdditionalData*> additional);
|
||||||
|
|
||||||
void prepareChatRows(not_null<ChatData*> chat);
|
void prepareChatRows(not_null<ChatData*> chat);
|
||||||
void rebuildChatRows(not_null<ChatData*> chat);
|
void rebuildChatRows(not_null<ChatData*> chat);
|
||||||
|
void rebuildChatParticipants(not_null<ChatData*> chat);
|
||||||
|
void rebuildChatAdmins(not_null<ChatData*> chat);
|
||||||
void rebuildRowTypes();
|
void rebuildRowTypes();
|
||||||
|
|
||||||
void addNewItem();
|
void addNewItem();
|
||||||
|
@ -169,12 +212,8 @@ private:
|
||||||
bool removeRow(not_null<UserData*> user);
|
bool removeRow(not_null<UserData*> user);
|
||||||
void refreshCustomStatus(not_null<PeerListRow*> row) const;
|
void refreshCustomStatus(not_null<PeerListRow*> row) const;
|
||||||
bool feedMegagroupLastParticipants();
|
bool feedMegagroupLastParticipants();
|
||||||
void refreshOnlineCount();
|
|
||||||
Type computeType(not_null<UserData*> user) const;
|
Type computeType(not_null<UserData*> user) const;
|
||||||
void recomputeTypeFor(not_null<UserData*> user);
|
void recomputeTypeFor(not_null<UserData*> user);
|
||||||
bool canEditAdmin(not_null<UserData*> user) const;
|
|
||||||
bool canRestrictUser(not_null<UserData*> user) const;
|
|
||||||
bool canEditAdminByRights(not_null<UserData*> user) const;
|
|
||||||
|
|
||||||
not_null<Window::Navigation*> _navigation;
|
not_null<Window::Navigation*> _navigation;
|
||||||
not_null<PeerData*> _peer;
|
not_null<PeerData*> _peer;
|
||||||
|
@ -182,7 +221,7 @@ private:
|
||||||
int _offset = 0;
|
int _offset = 0;
|
||||||
mtpRequestId _loadRequestId = 0;
|
mtpRequestId _loadRequestId = 0;
|
||||||
bool _allLoaded = false;
|
bool _allLoaded = false;
|
||||||
Additional _additional;
|
ParticipantsAdditionalData _additional;
|
||||||
std::unique_ptr<ParticipantsOnlineSorter> _onlineSorter;
|
std::unique_ptr<ParticipantsOnlineSorter> _onlineSorter;
|
||||||
QPointer<BoxContent> _editBox;
|
QPointer<BoxContent> _editBox;
|
||||||
QPointer<PeerListBox> _addBox;
|
QPointer<PeerListBox> _addBox;
|
||||||
|
@ -195,12 +234,11 @@ class ParticipantsBoxSearchController
|
||||||
, private MTP::Sender {
|
, private MTP::Sender {
|
||||||
public:
|
public:
|
||||||
using Role = ParticipantsBoxController::Role;
|
using Role = ParticipantsBoxController::Role;
|
||||||
using Additional = ParticipantsBoxController::Additional;
|
|
||||||
|
|
||||||
ParticipantsBoxSearchController(
|
ParticipantsBoxSearchController(
|
||||||
not_null<ChannelData*> channel,
|
not_null<ChannelData*> channel,
|
||||||
Role role,
|
Role role,
|
||||||
not_null<Additional*> additional);
|
not_null<ParticipantsAdditionalData*> additional);
|
||||||
|
|
||||||
void searchQuery(const QString &query) override;
|
void searchQuery(const QString &query) override;
|
||||||
bool isLoading() override;
|
bool isLoading() override;
|
||||||
|
@ -234,7 +272,7 @@ private:
|
||||||
|
|
||||||
not_null<ChannelData*> _channel;
|
not_null<ChannelData*> _channel;
|
||||||
Role _role = Role::Restricted;
|
Role _role = Role::Restricted;
|
||||||
not_null<Additional*> _additional;
|
not_null<ParticipantsAdditionalData*> _additional;
|
||||||
|
|
||||||
base::Timer _timer;
|
base::Timer _timer;
|
||||||
QString _query;
|
QString _query;
|
||||||
|
|
|
@ -60,25 +60,25 @@ protected:
|
||||||
public:
|
public:
|
||||||
virtual ~PeerData();
|
virtual ~PeerData();
|
||||||
|
|
||||||
Data::Session &owner() const;
|
[[nodiscard]] Data::Session &owner() const;
|
||||||
AuthSession &session() const;
|
[[nodiscard]] AuthSession &session() const;
|
||||||
|
|
||||||
bool isUser() const {
|
[[nodiscard]] bool isUser() const {
|
||||||
return peerIsUser(id);
|
return peerIsUser(id);
|
||||||
}
|
}
|
||||||
bool isChat() const {
|
[[nodiscard]] bool isChat() const {
|
||||||
return peerIsChat(id);
|
return peerIsChat(id);
|
||||||
}
|
}
|
||||||
bool isChannel() const {
|
[[nodiscard]] bool isChannel() const {
|
||||||
return peerIsChannel(id);
|
return peerIsChannel(id);
|
||||||
}
|
}
|
||||||
bool isSelf() const {
|
[[nodiscard]] bool isSelf() const {
|
||||||
return (input.type() == mtpc_inputPeerSelf);
|
return (input.type() == mtpc_inputPeerSelf);
|
||||||
}
|
}
|
||||||
bool isVerified() const;
|
[[nodiscard]] bool isVerified() const;
|
||||||
bool isMegagroup() const;
|
[[nodiscard]] bool isMegagroup() const;
|
||||||
|
|
||||||
std::optional<TimeId> notifyMuteUntil() const {
|
[[nodiscard]] std::optional<TimeId> notifyMuteUntil() const {
|
||||||
return _notify.muteUntil();
|
return _notify.muteUntil();
|
||||||
}
|
}
|
||||||
bool notifyChange(const MTPPeerNotifySettings &settings) {
|
bool notifyChange(const MTPPeerNotifySettings &settings) {
|
||||||
|
@ -89,66 +89,54 @@ public:
|
||||||
std::optional<bool> silentPosts) {
|
std::optional<bool> silentPosts) {
|
||||||
return _notify.change(muteForSeconds, silentPosts);
|
return _notify.change(muteForSeconds, silentPosts);
|
||||||
}
|
}
|
||||||
bool notifySettingsUnknown() const {
|
[[nodiscard]] bool notifySettingsUnknown() const {
|
||||||
return _notify.settingsUnknown();
|
return _notify.settingsUnknown();
|
||||||
}
|
}
|
||||||
std::optional<bool> notifySilentPosts() const {
|
[[nodiscard]] std::optional<bool> notifySilentPosts() const {
|
||||||
return _notify.silentPosts();
|
return _notify.silentPosts();
|
||||||
}
|
}
|
||||||
MTPinputPeerNotifySettings notifySerialize() const {
|
[[nodiscard]] MTPinputPeerNotifySettings notifySerialize() const {
|
||||||
return _notify.serialize();
|
return _notify.serialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canWrite() const;
|
[[nodiscard]] bool canWrite() const;
|
||||||
bool amRestricted(ChatRestriction right) const;
|
[[nodiscard]] bool amRestricted(ChatRestriction right) const;
|
||||||
|
|
||||||
UserData *asUser();
|
[[nodiscard]] UserData *asUser();
|
||||||
const UserData *asUser() const;
|
[[nodiscard]] const UserData *asUser() const;
|
||||||
ChatData *asChat();
|
[[nodiscard]] ChatData *asChat();
|
||||||
const ChatData *asChat() const;
|
[[nodiscard]] const ChatData *asChat() const;
|
||||||
ChannelData *asChannel();
|
[[nodiscard]] ChannelData *asChannel();
|
||||||
const ChannelData *asChannel() const;
|
[[nodiscard]] const ChannelData *asChannel() const;
|
||||||
ChannelData *asMegagroup();
|
[[nodiscard]] ChannelData *asMegagroup();
|
||||||
const ChannelData *asMegagroup() const;
|
[[nodiscard]] const ChannelData *asMegagroup() const;
|
||||||
|
|
||||||
ChatData *migrateFrom() const;
|
[[nodiscard]] ChatData *migrateFrom() const;
|
||||||
ChannelData *migrateTo() const;
|
[[nodiscard]] ChannelData *migrateTo() const;
|
||||||
Data::Feed *feed() const;
|
[[nodiscard]] Data::Feed *feed() const;
|
||||||
|
|
||||||
void updateFull();
|
void updateFull();
|
||||||
void updateFullForced();
|
void updateFullForced();
|
||||||
void fullUpdated();
|
void fullUpdated();
|
||||||
bool wasFullUpdated() const {
|
[[nodiscard]] bool wasFullUpdated() const {
|
||||||
return (_lastFullUpdate != 0);
|
return (_lastFullUpdate != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Text &dialogName() const;
|
[[nodiscard]] const Text &dialogName() const;
|
||||||
const QString &shortName() const;
|
[[nodiscard]] const QString &shortName() const;
|
||||||
QString userName() const;
|
[[nodiscard]] QString userName() const;
|
||||||
|
|
||||||
const PeerId id;
|
[[nodiscard]] int32 bareId() const {
|
||||||
int32 bareId() const {
|
|
||||||
return int32(uint32(id & 0xFFFFFFFFULL));
|
return int32(uint32(id & 0xFFFFFFFFULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString name;
|
[[nodiscard]] const base::flat_set<QString> &nameWords() const {
|
||||||
Text nameText;
|
|
||||||
|
|
||||||
const base::flat_set<QString> &nameWords() const {
|
|
||||||
return _nameWords;
|
return _nameWords;
|
||||||
}
|
}
|
||||||
const base::flat_set<QChar> &nameFirstLetters() const {
|
[[nodiscard]] const base::flat_set<QChar> &nameFirstLetters() const {
|
||||||
return _nameFirstLetters;
|
return _nameFirstLetters;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum LoadedStatus {
|
|
||||||
NotLoaded = 0x00,
|
|
||||||
MinimalLoaded = 0x01,
|
|
||||||
FullLoaded = 0x02,
|
|
||||||
};
|
|
||||||
LoadedStatus loadedStatus = NotLoaded;
|
|
||||||
MTPinputPeer input;
|
|
||||||
|
|
||||||
void setUserpic(
|
void setUserpic(
|
||||||
PhotoId photoId,
|
PhotoId photoId,
|
||||||
const StorageImageLocation &location,
|
const StorageImageLocation &location,
|
||||||
|
@ -178,45 +166,43 @@ public:
|
||||||
int y,
|
int y,
|
||||||
int size) const;
|
int size) const;
|
||||||
void loadUserpic(bool loadFirst = false, bool prior = true);
|
void loadUserpic(bool loadFirst = false, bool prior = true);
|
||||||
bool userpicLoaded() const;
|
[[nodiscard]] bool userpicLoaded() const;
|
||||||
bool useEmptyUserpic() const;
|
[[nodiscard]] bool useEmptyUserpic() const;
|
||||||
StorageKey userpicUniqueKey() const;
|
[[nodiscard]] StorageKey userpicUniqueKey() const;
|
||||||
void saveUserpic(const QString &path, int size) const;
|
void saveUserpic(const QString &path, int size) const;
|
||||||
void saveUserpicRounded(const QString &path, int size) const;
|
void saveUserpicRounded(const QString &path, int size) const;
|
||||||
QPixmap genUserpic(int size) const;
|
[[nodiscard]] QPixmap genUserpic(int size) const;
|
||||||
QPixmap genUserpicRounded(int size) const;
|
[[nodiscard]] QPixmap genUserpicRounded(int size) const;
|
||||||
StorageImageLocation userpicLocation() const {
|
[[nodiscard]] StorageImageLocation userpicLocation() const {
|
||||||
return _userpicLocation;
|
return _userpicLocation;
|
||||||
}
|
}
|
||||||
bool userpicPhotoUnknown() const {
|
[[nodiscard]] bool userpicPhotoUnknown() const {
|
||||||
return (_userpicPhotoId == kUnknownPhotoId);
|
return (_userpicPhotoId == kUnknownPhotoId);
|
||||||
}
|
}
|
||||||
PhotoId userpicPhotoId() const {
|
[[nodiscard]] PhotoId userpicPhotoId() const {
|
||||||
return userpicPhotoUnknown() ? 0 : _userpicPhotoId;
|
return userpicPhotoUnknown() ? 0 : _userpicPhotoId;
|
||||||
}
|
}
|
||||||
Data::FileOrigin userpicOrigin() const;
|
[[nodiscard]] Data::FileOrigin userpicOrigin() const;
|
||||||
Data::FileOrigin userpicPhotoOrigin() const;
|
[[nodiscard]] Data::FileOrigin userpicPhotoOrigin() const;
|
||||||
|
|
||||||
int nameVersion = 1;
|
|
||||||
|
|
||||||
// If this string is not empty we must not allow to open the
|
// If this string is not empty we must not allow to open the
|
||||||
// conversation and we must show this string instead.
|
// conversation and we must show this string instead.
|
||||||
virtual QString unavailableReason() const {
|
[[nodiscard]] virtual QString unavailableReason() const {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickHandlerPtr createOpenLink();
|
[[nodiscard]] ClickHandlerPtr createOpenLink();
|
||||||
const ClickHandlerPtr &openLink() {
|
[[nodiscard]] const ClickHandlerPtr &openLink() {
|
||||||
if (!_openLink) {
|
if (!_openLink) {
|
||||||
_openLink = createOpenLink();
|
_openLink = createOpenLink();
|
||||||
}
|
}
|
||||||
return _openLink;
|
return _openLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagePtr currentUserpic() const;
|
[[nodiscard]] ImagePtr currentUserpic() const;
|
||||||
|
|
||||||
bool canPinMessages() const;
|
[[nodiscard]] bool canPinMessages() const;
|
||||||
MsgId pinnedMessageId() const {
|
[[nodiscard]] MsgId pinnedMessageId() const {
|
||||||
return _pinnedMessageId;
|
return _pinnedMessageId;
|
||||||
}
|
}
|
||||||
void setPinnedMessageId(MsgId messageId);
|
void setPinnedMessageId(MsgId messageId);
|
||||||
|
@ -230,6 +216,20 @@ public:
|
||||||
return _about;
|
return _about;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum LoadedStatus {
|
||||||
|
NotLoaded = 0x00,
|
||||||
|
MinimalLoaded = 0x01,
|
||||||
|
FullLoaded = 0x02,
|
||||||
|
};
|
||||||
|
|
||||||
|
const PeerId id;
|
||||||
|
QString name;
|
||||||
|
Text nameText;
|
||||||
|
LoadedStatus loadedStatus = NotLoaded;
|
||||||
|
MTPinputPeer input;
|
||||||
|
|
||||||
|
int nameVersion = 1;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateNameDelayed(
|
void updateNameDelayed(
|
||||||
const QString &newName,
|
const QString &newName,
|
||||||
|
|
Loading…
Reference in New Issue