feat: support expiring voice/video

fix: incorrect size of burn icon
fix: read reactions and mentions after actions
This commit is contained in:
ZavaruKitsu 2024-01-17 17:07:03 +03:00
parent fc2cc6ce6b
commit 31d486c2e2
6 changed files with 107 additions and 70 deletions

View file

@ -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";

View file

@ -197,80 +197,77 @@ void MarkAsReadChatList(not_null<Dialogs::MainList *> list)
ranges::for_each(mark, MarkAsReadThread);
}
void readMentions(base::weak_ptr<Data::Thread> 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<Data::Thread> 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<Data::Thread *> thread)
{
const auto readHistory = [&](not_null<History *> history)
{
history->owner().histories().readInbox(history);
};
const auto readMentions = [=](
base::weak_ptr<Data::Thread> 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<Data::Thread *> thread)
{
readMentions(base::make_weak(thread), readMentions);
};
const auto readReactions = [=](
base::weak_ptr<Data::Thread> 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<Data::Thread *> thread)
{
readReactions(base::make_weak(thread), readReactions);
readReactions(base::make_weak(thread));
};
if (thread->chatListBadgesState().unread) {
@ -327,6 +324,14 @@ void readHistory(not_null<HistoryItem *> message)
}).send();
}
});
if (history->unreadMentions().has()) {
readMentions(history->asThread());
}
if (history->unreadReactions().has()) {
readReactions(history->asThread());
}
}
QString formatTTL(int time)

View file

@ -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<Ui::RoundButton>(
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<Ui::ImportantTooltip>(
this,
object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(

View file

@ -791,6 +791,11 @@ void ShowTrialTranscribesToast(int left, TimeId until) {
}
void ClearMediaAsExpired(not_null<HistoryItem*> item) {
const auto settings = &AyuSettings::getInstance();
if (settings->saveDeletedMessages) {
return;
}
if (const auto media = item->media()) {
if (!media->ttlSeconds()) {
return;

View file

@ -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<rpl::lifetime>();
TTLVoiceStops(fullId) | rpl::start_with_next([=]() mutable {

View file

@ -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();