mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Support disabling top peers completely.
This commit is contained in:
parent
e1c21b908c
commit
c11f4efc5c
10 changed files with 125 additions and 35 deletions
|
@ -730,6 +730,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_settings_angle_backend_d3d11on12" = "D3D11on12";
|
||||
"lng_settings_angle_backend_opengl" = "OpenGL";
|
||||
"lng_settings_angle_backend_disabled" = "Disabled";
|
||||
"lng_settings_top_peers_title" = "Frequent contacts";
|
||||
"lng_settings_top_peers_suggest" = "Suggest frequent contacts";
|
||||
"lng_settings_top_peers_about" = "Display people you message frequently at the top of the search section for quick access.";
|
||||
"lng_settings_sensitive_title" = "Sensitive content";
|
||||
"lng_settings_sensitive_disable_filtering" = "Disable filtering";
|
||||
"lng_settings_sensitive_about" = "Display sensitive media in public channels on all your Telegram devices.";
|
||||
|
|
|
@ -70,7 +70,7 @@ void TopPeers::remove(not_null<PeerData*> peer) {
|
|||
}
|
||||
|
||||
void TopPeers::increment(not_null<PeerData*> peer, TimeId date) {
|
||||
if (date <= _lastReceivedDate) {
|
||||
if (_disabled || date <= _lastReceivedDate) {
|
||||
return;
|
||||
}
|
||||
if (const auto user = peer->asUser(); user && !user->isBot()) {
|
||||
|
@ -107,6 +107,27 @@ void TopPeers::reload() {
|
|||
request();
|
||||
}
|
||||
|
||||
void TopPeers::toggleDisabled(bool disabled) {
|
||||
if (disabled) {
|
||||
if (!_disabled || !_list.empty()) {
|
||||
_disabled = true;
|
||||
_list.clear();
|
||||
_updates.fire({});
|
||||
}
|
||||
} else if (_disabled) {
|
||||
_disabled = false;
|
||||
_updates.fire({});
|
||||
}
|
||||
|
||||
_session->api().request(MTPcontacts_ToggleTopPeers(
|
||||
MTP_bool(!disabled)
|
||||
)).done([=] {
|
||||
if (!_disabled) {
|
||||
request();
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
void TopPeers::request() {
|
||||
if (_requestId) {
|
||||
return;
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
void remove(not_null<PeerData*> peer);
|
||||
void increment(not_null<PeerData*> peer, TimeId date);
|
||||
void reload();
|
||||
void toggleDisabled(bool disabled);
|
||||
|
||||
private:
|
||||
struct TopPeer {
|
||||
|
|
|
@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/history.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/elastic_scroll.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
|
@ -23,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/dynamic_thumbnails.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_chat.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
|
@ -33,13 +35,23 @@ namespace {
|
|||
void FillTopPeerMenu(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const ShowTopPeerMenuRequest &request,
|
||||
Fn<void(not_null<PeerData*>)> remove) {
|
||||
Fn<void(not_null<PeerData*>)> remove,
|
||||
Fn<void()> hideAll) {
|
||||
const auto owner = &controller->session().data();
|
||||
const auto peer = owner->peer(PeerId(request.id));
|
||||
const auto &add = request.callback;
|
||||
const auto group = peer->isMegagroup();
|
||||
const auto channel = peer->isChannel();
|
||||
|
||||
add({
|
||||
.text = tr::lng_recent_remove(tr::now),
|
||||
.handler = [=] { remove(peer); },
|
||||
.icon = &st::menuIconDeleteAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
|
||||
add({ .separatorSt = &st::expandedMenuSeparator });
|
||||
|
||||
const auto showHistoryText = group
|
||||
? tr::lng_context_open_group(tr::now)
|
||||
: channel
|
||||
|
@ -58,12 +70,14 @@ void FillTopPeerMenu(
|
|||
controller->showPeerInfo(peer);
|
||||
}, channel ? &st::menuIconInfo : &st::menuIconProfile);
|
||||
|
||||
add({
|
||||
.text = tr::lng_recent_remove(tr::now),
|
||||
.handler = [=] { remove(peer); },
|
||||
.icon = &st::menuIconDeleteAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
add({ .separatorSt = &st::expandedMenuSeparator });
|
||||
|
||||
add(tr::lng_recent_hide_top(tr::now), [=] {
|
||||
controller->show(Ui::MakeConfirmBox({
|
||||
.text = tr::lng_recent_hide_sure(),
|
||||
.confirmed = [=](Fn<void()> close) { hideAll(); close(); }
|
||||
}));
|
||||
}, &st::menuIconCancel);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -90,11 +104,21 @@ Suggestions::Suggestions(
|
|||
|
||||
_topPeers->showMenuRequests(
|
||||
) | rpl::start_with_next([=](const ShowTopPeerMenuRequest &request) {
|
||||
const auto remove = crl::guard(this, [=](not_null<PeerData*> peer) {
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
const auto remove = [=](not_null<PeerData*> peer) {
|
||||
peer->session().topPeers().remove(peer);
|
||||
_topPeers->removeLocally(peer->id.value);
|
||||
if (weak) {
|
||||
_topPeers->removeLocally(peer->id.value);
|
||||
}
|
||||
};
|
||||
const auto session = &controller->session();
|
||||
const auto hideAll = crl::guard(session, [=] {
|
||||
session->topPeers().toggleDisabled(true);
|
||||
if (weak) {
|
||||
_topPeers->removeLocally();
|
||||
}
|
||||
});
|
||||
FillTopPeerMenu(controller, request, remove);
|
||||
FillTopPeerMenu(controller, request, remove, hideAll);
|
||||
}, _topPeers->lifetime());
|
||||
}
|
||||
|
||||
|
|
|
@ -246,6 +246,15 @@ auto TopPeersStrip::showMenuRequests() const
|
|||
}
|
||||
|
||||
void TopPeersStrip::removeLocally(uint64 id) {
|
||||
if (!id) {
|
||||
unsubscribeUserpics(true);
|
||||
setSelected(-1);
|
||||
_pressed = -1;
|
||||
_entries.clear();
|
||||
_hiddenLocally = true;
|
||||
_empty = true;
|
||||
return;
|
||||
}
|
||||
_removed.emplace(id);
|
||||
const auto i = ranges::find(_entries, id, &Entry::id);
|
||||
if (i == end(_entries)) {
|
||||
|
@ -321,6 +330,9 @@ bool TopPeersStrip::chooseRow() {
|
|||
}
|
||||
|
||||
void TopPeersStrip::apply(const TopPeersList &list) {
|
||||
if (_hiddenLocally) {
|
||||
return;
|
||||
}
|
||||
auto now = std::vector<Entry>();
|
||||
|
||||
auto selectedId = (_selected >= 0) ? _entries[_selected].id : 0;
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
[[nodiscard]] auto showMenuRequests() const
|
||||
-> rpl::producer<ShowTopPeerMenuRequest>;
|
||||
|
||||
void removeLocally(uint64 id);
|
||||
void removeLocally(uint64 id = 0);
|
||||
|
||||
[[nodiscard]] bool selectedByKeyboard() const;
|
||||
void selectByKeyboard(int delta);
|
||||
|
@ -105,6 +105,7 @@ private:
|
|||
int _selected = -1;
|
||||
int _pressed = -1;
|
||||
bool _selectionByKeyboard = false;
|
||||
bool _hiddenLocally = false;
|
||||
|
||||
Ui::RoundRect _selection;
|
||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||
|
|
|
@ -953,13 +953,11 @@ void GenerateItems(
|
|||
Ui::Text::WithEntities);
|
||||
addSimpleServiceMessage(text, realId);
|
||||
|
||||
const auto detachExistingItem = false;
|
||||
addPart(
|
||||
history->createItem(
|
||||
history->nextNonHistoryEntryId(),
|
||||
PrepareLogMessage(action.vmessage(), date),
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem),
|
||||
MessageFlag::AdminLogEntry),
|
||||
ExtractSentDate(action.vmessage()),
|
||||
realId);
|
||||
}, [&](const auto &) {
|
||||
|
@ -1008,12 +1006,10 @@ void GenerateItems(
|
|||
Ui::Text::WithEntities);
|
||||
addSimpleServiceMessage(text, realId);
|
||||
|
||||
const auto detachExistingItem = false;
|
||||
const auto body = history->createItem(
|
||||
history->nextNonHistoryEntryId(),
|
||||
PrepareLogMessage(action.vnew_message(), date),
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem);
|
||||
MessageFlag::AdminLogEntry);
|
||||
if (oldValue.text.isEmpty()) {
|
||||
oldValue = PrepareText(
|
||||
QString(),
|
||||
|
@ -1038,13 +1034,11 @@ void GenerateItems(
|
|||
Ui::Text::WithEntities);
|
||||
addSimpleServiceMessage(text, realId);
|
||||
|
||||
const auto detachExistingItem = false;
|
||||
addPart(
|
||||
history->createItem(
|
||||
history->nextNonHistoryEntryId(),
|
||||
PrepareLogMessage(action.vmessage(), date),
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem),
|
||||
MessageFlag::AdminLogEntry),
|
||||
ExtractSentDate(action.vmessage()),
|
||||
realId);
|
||||
};
|
||||
|
@ -1218,13 +1212,11 @@ void GenerateItems(
|
|||
Ui::Text::WithEntities);
|
||||
addSimpleServiceMessage(text, realId);
|
||||
|
||||
const auto detachExistingItem = false;
|
||||
addPart(
|
||||
history->createItem(
|
||||
history->nextNonHistoryEntryId(),
|
||||
PrepareLogMessage(action.vmessage(), date),
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem),
|
||||
MessageFlag::AdminLogEntry),
|
||||
ExtractSentDate(action.vmessage()),
|
||||
realId);
|
||||
};
|
||||
|
@ -1604,13 +1596,11 @@ void GenerateItems(
|
|||
Ui::Text::WithEntities);
|
||||
addSimpleServiceMessage(text, realId);
|
||||
|
||||
const auto detachExistingItem = false;
|
||||
addPart(
|
||||
history->createItem(
|
||||
history->nextNonHistoryEntryId(),
|
||||
PrepareLogMessage(data.vmessage(), date),
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem),
|
||||
MessageFlag::AdminLogEntry),
|
||||
ExtractSentDate(data.vmessage()),
|
||||
realId);
|
||||
};
|
||||
|
|
|
@ -423,7 +423,8 @@ not_null<HistoryItem*> History::createItem(
|
|||
MsgId id,
|
||||
const MTPMessage &message,
|
||||
MessageFlags localFlags,
|
||||
bool detachExistingItem) {
|
||||
bool detachExistingItem,
|
||||
bool newMessage) {
|
||||
if (const auto result = owner().message(peer, id)) {
|
||||
if (detachExistingItem) {
|
||||
result->removeMainView();
|
||||
|
@ -433,7 +434,7 @@ not_null<HistoryItem*> History::createItem(
|
|||
const auto result = message.match([&](const auto &data) {
|
||||
return makeMessage(id, data, localFlags);
|
||||
});
|
||||
if (result->out() && result->isRegular()) {
|
||||
if (newMessage && result->out() && result->isRegular()) {
|
||||
session().topPeers().increment(peer, result->date());
|
||||
}
|
||||
return result;
|
||||
|
@ -461,16 +462,21 @@ not_null<HistoryItem*> History::addNewMessage(
|
|||
const MTPMessage &message,
|
||||
MessageFlags localFlags,
|
||||
NewMessageType type) {
|
||||
const auto detachExisting = (type == NewMessageType::Unread);
|
||||
const auto item = createItem(id, message, localFlags, detachExisting);
|
||||
const auto newMessage = (type == NewMessageType::Unread);
|
||||
const auto detachExisting = newMessage;
|
||||
const auto item = createItem(
|
||||
id,
|
||||
message,
|
||||
localFlags,
|
||||
detachExisting,
|
||||
newMessage);
|
||||
if (type == NewMessageType::Existing || item->mainView()) {
|
||||
return item;
|
||||
}
|
||||
const auto unread = (type == NewMessageType::Unread);
|
||||
if (unread && item->isHistoryEntry()) {
|
||||
if (newMessage && item->isHistoryEntry()) {
|
||||
applyMessageChanges(item, message);
|
||||
}
|
||||
return addNewItem(item, unread);
|
||||
return addNewItem(item, newMessage);
|
||||
}
|
||||
|
||||
not_null<HistoryItem*> History::insertItem(
|
||||
|
|
|
@ -185,7 +185,8 @@ public:
|
|||
MsgId id,
|
||||
const MTPMessage &message,
|
||||
MessageFlags localFlags,
|
||||
bool detachExistingItem);
|
||||
bool detachExistingItem = false,
|
||||
bool newMessage = false);
|
||||
std::vector<not_null<HistoryItem*>> createItems(
|
||||
const QVector<MTPMessage> &data);
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "calls/calls_instance.h"
|
||||
#include "core/update_checker.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "data/components/top_peers.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_channel.h"
|
||||
|
@ -546,6 +547,35 @@ void SetupCloudPassword(
|
|||
session->api().cloudPassword().reload();
|
||||
}
|
||||
|
||||
void SetupTopPeers(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
Ui::AddSkip(container);
|
||||
Ui::AddSubsectionTitle(container, tr::lng_settings_top_peers_title());
|
||||
|
||||
const auto session = &controller->session();
|
||||
|
||||
container->add(object_ptr<Button>(
|
||||
container,
|
||||
tr::lng_settings_top_peers_suggest(),
|
||||
st::settingsButtonNoIcon
|
||||
))->toggleOn(rpl::single(
|
||||
rpl::empty
|
||||
) | rpl::then(
|
||||
session->topPeers().updates()
|
||||
) | rpl::map([=] {
|
||||
return !session->topPeers().disabled();
|
||||
}))->toggledChanges(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return enabled == session->topPeers().disabled();
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
session->topPeers().toggleDisabled(!enabled);
|
||||
}, container->lifetime());
|
||||
|
||||
Ui::AddSkip(container);
|
||||
Ui::AddDividerText(container, tr::lng_settings_top_peers_about());
|
||||
}
|
||||
|
||||
void SetupSensitiveContent(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
|
@ -1065,6 +1095,7 @@ void PrivacySecurity::setupContent(
|
|||
|
||||
SetupSecurity(controller, content, trigger(), showOtherMethod());
|
||||
SetupPrivacy(controller, content, trigger());
|
||||
SetupTopPeers(controller, content);
|
||||
#if !defined OS_MAC_STORE && !defined OS_WIN_STORE
|
||||
SetupSensitiveContent(controller, content, trigger());
|
||||
#else // !OS_MAC_STORE && !OS_WIN_STORE
|
||||
|
|
Loading…
Add table
Reference in a new issue