mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
feat: show / hide filtered messages & move actions into separate subsection
This commit is contained in:
@@ -111,6 +111,20 @@ std::optional<bool> isFiltered(not_null<HistoryItem*> item) {
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasFilteredMessages(not_null<PeerData*> peer) {
|
||||||
|
std::lock_guard lock(mutex);
|
||||||
|
const auto dialogIt = filteredMessages.find(peer->id.value);
|
||||||
|
if (dialogIt == filteredMessages.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (const auto &entry : dialogIt->second) {
|
||||||
|
if (entry.second == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void putFiltered(not_null<HistoryItem*> item, const Data::Group *group, bool res) {
|
void putFiltered(not_null<HistoryItem*> item, const Data::Group *group, bool res) {
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
filteredMessages[item->history()->peer->id.value][item->id.bare] = res;
|
filteredMessages[item->history()->peer->id.value][item->id.bare] = res;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ std::unordered_map<long long, std::unordered_set<HashablePattern, PatternHasher>
|
|||||||
const std::vector<HashablePattern> &shared);
|
const std::vector<HashablePattern> &shared);
|
||||||
|
|
||||||
std::optional<bool> isFiltered(not_null<HistoryItem*> item);
|
std::optional<bool> isFiltered(not_null<HistoryItem*> item);
|
||||||
|
bool hasFilteredMessages(not_null<PeerData*> peer);
|
||||||
void putFiltered(not_null<HistoryItem*> item, const Data::Group *group, bool res);
|
void putFiltered(not_null<HistoryItem*> item, const Data::Group *group, bool res);
|
||||||
|
|
||||||
void invalidate(not_null<HistoryItem*> item);
|
void invalidate(not_null<HistoryItem*> item);
|
||||||
|
|||||||
@@ -20,8 +20,12 @@
|
|||||||
#include "history/history_item_components.h"
|
#include "history/history_item_components.h"
|
||||||
#include "unicode/regex.h"
|
#include "unicode/regex.h"
|
||||||
|
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace FiltersController {
|
namespace FiltersController {
|
||||||
|
|
||||||
|
std::unordered_set<long long> showingFilteredMessages;
|
||||||
|
|
||||||
bool filterBlocked(const not_null<HistoryItem*> item) {
|
bool filterBlocked(const not_null<HistoryItem*> item) {
|
||||||
if (item->from() != item->history()->peer) {
|
if (item->from() != item->history()->peer) {
|
||||||
if (isBlocked(item)) {
|
if (isBlocked(item)) {
|
||||||
@@ -123,6 +127,10 @@ bool isBlocked(const not_null<PeerData*> peer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool filtered(const not_null<HistoryItem*> item) {
|
bool filtered(const not_null<HistoryItem*> item) {
|
||||||
|
if (showingFilteredMessages.contains(item->history()->peer->id.value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto &settings = AyuSettings::getInstance();
|
const auto &settings = AyuSettings::getInstance();
|
||||||
if (!settings.filtersEnabled()) {
|
if (!settings.filtersEnabled()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -153,6 +161,23 @@ bool filtered(const not_null<HistoryItem*> item) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<bool> filteredMessagesShown(not_null<PeerData*> peer) {
|
||||||
|
if (!showingFilteredMessages.contains(peer->id.value)
|
||||||
|
&& !FiltersCacheController::hasFilteredMessages(peer)) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return showingFilteredMessages.contains(peer->id.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleFilteredMessagesShown(not_null<PeerData*> peer) {
|
||||||
|
if (showingFilteredMessages.contains(peer->id.value)) {
|
||||||
|
showingFilteredMessages.erase(peer->id.value);
|
||||||
|
} else {
|
||||||
|
showingFilteredMessages.insert(peer->id.value);
|
||||||
|
}
|
||||||
|
FiltersCacheController::fireUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
void invalidate(not_null<HistoryItem*> item) {
|
void invalidate(not_null<HistoryItem*> item) {
|
||||||
const auto &settings = AyuSettings::getInstance();
|
const auto &settings = AyuSettings::getInstance();
|
||||||
if (!settings.filtersEnabled()) {
|
if (!settings.filtersEnabled()) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "unicode/regex.h"
|
#include "unicode/regex.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -19,6 +20,8 @@ bool isEnabled(PeerData *peer);
|
|||||||
bool isBlocked(not_null<HistoryItem*> item);
|
bool isBlocked(not_null<HistoryItem*> item);
|
||||||
bool isBlocked(not_null<PeerData*> peer);
|
bool isBlocked(not_null<PeerData*> peer);
|
||||||
bool filtered(not_null<HistoryItem*> historyItem);
|
bool filtered(not_null<HistoryItem*> historyItem);
|
||||||
|
std::optional<bool> filteredMessagesShown(not_null<PeerData*> peer);
|
||||||
|
void toggleFilteredMessagesShown(not_null<PeerData*> peer);
|
||||||
|
|
||||||
void invalidate(not_null<HistoryItem*> item);
|
void invalidate(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
|
|||||||
@@ -77,3 +77,5 @@ ayuHistoryFileInPlugin: icon {{ "ayu/history_file_plugin", historyFileInIconFg }
|
|||||||
ayuHistoryFileInPluginSelected: icon {{ "ayu/history_file_plugin", historyFileInIconFgSelected }};
|
ayuHistoryFileInPluginSelected: icon {{ "ayu/history_file_plugin", historyFileInIconFgSelected }};
|
||||||
ayuHistoryFileOutPlugin: icon {{ "ayu/history_file_plugin", historyFileOutIconFg }};
|
ayuHistoryFileOutPlugin: icon {{ "ayu/history_file_plugin", historyFileOutIconFg }};
|
||||||
ayuHistoryFileOutPluginSelected: icon {{ "ayu/history_file_plugin", historyFileOutIconFgSelected }};
|
ayuHistoryFileOutPluginSelected: icon {{ "ayu/history_file_plugin", historyFileOutIconFgSelected }};
|
||||||
|
|
||||||
|
menuIconClearAttention: icon {{ "menu/clear", menuIconAttentionColor }};
|
||||||
|
|||||||
@@ -13,10 +13,12 @@
|
|||||||
#include "ayu/ayu_settings.h"
|
#include "ayu/ayu_settings.h"
|
||||||
#include "ayu/ayu_state.h"
|
#include "ayu/ayu_state.h"
|
||||||
#include "ayu/data/messages_storage.h"
|
#include "ayu/data/messages_storage.h"
|
||||||
|
#include "ayu/features/filters/filters_controller.h"
|
||||||
#include "ayu/features/forward/ayu_forward.h"
|
#include "ayu/features/forward/ayu_forward.h"
|
||||||
#include "ayu/ui/context_menu/menu_item_subtext.h"
|
#include "ayu/ui/context_menu/menu_item_subtext.h"
|
||||||
#include "ayu/ui/message_history/history_section.h"
|
#include "ayu/ui/message_history/history_section.h"
|
||||||
#include "ayu/ui/settings/filters/edit_filter.h"
|
#include "ayu/ui/settings/filters/edit_filter.h"
|
||||||
|
#include "ayu/ui/settings/filters/settings_filters_list.h"
|
||||||
#include "ayu/utils/qt_key_modifiers_extended.h"
|
#include "ayu/utils/qt_key_modifiers_extended.h"
|
||||||
#include "ayu/utils/telegram_helpers.h"
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
@@ -215,7 +217,7 @@ bool needToShowItem(ContextMenuVisibility state) {
|
|||||||
|| (state == ContextMenuVisibility::VisibleWithModifier && base::IsExtendedContextMenuModifierPressed());
|
|| (state == ContextMenuVisibility::VisibleWithModifier && base::IsExtendedContextMenuModifierPressed());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddDeletedMessagesActions(PeerData *peerData,
|
void AddAyuGramActions(PeerData *peerData,
|
||||||
Data::Thread *thread,
|
Data::Thread *thread,
|
||||||
not_null<Window::SessionController*> sessionController,
|
not_null<Window::SessionController*> sessionController,
|
||||||
const Window::PeerMenuCallback &addCallback) {
|
const Window::PeerMenuCallback &addCallback) {
|
||||||
@@ -223,27 +225,72 @@ void AddDeletedMessagesActions(PeerData *peerData,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto &settings = AyuSettings::getInstance();
|
||||||
|
const auto user = peerData->asUser();
|
||||||
|
const auto showFilters = settings.filtersEnabled()
|
||||||
|
&& (!user || user->isBot());
|
||||||
|
const auto saveDeletedMessages = settings.saveDeletedMessages();
|
||||||
|
if (!showFilters && !saveDeletedMessages) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto topic = peerData->isForum() ? thread->asTopic() : nullptr;
|
const auto topic = peerData->isForum() ? thread->asTopic() : nullptr;
|
||||||
const auto topicId = topic ? topic->rootId().bare : 0;
|
const auto topicId = topic ? topic->rootId().bare : 0;
|
||||||
|
|
||||||
// const auto has = AyuMessages::hasDeletedMessages(peerData, topicId);
|
addCallback(Window::PeerMenuCallback::Args{
|
||||||
// if (!has) {
|
.text = u"AyuGram"_q,
|
||||||
// return;
|
.handler = nullptr,
|
||||||
// }
|
.icon = &st::menuIconGroupReactions,
|
||||||
|
.fillSubmenu = [=](not_null<Ui::PopupMenu*> menu) {
|
||||||
addCallback(
|
const auto addAction = Ui::Menu::CreateAddActionCallback(menu);
|
||||||
tr::ayu_ViewDeletedMenuText(tr::now),
|
if (showFilters) {
|
||||||
[=]
|
addAction(
|
||||||
{
|
tr::ayu_ViewFiltersMenuText(tr::now),
|
||||||
sessionController->session().tryResolveWindow()
|
[=]
|
||||||
->showSection(std::make_shared<MessageHistory::SectionMemento>(peerData, nullptr, topicId));
|
{
|
||||||
|
sessionController->dialogId = getDialogIdFromPeer(peerData);
|
||||||
|
sessionController->showExclude = true;
|
||||||
|
sessionController->shadowBan = false;
|
||||||
|
sessionController->showSettings(Settings::AyuFiltersList::Id());
|
||||||
|
},
|
||||||
|
&st::menuIconAddToFolder);
|
||||||
|
}
|
||||||
|
const auto filteredToggleShown = FiltersController::filteredMessagesShown(peerData);
|
||||||
|
if (filteredToggleShown) {
|
||||||
|
addAction(
|
||||||
|
*filteredToggleShown
|
||||||
|
? tr::ayu_HideFilteredMessagesMenuText(tr::now)
|
||||||
|
: tr::ayu_ShowFilteredMessagesMenuText(tr::now),
|
||||||
|
[=]
|
||||||
|
{
|
||||||
|
FiltersController::toggleFilteredMessagesShown(peerData);
|
||||||
|
},
|
||||||
|
*filteredToggleShown
|
||||||
|
? &st::menuIconCaptionHide
|
||||||
|
: &st::menuIconCaptionShow);
|
||||||
|
}
|
||||||
|
if (saveDeletedMessages) {
|
||||||
|
addAction(
|
||||||
|
tr::ayu_ViewDeletedMenuText(tr::now),
|
||||||
|
[=]
|
||||||
|
{
|
||||||
|
sessionController->session().tryResolveWindow()
|
||||||
|
->showSection(std::make_shared<MessageHistory::SectionMemento>(
|
||||||
|
peerData,
|
||||||
|
nullptr,
|
||||||
|
topicId));
|
||||||
|
},
|
||||||
|
&st::menuIconArchive);
|
||||||
|
if (showFilters || filteredToggleShown.value_or(false)) addAction({ .isSeparator = true });
|
||||||
|
addAction({
|
||||||
|
.text = tr::ayu_ClearDeletedMenuText(tr::now),
|
||||||
|
.handler = ClearDeletedMessagesHandler(sessionController, peerData, topicId),
|
||||||
|
.icon = &st::menuIconClearAttention,
|
||||||
|
.isAttention = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
&st::menuIconArchive);
|
});
|
||||||
addCallback(
|
|
||||||
tr::ayu_ClearDeletedMenuText(tr::now),
|
|
||||||
ClearDeletedMessagesHandler(sessionController, peerData, topicId),
|
|
||||||
&st::menuIconDelete);
|
|
||||||
// todo view filters
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddJumpToBeginningAction(PeerData *peerData,
|
void AddJumpToBeginningAction(PeerData *peerData,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace AyuUi {
|
|||||||
|
|
||||||
bool needToShowItem(ContextMenuVisibility state);
|
bool needToShowItem(ContextMenuVisibility state);
|
||||||
|
|
||||||
void AddDeletedMessagesActions(PeerData *peerData,
|
void AddAyuGramActions(PeerData *peerData,
|
||||||
Data::Thread *thread,
|
Data::Thread *thread,
|
||||||
not_null<Window::SessionController*> sessionController,
|
not_null<Window::SessionController*> sessionController,
|
||||||
const Window::PeerMenuCallback &addCallback);
|
const Window::PeerMenuCallback &addCallback);
|
||||||
|
|||||||
@@ -134,10 +134,12 @@ void RegexEditBuilder(
|
|||||||
RegexFilter data;
|
RegexFilter data;
|
||||||
|
|
||||||
if (filter) {
|
if (filter) {
|
||||||
box->setTitle(tr::ayu_RegexFiltersEdit());
|
box->setTitle(showToast ? tr::ayu_RegexFiltersAdd() : tr::ayu_RegexFiltersEdit());
|
||||||
data = *filter;
|
data = *filter;
|
||||||
} else {
|
} else {
|
||||||
box->setTitle(tr::ayu_RegexFiltersAdd());
|
box->setTitle(tr::ayu_RegexFiltersAdd());
|
||||||
|
data.enabled = true;
|
||||||
|
data.caseInsensitive = true;
|
||||||
data.reversed = false;
|
data.reversed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -795,9 +795,11 @@ void WrapWidget::finishShowContent() {
|
|||||||
std::vector<std::shared_ptr<ContentMemento>> stack;
|
std::vector<std::shared_ptr<ContentMemento>> stack;
|
||||||
stack.push_back(std::move(contentMemento));
|
stack.push_back(std::move(contentMemento));
|
||||||
const auto sectionMemento = std::make_shared<Memento>(std::move(stack));
|
const auto sectionMemento = std::make_shared<Memento>(std::move(stack));
|
||||||
|
const auto params = Window::SectionShow(
|
||||||
|
Window::SectionShow::Way::Backward,
|
||||||
|
anim::type::instant);
|
||||||
|
|
||||||
showBackFromStackInternal(Window::SectionShow(anim::type::instant));
|
showInternal(sectionMemento.get(), params);
|
||||||
showInternal(sectionMemento.get(), Window::SectionShow(anim::type::instant));
|
|
||||||
}, _content->lifetime());
|
}, _content->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1766,6 +1766,7 @@ void Filler::fillContextMenuActions() {
|
|||||||
|
|
||||||
void Filler::fillHistoryActions() {
|
void Filler::fillHistoryActions() {
|
||||||
addToggleMuteSubmenu(true);
|
addToggleMuteSubmenu(true);
|
||||||
|
AyuUi::AddAyuGramActions(_peer, _thread, _controller, _addAction);
|
||||||
addCreateTopic();
|
addCreateTopic();
|
||||||
addInfo();
|
addInfo();
|
||||||
AyuUi::AddJumpToBeginningAction(_peer, _thread, _controller, _addAction);
|
AyuUi::AddJumpToBeginningAction(_peer, _thread, _controller, _addAction);
|
||||||
@@ -1784,7 +1785,6 @@ void Filler::fillHistoryActions() {
|
|||||||
addExportChat();
|
addExportChat();
|
||||||
addTranslate();
|
addTranslate();
|
||||||
addReport();
|
addReport();
|
||||||
AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
|
|
||||||
addClearHistory();
|
addClearHistory();
|
||||||
AyuUi::AddDeleteOwnMessagesAction(_peer, _topic, _controller, _addAction);
|
AyuUi::AddDeleteOwnMessagesAction(_peer, _topic, _controller, _addAction);
|
||||||
addDeleteChat();
|
addDeleteChat();
|
||||||
@@ -1822,6 +1822,7 @@ void Filler::fillProfileActions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Filler::fillRepliesActions() {
|
void Filler::fillRepliesActions() {
|
||||||
|
AyuUi::AddAyuGramActions(_peer, _thread, _controller, _addAction);
|
||||||
if (_topic) {
|
if (_topic) {
|
||||||
addInfo();
|
addInfo();
|
||||||
AyuUi::AddJumpToBeginningAction(_peer, _thread, _controller, _addAction);
|
AyuUi::AddJumpToBeginningAction(_peer, _thread, _controller, _addAction);
|
||||||
@@ -1832,7 +1833,6 @@ void Filler::fillRepliesActions() {
|
|||||||
addCreateTodoList();
|
addCreateTodoList();
|
||||||
addToggleTopicClosed();
|
addToggleTopicClosed();
|
||||||
addDeleteTopic();
|
addDeleteTopic();
|
||||||
AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Filler::fillScheduledActions() {
|
void Filler::fillScheduledActions() {
|
||||||
|
|||||||
Reference in New Issue
Block a user