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;
|
||||
}
|
||||
|
||||
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) {
|
||||
std::lock_guard lock(mutex);
|
||||
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);
|
||||
|
||||
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 invalidate(not_null<HistoryItem*> item);
|
||||
|
||||
@@ -20,8 +20,12 @@
|
||||
#include "history/history_item_components.h"
|
||||
#include "unicode/regex.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace FiltersController {
|
||||
|
||||
std::unordered_set<long long> showingFilteredMessages;
|
||||
|
||||
bool filterBlocked(const not_null<HistoryItem*> item) {
|
||||
if (item->from() != item->history()->peer) {
|
||||
if (isBlocked(item)) {
|
||||
@@ -123,6 +127,10 @@ bool isBlocked(const not_null<PeerData*> peer) {
|
||||
}
|
||||
|
||||
bool filtered(const not_null<HistoryItem*> item) {
|
||||
if (showingFilteredMessages.contains(item->history()->peer->id.value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &settings = AyuSettings::getInstance();
|
||||
if (!settings.filtersEnabled()) {
|
||||
return false;
|
||||
@@ -153,6 +161,23 @@ bool filtered(const not_null<HistoryItem*> item) {
|
||||
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) {
|
||||
const auto &settings = AyuSettings::getInstance();
|
||||
if (!settings.filtersEnabled()) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "unicode/regex.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -19,6 +20,8 @@ bool isEnabled(PeerData *peer);
|
||||
bool isBlocked(not_null<HistoryItem*> item);
|
||||
bool isBlocked(not_null<PeerData*> peer);
|
||||
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);
|
||||
|
||||
|
||||
@@ -77,3 +77,5 @@ ayuHistoryFileInPlugin: icon {{ "ayu/history_file_plugin", historyFileInIconFg }
|
||||
ayuHistoryFileInPluginSelected: icon {{ "ayu/history_file_plugin", historyFileInIconFgSelected }};
|
||||
ayuHistoryFileOutPlugin: icon {{ "ayu/history_file_plugin", historyFileOutIconFg }};
|
||||
ayuHistoryFileOutPluginSelected: icon {{ "ayu/history_file_plugin", historyFileOutIconFgSelected }};
|
||||
|
||||
menuIconClearAttention: icon {{ "menu/clear", menuIconAttentionColor }};
|
||||
|
||||
@@ -13,10 +13,12 @@
|
||||
#include "ayu/ayu_settings.h"
|
||||
#include "ayu/ayu_state.h"
|
||||
#include "ayu/data/messages_storage.h"
|
||||
#include "ayu/features/filters/filters_controller.h"
|
||||
#include "ayu/features/forward/ayu_forward.h"
|
||||
#include "ayu/ui/context_menu/menu_item_subtext.h"
|
||||
#include "ayu/ui/message_history/history_section.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/telegram_helpers.h"
|
||||
#include "base/call_delayed.h"
|
||||
@@ -215,7 +217,7 @@ bool needToShowItem(ContextMenuVisibility state) {
|
||||
|| (state == ContextMenuVisibility::VisibleWithModifier && base::IsExtendedContextMenuModifierPressed());
|
||||
}
|
||||
|
||||
void AddDeletedMessagesActions(PeerData *peerData,
|
||||
void AddAyuGramActions(PeerData *peerData,
|
||||
Data::Thread *thread,
|
||||
not_null<Window::SessionController*> sessionController,
|
||||
const Window::PeerMenuCallback &addCallback) {
|
||||
@@ -223,27 +225,72 @@ void AddDeletedMessagesActions(PeerData *peerData,
|
||||
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 topicId = topic ? topic->rootId().bare : 0;
|
||||
|
||||
// const auto has = AyuMessages::hasDeletedMessages(peerData, topicId);
|
||||
// if (!has) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
addCallback(
|
||||
tr::ayu_ViewDeletedMenuText(tr::now),
|
||||
[=]
|
||||
{
|
||||
sessionController->session().tryResolveWindow()
|
||||
->showSection(std::make_shared<MessageHistory::SectionMemento>(peerData, nullptr, topicId));
|
||||
addCallback(Window::PeerMenuCallback::Args{
|
||||
.text = u"AyuGram"_q,
|
||||
.handler = nullptr,
|
||||
.icon = &st::menuIconGroupReactions,
|
||||
.fillSubmenu = [=](not_null<Ui::PopupMenu*> menu) {
|
||||
const auto addAction = Ui::Menu::CreateAddActionCallback(menu);
|
||||
if (showFilters) {
|
||||
addAction(
|
||||
tr::ayu_ViewFiltersMenuText(tr::now),
|
||||
[=]
|
||||
{
|
||||
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,
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace AyuUi {
|
||||
|
||||
bool needToShowItem(ContextMenuVisibility state);
|
||||
|
||||
void AddDeletedMessagesActions(PeerData *peerData,
|
||||
void AddAyuGramActions(PeerData *peerData,
|
||||
Data::Thread *thread,
|
||||
not_null<Window::SessionController*> sessionController,
|
||||
const Window::PeerMenuCallback &addCallback);
|
||||
|
||||
@@ -134,10 +134,12 @@ void RegexEditBuilder(
|
||||
RegexFilter data;
|
||||
|
||||
if (filter) {
|
||||
box->setTitle(tr::ayu_RegexFiltersEdit());
|
||||
box->setTitle(showToast ? tr::ayu_RegexFiltersAdd() : tr::ayu_RegexFiltersEdit());
|
||||
data = *filter;
|
||||
} else {
|
||||
box->setTitle(tr::ayu_RegexFiltersAdd());
|
||||
data.enabled = true;
|
||||
data.caseInsensitive = true;
|
||||
data.reversed = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -795,9 +795,11 @@ void WrapWidget::finishShowContent() {
|
||||
std::vector<std::shared_ptr<ContentMemento>> stack;
|
||||
stack.push_back(std::move(contentMemento));
|
||||
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(), Window::SectionShow(anim::type::instant));
|
||||
showInternal(sectionMemento.get(), params);
|
||||
}, _content->lifetime());
|
||||
}
|
||||
|
||||
|
||||
@@ -1766,6 +1766,7 @@ void Filler::fillContextMenuActions() {
|
||||
|
||||
void Filler::fillHistoryActions() {
|
||||
addToggleMuteSubmenu(true);
|
||||
AyuUi::AddAyuGramActions(_peer, _thread, _controller, _addAction);
|
||||
addCreateTopic();
|
||||
addInfo();
|
||||
AyuUi::AddJumpToBeginningAction(_peer, _thread, _controller, _addAction);
|
||||
@@ -1784,7 +1785,6 @@ void Filler::fillHistoryActions() {
|
||||
addExportChat();
|
||||
addTranslate();
|
||||
addReport();
|
||||
AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
|
||||
addClearHistory();
|
||||
AyuUi::AddDeleteOwnMessagesAction(_peer, _topic, _controller, _addAction);
|
||||
addDeleteChat();
|
||||
@@ -1822,6 +1822,7 @@ void Filler::fillProfileActions() {
|
||||
}
|
||||
|
||||
void Filler::fillRepliesActions() {
|
||||
AyuUi::AddAyuGramActions(_peer, _thread, _controller, _addAction);
|
||||
if (_topic) {
|
||||
addInfo();
|
||||
AyuUi::AddJumpToBeginningAction(_peer, _thread, _controller, _addAction);
|
||||
@@ -1832,7 +1833,6 @@ void Filler::fillRepliesActions() {
|
||||
addCreateTodoList();
|
||||
addToggleTopicClosed();
|
||||
addDeleteTopic();
|
||||
AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
|
||||
}
|
||||
|
||||
void Filler::fillScheduledActions() {
|
||||
|
||||
Reference in New Issue
Block a user