From 31d486c2e2defb4571e3bade6ef2d1384664e2a2 Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Wed, 17 Jan 2024 17:07:03 +0300 Subject: [PATCH] feat: support expiring voice/video fix: incorrect size of burn icon fix: read reactions and mentions after actions --- Telegram/Resources/langs/lang.strings | 16 ++- .../ayu/utils/telegram_helpers.cpp | 127 +++++++++--------- .../chat_helpers/ttl_media_layer_widget.cpp | 12 +- .../history/history_item_helpers.cpp | 5 + .../view/media/history_view_document.cpp | 9 +- .../history/view/media/history_view_gif.cpp | 8 +- 6 files changed, 107 insertions(+), 70 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index c6570fe5b..772a0c2a5 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4671,7 +4671,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_DrawerElementsHeader" = "Drawer Elements"; "ayu_TrayElementsHeader" = "Tray Elements"; "ayu_RegexFilters" = "Message Filters"; -"ayu_RegexFiltersAmount" = "filters"; +"ayu_RegexFiltersAmount_zero" = "%1$d filters"; +"ayu_RegexFiltersAmount_one" = "1 filter"; +"ayu_RegexFiltersAmount_two" = "%1$d filters"; +"ayu_RegexFiltersAmount_few" = "%1$d filters"; +"ayu_RegexFiltersAmount_many" = "%1$d filters"; +"ayu_RegexFiltersAmount_other" = "%1$d filters"; +"ayu_RegexFiltersExcludedAmount_zero" = "%1$d excluded"; +"ayu_RegexFiltersExcludedAmount_one" = "1 excluded"; +"ayu_RegexFiltersExcludedAmount_two" = "%1$d excluded"; +"ayu_RegexFiltersExcludedAmount_few" = "%1$d excluded"; +"ayu_RegexFiltersExcludedAmount_many" = "%1$d excluded"; +"ayu_RegexFiltersExcludedAmount_other" = "%1$d excluded"; "ayu_RegexFiltersHeader" = "Filters"; "ayu_RegexFiltersShared" = "Shared filters"; "ayu_RegexFiltersExcluded" = "Excluded filters"; @@ -4792,6 +4803,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_AyuForwardStatusLoadingMedia" = "Loading media…"; "ayu_AyuForwardForwardingDescription" = "Please keep this window open while AyuGram is forwarding your messages."; "ayu_AyuForwardLoadingMediaDescription" = "Please keep this window open while AyuGram is downloading media from your messages."; +"ayu_ExpireMediaContextMenuText" = "Burn"; +"ayu_ExpiringVoiceMessageNote" = "This voice message can be played as many times as you want."; +"ayu_ExpiringVideoMessageNote" = "This video message can be played as many times as you want."; "ayu_UserNotFoundMessage" = "User not found."; "ayu_DeleteDateMenuText" = "Delete Date"; "ayu_ReadDateMenuText" = "Read Date"; diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp index 1878d9d7c..82be0cb9a 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp @@ -197,80 +197,77 @@ void MarkAsReadChatList(not_null list) ranges::for_each(mark, MarkAsReadThread); } +void readMentions(base::weak_ptr weakThread) +{ + const auto thread = weakThread.get(); + if (!thread) { + return; + } + const auto peer = thread->peer(); + const auto topic = thread->asTopic(); + const auto rootId = topic ? topic->rootId() : 0; + using Flag = MTPmessages_ReadMentions::Flag; + peer->session().api().request(MTPmessages_ReadMentions( + MTP_flags(rootId ? Flag::f_top_msg_id : Flag()), + peer->input, + MTP_int(rootId) + )).done([=](const MTPmessages_AffectedHistory &result) + { + const auto offset = peer->session().api().applyAffectedHistory( + peer, + result); + if (offset > 0) { + readMentions(weakThread); + } + else { + peer->owner().history(peer)->clearUnreadMentionsFor(rootId); + } + }).send(); +} + +void readReactions(base::weak_ptr weakThread) +{ + const auto thread = weakThread.get(); + if (!thread) { + return; + } + const auto topic = thread->asTopic(); + const auto peer = thread->peer(); + const auto rootId = topic ? topic->rootId() : 0; + using Flag = MTPmessages_ReadReactions::Flag; + peer->session().api().request(MTPmessages_ReadReactions( + MTP_flags(rootId ? Flag::f_top_msg_id : Flag(0)), + peer->input, + MTP_int(rootId) + )).done([=](const MTPmessages_AffectedHistory &result) + { + const auto offset = peer->session().api().applyAffectedHistory( + peer, + result); + if (offset > 0) { + readReactions(weakThread); + } + else { + peer->owner().history(peer)->clearUnreadReactionsFor(rootId); + } + }).send(); +} + void MarkAsReadThread(not_null thread) { const auto readHistory = [&](not_null history) { history->owner().histories().readInbox(history); }; - const auto readMentions = [=]( - base::weak_ptr weakThread, - auto resend) -> void - { - const auto thread = weakThread.get(); - if (!thread) { - return; - } - const auto peer = thread->peer(); - const auto topic = thread->asTopic(); - const auto rootId = topic ? topic->rootId() : 0; - using Flag = MTPmessages_ReadMentions::Flag; - peer->session().api().request(MTPmessages_ReadMentions( - MTP_flags(rootId ? Flag::f_top_msg_id : Flag()), - peer->input, - MTP_int(rootId) - )).done([=](const MTPmessages_AffectedHistory &result) - { - const auto offset = peer->session().api().applyAffectedHistory( - peer, - result); - if (offset > 0) { - resend(weakThread, resend); - } - else { - peer->owner().history(peer)->clearUnreadMentionsFor(rootId); - } - }).send(); - }; const auto sendReadMentions = [=]( not_null thread) { - readMentions(base::make_weak(thread), readMentions); - }; - - const auto readReactions = [=]( - base::weak_ptr weakThread, - auto resend) -> void - { - const auto thread = weakThread.get(); - if (!thread) { - return; - } - const auto topic = thread->asTopic(); - const auto peer = thread->peer(); - const auto rootId = topic ? topic->rootId() : 0; - using Flag = MTPmessages_ReadReactions::Flag; - peer->session().api().request(MTPmessages_ReadReactions( - MTP_flags(rootId ? Flag::f_top_msg_id : Flag(0)), - peer->input, - MTP_int(rootId) - )).done([=](const MTPmessages_AffectedHistory &result) - { - const auto offset = peer->session().api().applyAffectedHistory( - peer, - result); - if (offset > 0) { - resend(weakThread, resend); - } - else { - peer->owner().history(peer)->clearUnreadReactionsFor(rootId); - } - }).send(); + readMentions(base::make_weak(thread)); }; const auto sendReadReactions = [=]( not_null thread) { - readReactions(base::make_weak(thread), readReactions); + readReactions(base::make_weak(thread)); }; if (thread->chatListBadgesState().unread) { @@ -327,6 +324,14 @@ void readHistory(not_null message) }).send(); } }); + + if (history->unreadMentions().has()) { + readMentions(history->asThread()); + } + + if (history->unreadReactions().has()) { + readReactions(history->asThread()); + } } QString formatTTL(int time) diff --git a/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp b/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp index f2445a166..9fab91f06 100644 --- a/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp @@ -37,6 +37,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_chat_helpers.h" #include "styles/style_dialogs.h" +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace ChatHelpers { namespace { @@ -190,10 +194,12 @@ PreviewWrap::PreviewWrap( } }, lifetime()); + const auto settings = &AyuSettings::getInstance(); + { const auto close = Ui::CreateChild( this, - item->out() + item->out() || settings->saveDeletedMessages ? tr::lng_close() : tr::lng_ttl_voice_close_in(), st::ttlMediaButton); @@ -227,8 +233,8 @@ PreviewWrap::PreviewWrap( ) | rpl::map(Ui::Text::RichLangValue), Ui::Text::RichLangValue) : (isRound - ? tr::lng_ttl_round_tooltip_in - : tr::lng_ttl_voice_tooltip_in)(Ui::Text::RichLangValue); + ? settings->saveDeletedMessages ? tr::ayu_ExpiringVideoMessageNote : tr::lng_ttl_round_tooltip_in + : settings->saveDeletedMessages ? tr::ayu_ExpiringVoiceMessageNote : tr::lng_ttl_voice_tooltip_in)(Ui::Text::RichLangValue); const auto tooltip = Ui::CreateChild( this, object_ptr>( diff --git a/Telegram/SourceFiles/history/history_item_helpers.cpp b/Telegram/SourceFiles/history/history_item_helpers.cpp index 06bd10837..bec58398d 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.cpp +++ b/Telegram/SourceFiles/history/history_item_helpers.cpp @@ -791,6 +791,11 @@ void ShowTrialTranscribesToast(int left, TimeId until) { } void ClearMediaAsExpired(not_null item) { + const auto settings = &AyuSettings::getInstance(); + if (settings->saveDeletedMessages) { + return; + } + if (const auto media = item->media()) { if (!media->ttlSeconds()) { return; diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 3eb378a17..27b1582c8 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -40,6 +40,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_chat.h" #include "styles/style_dialogs.h" +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace HistoryView { namespace { @@ -323,7 +327,10 @@ Document::Document( const auto &data = &_parent->data()->history()->owner(); _parent->data()->removeFromSharedMediaIndex(); setDocumentLinks(_data, realParent, [=] { - _openl = nullptr; + const auto settings = &AyuSettings::getInstance(); + if (!settings->saveDeletedMessages) { + _openl = nullptr; + } auto lifetime = std::make_shared(); TTLVoiceStops(fullId) | rpl::start_with_next([=]() mutable { diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 03164193b..f89a5771a 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -80,10 +80,10 @@ int gifMaxStatusWidth(DocumentData *document) { const auto centerRect = r - centerMargins; const auto &icon = context.imageStyle()->historyVideoMessageTtlIcon; const auto iconRect = QRect( - rect::right(centerRect) - icon.width() * 0.75, - rect::bottom(centerRect) - icon.height() * 0.75, - icon.width(), - icon.height()); + rect::right(centerRect) - icon.width() * 1.2, + rect::bottom(centerRect) - icon.height() * 1.2, + icon.width() / 3, + icon.height() / 3); { auto hq = PainterHighQualityEnabler(p); auto path = QPainterPath();