mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Don't suggest joining forbidden chats by link.
This commit is contained in:
parent
959348f8cd
commit
9600cc0ed5
4 changed files with 49 additions and 6 deletions
|
@ -3585,6 +3585,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_filters_link_noadmin_channel_error" = "You don't have the admin rights to share invite links to this private channel.";
|
||||
"lng_filters_link_already_group" = "you are already a member";
|
||||
"lng_filters_link_already_channel" = "you are already subscribed";
|
||||
"lng_filters_link_inaccessible" = "chat is inaccessible";
|
||||
"lng_filters_link_chats_about" = "Select groups and channels that you want everyone who adds the folder via invite link to join.";
|
||||
"lng_filters_link_no_about" = "There are no chats in this folder that you can share with others.";
|
||||
"lng_filters_link_chats_no" = "These chats cannot be shared";
|
||||
|
|
|
@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/premium_limits_box.h"
|
||||
#include "boxes/filters/edit_filter_links.h" // FilterChatStatusText
|
||||
#include "core/application.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_chat_filters.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_session.h"
|
||||
|
@ -72,6 +74,7 @@ private:
|
|||
|
||||
ToggleAction _action = ToggleAction::Adding;
|
||||
QString _filterTitle;
|
||||
base::flat_set<not_null<PeerData*>> _checkable;
|
||||
std::vector<not_null<PeerData*>> _chats;
|
||||
std::vector<not_null<PeerData*>> _additional;
|
||||
rpl::variable<base::flat_set<not_null<PeerData*>>> _selected;
|
||||
|
@ -262,20 +265,36 @@ ToggleChatsController::ToggleChatsController(
|
|||
|
||||
void ToggleChatsController::prepare() {
|
||||
auto selected = base::flat_set<not_null<PeerData*>>();
|
||||
const auto disabled = [](not_null<PeerData*> peer) {
|
||||
return peer->isChat()
|
||||
? peer->asChat()->isForbidden()
|
||||
: peer->isChannel()
|
||||
? peer->asChannel()->isForbidden()
|
||||
: false;
|
||||
};
|
||||
const auto add = [&](not_null<PeerData*> peer, bool additional = false) {
|
||||
auto row = std::make_unique<PeerListRow>(peer);
|
||||
const auto disable = disabled(peer);
|
||||
auto row = (additional || !disable)
|
||||
? std::make_unique<PeerListRow>(peer)
|
||||
: MakeFilterChatRow(
|
||||
peer,
|
||||
tr::lng_filters_link_inaccessible(tr::now),
|
||||
true);
|
||||
if (delegate()->peerListFindRow(peer->id.value)) {
|
||||
return;
|
||||
}
|
||||
const auto raw = row.get();
|
||||
delegate()->peerListAppendRow(std::move(row));
|
||||
if (!additional || _action == ToggleAction::Removing) {
|
||||
if (!disable
|
||||
&& (!additional || _action == ToggleAction::Removing)) {
|
||||
_checkable.emplace(peer);
|
||||
if (const auto status = FilterChatStatusText(peer)
|
||||
; !status.isEmpty()) {
|
||||
raw->setCustomStatus(status);
|
||||
}
|
||||
}
|
||||
if (!additional) {
|
||||
if (disable) {
|
||||
} else if (!additional) {
|
||||
delegate()->peerListSetRowChecked(raw, true);
|
||||
raw->finishCheckedAnimation();
|
||||
selected.emplace(peer);
|
||||
|
@ -287,11 +306,18 @@ void ToggleChatsController::prepare() {
|
|||
}
|
||||
};
|
||||
for (const auto &peer : _chats) {
|
||||
add(peer);
|
||||
if (!disabled(peer)) {
|
||||
add(peer);
|
||||
}
|
||||
}
|
||||
for (const auto &peer : _additional) {
|
||||
add(peer, true);
|
||||
}
|
||||
for (const auto &peer : _chats) {
|
||||
if (disabled(peer)) {
|
||||
add(peer);
|
||||
}
|
||||
}
|
||||
setupAboveWidget();
|
||||
setupBelowWidget();
|
||||
initDesiredHeightValue();
|
||||
|
@ -301,6 +327,9 @@ void ToggleChatsController::prepare() {
|
|||
|
||||
void ToggleChatsController::rowClicked(not_null<PeerListRow*> row) {
|
||||
const auto peer = row->peer();
|
||||
if (!_checkable.contains(peer)) {
|
||||
return;
|
||||
}
|
||||
const auto checked = row->checked();
|
||||
auto selected = _selected.current();
|
||||
delegate()->peerListSetRowChecked(row, !checked);
|
||||
|
@ -341,8 +370,7 @@ void ToggleChatsController::setupAboveWidget() {
|
|||
: _chats.empty()
|
||||
? _additional.size()
|
||||
: _chats.size();
|
||||
const auto selectableCount = delegate()->peerListFullRowsCount()
|
||||
- (_action == ToggleAction::Adding ? int(_additional.size()) : 0);
|
||||
const auto selectableCount = int(_checkable.size());
|
||||
auto selectedCount = _selected.value(
|
||||
) | rpl::map([](const base::flat_set<not_null<PeerData*>> &selected) {
|
||||
return int(selected.size());
|
||||
|
|
|
@ -1292,3 +1292,10 @@ void AddFilterSubtitleWithToggles(
|
|||
link->move(outer - st::boxRowPadding.right() - width, y);
|
||||
}, link->lifetime());
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListRow> MakeFilterChatRow(
|
||||
not_null<PeerData*> peer,
|
||||
const QString &status,
|
||||
bool disabled) {
|
||||
return std::make_unique<ChatRow>(peer, status, disabled);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "base/object_ptr.h"
|
||||
|
||||
class PeerListRow;
|
||||
|
||||
namespace Ui {
|
||||
class Show;
|
||||
class BoxContent;
|
||||
|
@ -54,3 +56,8 @@ void AddFilterSubtitleWithToggles(
|
|||
int selectableCount,
|
||||
rpl::producer<int> selectedCount,
|
||||
Fn<void(bool select)> toggle);
|
||||
|
||||
[[nodiscard]] std::unique_ptr<PeerListRow> MakeFilterChatRow(
|
||||
not_null<PeerData*> peer,
|
||||
const QString &status,
|
||||
bool disabled);
|
||||
|
|
Loading…
Add table
Reference in a new issue