Add support for 1 month self-destruct messages.

This commit is contained in:
John Preston 2021-07-30 14:43:48 +03:00
parent 256546071b
commit b2e829904f
12 changed files with 39 additions and 21 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -1017,8 +1017,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_manage_messages_ttl_title" = "Auto-delete messages";
"lng_manage_messages_ttl_never" = "Off";
"lng_manage_messages_ttl_after1" = "24 hours";
"lng_manage_messages_ttl_after2" = "7 days";
"lng_manage_messages_ttl_after1" = "1 day";
"lng_manage_messages_ttl_after2" = "1 week";
"lng_manage_messages_ttl_after3" = "1 month";
"lng_ttl_edit_about" = "Automatically delete new messages after a certain period of time for you and {user}.";
"lng_ttl_edit_about_group" = "Automatically delete new messages sent in this chat after a certain period of time.";
@ -1027,8 +1028,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_ttl_about_tooltip" = "New messages in this chat will be automatically deleted in {duration}.";
"lng_ttl_about_tooltip_channel" = "New messages in this chat will be automatically deleted in {duration}.";
"lng_ttl_about_tooltip_off" = "Auto-delete is now disabled.";
"lng_ttl_about_duration1" = "24 hours";
"lng_ttl_about_duration2" = "7 days";
"lng_ttl_about_duration1" = "1 day";
"lng_ttl_about_duration2" = "1 week";
"lng_ttl_about_duration3" = "1 month";
"lng_report_title" = "Report channel";
"lng_report_group_title" = "Report group";

View File

@ -93,8 +93,6 @@ void AboutBox::showVersionHistory() {
url += qsl("win/%1.zip");
} else if (Platform::IsWindows64Bit()) {
url += qsl("win64/%1.zip");
} else if (Platform::IsOSXBuild()) {
url += qsl("osx/%1.zip");
} else if (Platform::IsMac()) {
url += qsl("mac/%1.zip");
} else if (Platform::IsLinux32Bit()) {

View File

@ -297,8 +297,6 @@ QString PlatformString() {
return qsl("Windows64Bit");
} else if (Platform::IsMacStoreBuild()) {
return qsl("MacAppStore");
} else if (Platform::IsOSXBuild()) {
return qsl("OSX");
} else if (Platform::IsMac()) {
return qsl("MacOS");
} else if (Platform::IsLinux32Bit()) {

View File

@ -2020,8 +2020,11 @@ void Session::scheduleNextTTLs() {
}
const auto nearest = _ttlMessages.begin()->first;
const auto now = base::unixtime::now();
const auto timeout = (std::max(now, nearest) - now) * crl::time(1000);
_ttlCheckTimer.callOnce(timeout);
// Set timer not more than for 24 hours.
const auto maxTimeout = TimeId(86400);
const auto timeout = std::min(std::max(now, nearest) - now, maxTimeout);
_ttlCheckTimer.callOnce(timeout * crl::time(1000));
}
void Session::unregisterMessageTTL(

View File

@ -1047,9 +1047,11 @@ void GenerateItems(
const auto wrap = [](int duration) {
return (duration == 5)
? u"5 seconds"_q
: (duration < 3 * 86400)
: (duration < 2 * 86400)
? tr::lng_manage_messages_ttl_after1(tr::now)
: tr::lng_manage_messages_ttl_after2(tr::now);
: (duration < 8 * 86400)
? tr::lng_manage_messages_ttl_after2(tr::now)
: tr::lng_manage_messages_ttl_after3(tr::now);
};
auto text = !was
? tr::lng_admin_log_messages_ttl_set(tr::now, lt_from, fromLinkText, lt_duration, wrap(now))

View File

@ -399,9 +399,11 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
const auto period = action.vperiod().v;
const auto duration = (period == 5)
? u"5 seconds"_q
: (period < 3 * 86400)
: (period < 2 * 86400)
? tr::lng_ttl_about_duration1(tr::now)
: tr::lng_ttl_about_duration2(tr::now);
: (period < 8 * 86400)
? tr::lng_ttl_about_duration2(tr::now)
: tr::lng_ttl_about_duration3(tr::now);
if (isPost()) {
if (!period) {
result.text = tr::lng_action_ttl_removed_channel(tr::now);

View File

@ -37,9 +37,11 @@ void ShowAutoDeleteToast(not_null<PeerData*> peer) {
const auto duration = (period == 5)
? u"5 seconds"_q
: (period < 3 * 86400)
: (period < 2 * 86400)
? tr::lng_ttl_about_duration1(tr::now)
: tr::lng_ttl_about_duration2(tr::now);
: (period < 8 * 86400)
? tr::lng_ttl_about_duration2(tr::now)
: tr::lng_ttl_about_duration3(tr::now);
const auto text = peer->isBroadcast()
? tr::lng_ttl_about_tooltip_channel(tr::now, lt_duration, duration)
: tr::lng_ttl_about_tooltip(tr::now, lt_duration, duration);
@ -113,12 +115,16 @@ TTLButton::TTLButton(not_null<QWidget*> parent, not_null<PeerData*> peer)
Data::PeerUpdate::Flag::MessagesTTL
) | rpl::start_with_next([=] {
const auto ttl = peer->messagesTTL();
if (ttl < 3 * 86400) {
if (ttl < 2 * 86400) {
_button.setIconOverride(nullptr, nullptr);
} else {
} else if (ttl < 8 * 86400) {
_button.setIconOverride(
&st::historyMessagesTTL2Icon,
&st::historyMessagesTTL2IconOver);
} else {
_button.setIconOverride(
&st::historyMessagesTTL3Icon,
&st::historyMessagesTTL3IconOver);
}
}, _button.lifetime());
}

View File

@ -204,15 +204,18 @@ void AutoDeleteSettingsBox(
//u"5 seconds"_q, AssertIsDebug()
tr::lng_manage_messages_ttl_after1(tr::now),
tr::lng_manage_messages_ttl_after2(tr::now),
tr::lng_manage_messages_ttl_after3(tr::now),
};
const auto periodToIndex = [&](TimeId period) {
return !period
? 0
//: (period == 5) AssertIsDebug()
//? 1 AssertIsDebug()
: (period < 3 * 86400)
: (period < 2 * 86400)
? 1
: 2;
: (period < 8 * 86400)
? 2
: 3;
};
const auto indexToPeriod = [&](int index) {
return !index
@ -221,7 +224,9 @@ void AutoDeleteSettingsBox(
//? 5 AssertIsDebug()
: (index == 1)
? 86400
: 7 * 86400;
: (index == 2)
? 7 * 86400
: 31 * 86400;
};
const auto sliderCallback = [=](int index) {
state->period = indexToPeriod(index);

View File

@ -311,6 +311,8 @@ historyMessagesTTL: IconButton(historyAttach) {
}
historyMessagesTTL2Icon: icon {{ "chat/input_autodelete_7d", historyComposeIconFg }};
historyMessagesTTL2IconOver: icon {{ "chat/input_autodelete_7d", historyComposeIconFgOver }};
historyMessagesTTL3Icon: icon {{ "chat/input_autodelete_30d", historyComposeIconFg }};
historyMessagesTTL3IconOver: icon {{ "chat/input_autodelete_30d", historyComposeIconFgOver }};
historyAttachEmojiFgActive: windowActiveTextFg;
historyAttachEmojiActive: icon {{ "chat/input_smile_face", historyAttachEmojiFgActive }};
historyAttachEmojiTooltipDelta: 4px;