mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Allow to ban channels in groups from moderate actions.
This commit is contained in:
parent
fc4cdd4482
commit
03775e0cc5
3 changed files with 53 additions and 30 deletions
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/view/history_view_cursor_state.h"
|
#include "history/view/history_view_cursor_state.h"
|
||||||
#include "chat_helpers/message_field.h"
|
#include "chat_helpers/message_field.h"
|
||||||
#include "boxes/sticker_set_box.h"
|
#include "boxes/sticker_set_box.h"
|
||||||
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
@ -1233,10 +1234,8 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (fromId) { // suggest to block
|
} else if (fromId) { // suggest to block
|
||||||
if (const auto userId = peerToUser(fromId)) {
|
if (const auto participant = session().data().peer(fromId)) {
|
||||||
if (const auto user = session().data().user(userId)) {
|
suggestRestrictParticipant(participant);
|
||||||
suggestRestrictUser(user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else { // maybe cursor on some text history item?
|
} else { // maybe cursor on some text history item?
|
||||||
const auto item = view ? view->data().get() : nullptr;
|
const auto item = view ? view->data().get() : nullptr;
|
||||||
|
@ -1360,38 +1359,57 @@ void InnerWidget::copyContextText(FullMsgId itemId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::suggestRestrictUser(not_null<UserData*> user) {
|
void InnerWidget::suggestRestrictParticipant(
|
||||||
|
not_null<PeerData*> participant) {
|
||||||
Expects(_menu != nullptr);
|
Expects(_menu != nullptr);
|
||||||
|
|
||||||
if (!_channel->isMegagroup() || !_channel->canBanMembers() || _admins.empty()) {
|
if (!_channel->isMegagroup()
|
||||||
|
|| !_channel->canBanMembers()
|
||||||
|
|| _admins.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (base::contains(_admins, user)) {
|
if (ranges::contains(_admins, participant)) {
|
||||||
if (!base::contains(_adminsCanEdit, user)) {
|
if (!ranges::contains(_adminsCanEdit, participant)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_menu->addAction(tr::lng_context_restrict_user(tr::now), [=] {
|
_menu->addAction(tr::lng_context_restrict_user(tr::now), [=] {
|
||||||
|
const auto user = participant->asUser();
|
||||||
auto editRestrictions = [=](bool hasAdminRights, ChatRestrictionsInfo currentRights) {
|
auto editRestrictions = [=](bool hasAdminRights, ChatRestrictionsInfo currentRights) {
|
||||||
auto weak = QPointer<InnerWidget>(this);
|
auto weak = QPointer<InnerWidget>(this);
|
||||||
auto weakBox = std::make_shared<QPointer<EditRestrictedBox>>();
|
auto weakBox = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||||
auto box = Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights);
|
auto box = Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights);
|
||||||
box->setSaveCallback([=](
|
box->setSaveCallback([=](
|
||||||
ChatRestrictionsInfo oldRights,
|
ChatRestrictionsInfo oldRights,
|
||||||
ChatRestrictionsInfo newRights) {
|
ChatRestrictionsInfo newRights) {
|
||||||
if (weak) {
|
if (weak) {
|
||||||
weak->restrictUser(user, oldRights, newRights);
|
weak->restrictParticipant(participant, oldRights, newRights);
|
||||||
}
|
}
|
||||||
if (*weakBox) {
|
if (*weakBox) {
|
||||||
(*weakBox)->closeBox();
|
(*weakBox)->closeBox();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
*weakBox = QPointer<EditRestrictedBox>(box.data());
|
*weakBox = _controller->show(std::move(box));
|
||||||
_controller->show(
|
|
||||||
std::move(box),
|
|
||||||
Ui::LayerOption::KeepOther);
|
|
||||||
};
|
};
|
||||||
if (base::contains(_admins, user)) {
|
if (!user) {
|
||||||
|
const auto text = (_channel->isBroadcast()
|
||||||
|
? tr::lng_profile_sure_kick_channel
|
||||||
|
: tr::lng_profile_sure_kick)(
|
||||||
|
tr::now,
|
||||||
|
lt_user,
|
||||||
|
participant->name);
|
||||||
|
auto weakBox = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||||
|
const auto sure = crl::guard(this, [=] {
|
||||||
|
restrictParticipant(
|
||||||
|
participant,
|
||||||
|
ChatRestrictionsInfo(),
|
||||||
|
ChannelData::KickedRestrictedRights(participant));
|
||||||
|
if (*weakBox) {
|
||||||
|
(*weakBox)->closeBox();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*weakBox = _controller->show(Box<Ui::ConfirmBox>(text, sure));
|
||||||
|
} else if (base::contains(_admins, user)) {
|
||||||
editRestrictions(true, ChatRestrictionsInfo());
|
editRestrictions(true, ChatRestrictionsInfo());
|
||||||
} else {
|
} else {
|
||||||
_api.request(MTPchannels_GetParticipant(
|
_api.request(MTPchannels_GetParticipant(
|
||||||
|
@ -1420,30 +1438,33 @@ void InnerWidget::suggestRestrictUser(not_null<UserData*> user) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::restrictUser(
|
void InnerWidget::restrictParticipant(
|
||||||
not_null<UserData*> user,
|
not_null<PeerData*> participant,
|
||||||
ChatRestrictionsInfo oldRights,
|
ChatRestrictionsInfo oldRights,
|
||||||
ChatRestrictionsInfo newRights) {
|
ChatRestrictionsInfo newRights) {
|
||||||
const auto done = [=](ChatRestrictionsInfo newRights) {
|
const auto done = [=](ChatRestrictionsInfo newRights) {
|
||||||
restrictUserDone(user, newRights);
|
restrictParticipantDone(participant, newRights);
|
||||||
};
|
};
|
||||||
const auto callback = SaveRestrictedCallback(
|
const auto callback = SaveRestrictedCallback(
|
||||||
_channel,
|
_channel,
|
||||||
user,
|
participant,
|
||||||
crl::guard(this, done),
|
crl::guard(this, done),
|
||||||
nullptr);
|
nullptr);
|
||||||
callback(oldRights, newRights);
|
callback(oldRights, newRights);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::restrictUserDone(
|
void InnerWidget::restrictParticipantDone(
|
||||||
not_null<UserData*> user,
|
not_null<PeerData*> participant,
|
||||||
ChatRestrictionsInfo rights) {
|
ChatRestrictionsInfo rights) {
|
||||||
if (rights.flags) {
|
if (rights.flags) {
|
||||||
_admins.erase(
|
_admins.erase(
|
||||||
std::remove(_admins.begin(), _admins.end(), user),
|
std::remove(_admins.begin(), _admins.end(), participant),
|
||||||
_admins.end());
|
_admins.end());
|
||||||
_adminsCanEdit.erase(
|
_adminsCanEdit.erase(
|
||||||
std::remove(_adminsCanEdit.begin(), _adminsCanEdit.end(), user),
|
std::remove(
|
||||||
|
_adminsCanEdit.begin(),
|
||||||
|
_adminsCanEdit.end(),
|
||||||
|
participant),
|
||||||
_adminsCanEdit.end());
|
_adminsCanEdit.end());
|
||||||
}
|
}
|
||||||
_downLoaded = false;
|
_downLoaded = false;
|
||||||
|
|
|
@ -204,9 +204,14 @@ private:
|
||||||
void copyContextText(FullMsgId itemId);
|
void copyContextText(FullMsgId itemId);
|
||||||
void copySelectedText();
|
void copySelectedText();
|
||||||
TextForMimeData getSelectedText() const;
|
TextForMimeData getSelectedText() const;
|
||||||
void suggestRestrictUser(not_null<UserData*> user);
|
void suggestRestrictParticipant(not_null<PeerData*> participant);
|
||||||
void restrictUser(not_null<UserData*> user, ChatRestrictionsInfo oldRights, ChatRestrictionsInfo newRights);
|
void restrictParticipant(
|
||||||
void restrictUserDone(not_null<UserData*> user, ChatRestrictionsInfo rights);
|
not_null<PeerData*> participant,
|
||||||
|
ChatRestrictionsInfo oldRights,
|
||||||
|
ChatRestrictionsInfo newRights);
|
||||||
|
void restrictParticipantDone(
|
||||||
|
not_null<PeerData*> participant,
|
||||||
|
ChatRestrictionsInfo rights);
|
||||||
|
|
||||||
void requestAdmins();
|
void requestAdmins();
|
||||||
void checkPreloadMore();
|
void checkPreloadMore();
|
||||||
|
|
|
@ -727,10 +727,7 @@ bool HistoryItem::suggestReport() const {
|
||||||
|
|
||||||
bool HistoryItem::suggestBanReport() const {
|
bool HistoryItem::suggestBanReport() const {
|
||||||
const auto channel = history()->peer->asChannel();
|
const auto channel = history()->peer->asChannel();
|
||||||
const auto fromUser = from()->asUser();
|
if (!channel || !channel->canRestrictParticipant(from())) {
|
||||||
if (!channel
|
|
||||||
|| !fromUser
|
|
||||||
|| !channel->canRestrictParticipant(fromUser)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !isPost() && !out();
|
return !isPost() && !out();
|
||||||
|
|
Loading…
Add table
Reference in a new issue