Update API scheme, simplify auto-delete.

This commit is contained in:
John Preston 2021-02-15 14:31:04 +04:00
parent 05488022c7
commit 781e7a2e79
13 changed files with 95 additions and 192 deletions

View File

@ -977,23 +977,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_manage_history_visibility_hidden_legacy" = "New members won't see more than 100 previous messages.";
"lng_manage_messages_ttl_title" = "Auto-delete messages";
"lng_manage_messages_ttl_never" = "Never";
"lng_manage_messages_ttl_after1" = "After 24 hours";
"lng_manage_messages_ttl_after2" = "After 7 days";
"lng_manage_messages_ttl_about" = "Turning on this setting will make auto-delete messages from this group after the selected period.";
"lng_manage_messages_ttl_about_channel" = "Turning on this setting will make auto-delete messages from this channel after the selected period.";
"lng_manage_messages_ttl_never" = "Off";
"lng_manage_messages_ttl_after1" = "24 hours";
"lng_manage_messages_ttl_after2" = "7 days";
"lng_ttl_edit_title" = "Auto-delete messages in this chat";
"lng_ttl_edit_about" = "Automatically delete new messages sent in this chat after a certain period of time.";
"lng_ttl_edit_about_other" = "{user} has set messages to auto-delete in {duration} for both of you.";
"lng_ttl_edit_about_you" = "You have set messages to auto-delete in {duration} for both you and {user}.";
"lng_ttl_edit_about_you_only" = "You have set messages to auto-delete in {duration} only for yourself.";
"lng_ttl_also_checkbox" = "Also delete for {user}";
"lng_ttl_about_tooltip_on_title" = "Auto-delete On {duration}";
"lng_ttl_about_tooltip" = "Messages in this chat will auto-delete in {duration}.";
"lng_ttl_about_tooltip_no_longer" = "{user} has set messages to auto-delete in {duration}. You can't make this interval longer.";
"lng_ttl_about_tooltip_no_cancel" = "{user} has set messages to auto-delete in {duration}. You can't cancel this.";
"lng_ttl_about_tooltip_off" = "Auto-delete is now Off.";
"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.";
"lng_ttl_edit_about_channel" = "Automatically delete new messages sent in this channel after a certain period of time.";
"lng_ttl_edit_save" = "Confirm";
"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";
@ -1117,6 +1112,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_action_changed_title" = "{from} changed group name to «{title}»";
"lng_action_changed_title_channel" = "Channel name was changed to «{title}»";
"lng_action_created_chat" = "{from} created group «{title}»";
"lng_action_ttl_changed" = "{from} has set messages to auto-delete in {duration}";
"lng_action_ttl_changed_channel" = "New messages will auto-delete in {duration}";
"lng_action_ttl_removed" = "{from} has set messages not to auto-delete";
"lng_action_ttl_removed_channel" = "New messages will not auto-delete";
"lng_action_created_channel" = "Channel created";
"lng_action_pinned_message" = "{from} pinned «{text}»";
"lng_action_pinned_media" = "{from} pinned {media}";

View File

@ -127,8 +127,8 @@ chatForbidden#7328bdb id:int title:string = Chat;
channel#d31a961e flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?Vector<RestrictionReason> admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat;
channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat;
chatFull#e22542a0 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector<BotInfo> pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl:flags.14?PeerHistoryTTL = ChatFull;
channelFull#7c62b528 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector<BotInfo> migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl:flags.24?PeerHistoryTTL pending_suggestions:flags.25?Vector<string> = ChatFull;
chatFull#f06c4018 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector<BotInfo> pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int = ChatFull;
channelFull#2548c037 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector<BotInfo> migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector<string> = ChatFull;
chatParticipant#c8d7493e user_id:int inviter_id:int date:int = ChatParticipant;
chatParticipantCreator#da13538a user_id:int = ChatParticipant;
@ -184,6 +184,7 @@ messageActionContactSignUp#f3f25f76 = MessageAction;
messageActionGeoProximityReached#98e0d697 from_id:Peer to_id:Peer distance:int = MessageAction;
messageActionGroupCall#7a0d7f42 flags:# call:InputGroupCall duration:flags.0?int = MessageAction;
messageActionInviteToGroupCall#76b9f11a call:InputGroupCall users:Vector<int> = MessageAction;
messageActionSetMessagesTTL#aa1afbfd period:int = MessageAction;
dialog#2c171f72 flags:# pinned:flags.2?true unread_mark:flags.3?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog;
dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog;
@ -231,7 +232,7 @@ inputReportReasonCopyright#9b89f93a = ReportReason;
inputReportReasonGeoIrrelevant#dbd4feed = ReportReason;
inputReportReasonFake#f5ddd6e7 = ReportReason;
userFull#a54475a7 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true user:User about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl:flags.14?PeerHistoryTTL = UserFull;
userFull#139a9a77 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true user:User about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int = UserFull;
contact#f911c994 user_id:int mutual:Bool = Contact;
@ -358,7 +359,6 @@ updateDialogFilter#26ffde7d flags:# id:int filter:flags.0?DialogFilter = Update;
updateDialogFilterOrder#a5d72105 order:Vector<int> = Update;
updateDialogFilters#3504914f = Update;
updatePhoneCallSignalingData#2661bf09 phone_call_id:long data:bytes = Update;
updateChannelParticipant#65d2b464 flags:# channel_id:int date:int user_id:int prev_participant:flags.0?ChannelParticipant new_participant:flags.1?ChannelParticipant qts:int = Update;
updateChannelMessageForwards#6e8a84df channel_id:int id:int forwards:int = Update;
updateReadChannelDiscussionInbox#1cc7de54 flags:# channel_id:int top_msg_id:int read_max_id:int broadcast_id:flags.0?int broadcast_post:flags.0?int = Update;
updateReadChannelDiscussionOutbox#4638a26c channel_id:int top_msg_id:int read_max_id:int = Update;
@ -369,7 +369,9 @@ updatePinnedChannelMessages#8588878b flags:# pinned:flags.0?true channel_id:int
updateChat#1330a196 chat_id:int = Update;
updateGroupCallParticipants#f2ebdb4e call:InputGroupCall participants:Vector<GroupCallParticipant> version:int = Update;
updateGroupCall#a45eb99b chat_id:int call:GroupCall = Update;
updatePeerHistoryTTL#1265be8 flags:# peer:Peer ttl:flags.0?PeerHistoryTTL = Update;
updatePeerHistoryTTL#bb9bb9a5 flags:# peer:Peer ttl_period:flags.0?int = Update;
updateChannelParticipant#65d2b464 flags:# channel_id:int date:int user_id:int prev_participant:flags.0?ChannelParticipant new_participant:flags.1?ChannelParticipant qts:int = Update;
updateBotStopped#30ec6ebc user_id:int stopped:Bool qts:int = Update;
updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
@ -1221,9 +1223,6 @@ messages.historyImportParsed#5e0fb7b9 flags:# pm:flags.0?true group:flags.1?true
messages.affectedFoundMessages#ef8d3e6c pts:int pts_count:int offset:int messages:Vector<int> = messages.AffectedFoundMessages;
peerHistoryTTLPM#cf622d96 flags:# my_oneside:flags.0?true my_ttl_period:flags.1?int peer_ttl_period:flags.2?int = PeerHistoryTTL;
peerHistoryTTL#3e11cee9 ttl_period:int = PeerHistoryTTL;
chatInviteImporter#1e3e6680 user_id:int date:int = ChatInviteImporter;
messages.exportedChatInvites#bdc62dcc count:int invites:Vector<ExportedChatInvite> users:Vector<User> = messages.ExportedChatInvites;
@ -1499,7 +1498,7 @@ messages.deleteRevokedExportedChatInvites#56987bd5 peer:InputPeer admin_id:Input
messages.deleteExportedChatInvite#d464a42b peer:InputPeer link:string = Bool;
messages.getAdminsWithInvites#3920e6ef peer:InputPeer = messages.ChatAdminsWithInvites;
messages.getChatInviteImporters#26fb7289 peer:InputPeer link:string offset_date:int offset_user:InputUser limit:int = messages.ChatInviteImporters;
messages.setHistoryTTL#cccb4721 flags:# pm_oneside:flags.0?true peer:InputPeer period:int = Updates;
messages.setHistoryTTL#b80e5fe4 peer:InputPeer period:int = Updates;
updates.getState#edd4882a = updates.State;
updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;

View File

@ -1824,11 +1824,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
const auto &d = update.c_updatePeerHistoryTTL();
const auto peerId = peerFromMTP(d.vpeer());
if (const auto peer = session().data().peerLoaded(peerId)) {
if (const auto ttl = d.vttl()) {
peer->applyMessagesTTL(*ttl);
} else {
peer->setMessagesTTL(0, 0, false);
}
peer->setMessagesTTL(d.vttl_period().value_or_empty());
}
} break;

View File

@ -750,9 +750,7 @@ void ApplyChannelUpdate(
channel->clearGroupCall();
}
if (const auto ttl = update.vttl()) {
channel->applyMessagesTTL(*ttl);
}
channel->setMessagesTTL(update.vttl_period().value_or_empty());
channel->setFullFlags(update.vflags().v);
channel->setUserpicPhoto(update.vchat_photo());
if (const auto migratedFrom = update.vmigrated_from_chat_id()) {

View File

@ -377,9 +377,7 @@ void ApplyChatUpdate(not_null<ChatData*> chat, const MTPDchatFull &update) {
chat->clearGroupCall();
}
if (const auto ttl = update.vttl()) {
chat->applyMessagesTTL(*ttl);
}
chat->setMessagesTTL(update.vttl_period().value_or_empty());
if (const auto info = update.vbot_info()) {
for (const auto &item : info->v) {
item.match([&](const MTPDbotInfo &data) {

View File

@ -950,41 +950,18 @@ void PeerData::setLoadedStatus(LoadedStatus status) {
}
TimeId PeerData::messagesTTL() const {
return (_ttlMyPeriod && _ttlPeerPeriod)
? std::min(_ttlMyPeriod, _ttlPeerPeriod)
: std::max(_ttlMyPeriod, _ttlPeerPeriod);
return _ttlPeriod;
}
void PeerData::setMessagesTTL(
TimeId myPeriod,
TimeId peerPeriod,
bool oneSide) {
if (_ttlMyPeriod != myPeriod
|| _ttlPeerPeriod != peerPeriod
|| _ttlOneSide != oneSide) {
_ttlMyPeriod = myPeriod;
_ttlPeerPeriod = peerPeriod;
_ttlOneSide = oneSide;
void PeerData::setMessagesTTL(TimeId period) {
if (_ttlPeriod != period) {
_ttlPeriod = period;
session().changes().peerUpdated(
this,
Data::PeerUpdate::Flag::MessagesTTL);
}
}
void PeerData::applyMessagesTTL(const MTPPeerHistoryTTL &ttl) {
ttl.match([&](const MTPDpeerHistoryTTL &data) {
setMessagesTTL(
data.vttl_period().v,
0,
false);
}, [&](const MTPDpeerHistoryTTLPM &data) {
setMessagesTTL(
data.vmy_ttl_period().value_or_empty(),
data.vpeer_ttl_period().value_or_empty(),
data.is_my_oneside());
});
}
namespace Data {
std::vector<ChatRestrictions> ListOfRestrictions() {

View File

@ -382,18 +382,8 @@ public:
}
void setLoadedStatus(LoadedStatus status);
[[nodiscard]] TimeId myMessagesTTL() const {
return _ttlMyPeriod;
}
[[nodiscard]] TimeId peerMessagesTTL() const {
return _ttlPeerPeriod;
}
[[nodiscard]] bool oneSideTTL() const {
return _ttlOneSide;
}
[[nodiscard]] TimeId messagesTTL() const;
void setMessagesTTL(TimeId myPeriod, TimeId peerPeriod, bool oneSide);
void applyMessagesTTL(const MTPPeerHistoryTTL &ttl);
void setMessagesTTL(TimeId period);
[[nodiscard]] Data::GroupCall *groupCall() const;
@ -439,9 +429,7 @@ private:
crl::time _lastFullUpdate = 0;
TimeId _ttlMyPeriod = 0;
TimeId _ttlPeerPeriod = 0;
bool _ttlOneSide = false;
TimeId _ttlPeriod = 0;
bool _hasPinnedMessages = false;
Settings _settings = { kSettingsUnknown };

View File

@ -256,9 +256,7 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
MTP_inputNotifyPeer(user->input),
update.vnotify_settings());
if (const auto ttl = update.vttl()) {
user->applyMessagesTTL(*ttl);
}
user->setMessagesTTL(update.vttl_period().value_or_empty());
if (const auto info = update.vbot_info()) {
user->setBotInfo(*info);
} else {

View File

@ -1128,6 +1128,8 @@ ServiceAction ParseServiceAction(
content.userIds.push_back(user.v);
}
result.content = content;
}, [&](const MTPDmessageActionSetMessagesTTL &data) {
// #TODO ttl
}, [](const MTPDmessageActionEmpty &data) {});
return result;
}

View File

@ -371,6 +371,31 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
return prepareInvitedToCallText(action.vusers().v, linkCallId);
};
auto prepareSetMessagesTTL = [this](const MTPDmessageActionSetMessagesTTL &action) {
auto result = PreparedText{};
const auto period = action.vperiod().v;
const auto duration = (period == 5) AssertIsDebug()
? u"5 seconds"_q AssertIsDebug()
: (period < 3 * 86400)
? tr::lng_ttl_about_duration1(tr::now)
: tr::lng_ttl_about_duration2(tr::now);
if (isPost()) {
if (!period) {
result.text = tr::lng_action_ttl_removed_channel(tr::now);
} else {
result.text = tr::lng_action_ttl_changed_channel(tr::now, lt_duration, duration);
}
} else {
result.links.push_back(fromLink());
if (!period) {
result.text = tr::lng_action_ttl_removed(tr::now, lt_from, fromLinkText());
} else {
result.text = tr::lng_action_ttl_changed(tr::now, lt_from, fromLinkText(), lt_duration, duration);
}
}
return result;
};
const auto messageText = action.match([&](
const MTPDmessageActionChatAddUser &data) {
return prepareChatAddUserText(data);
@ -424,6 +449,8 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
return prepareGroupCall(data);
}, [&](const MTPDmessageActionInviteToGroupCall &data) {
return prepareInviteToGroupCall(data);
}, [&](const MTPDmessageActionSetMessagesTTL &data) {
return prepareSetMessagesTTL(data);
}, [](const MTPDmessageActionEmpty &) {
return PreparedText{ tr::lng_message_empty(tr::now) };
});

View File

@ -40,23 +40,11 @@ void ShowAutoDeleteToast(not_null<PeerData*> peer) {
: (period < 3 * 86400)
? tr::lng_ttl_about_duration1(tr::now)
: tr::lng_ttl_about_duration2(tr::now);
auto rich = Ui::Text::Bold(
tr::lng_ttl_about_tooltip_on_title(tr::now, lt_duration, duration)
).append('\n');
const auto myPeriod = peer->myMessagesTTL();
rich.append((period == myPeriod)
? tr::lng_ttl_about_tooltip(tr::now, lt_duration, duration)
: (myPeriod
? tr::lng_ttl_about_tooltip_no_longer
: tr::lng_ttl_about_tooltip_no_cancel)(
tr::now,
lt_user,
peer->shortName(),
lt_duration,
duration));
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);
Ui::ShowMultilineToast({
.text = std::move(rich),
.text = { text },
.duration = kToastDuration,
});
}
@ -66,27 +54,20 @@ void AutoDeleteSettingsBox(
not_null<PeerData*> peer) {
struct State {
TimeId savingPeriod = 0;
bool savingOneSide = false;
mtpRequestId savingRequestId = 0;
QPointer<Ui::GenericBox> weak;
};
const auto state = std::make_shared<State>(State{ .weak = box.get() });
auto callback = [=](TimeId period, bool oneSide) {
auto callback = [=](TimeId period) {
auto &api = peer->session().api();
if (state->savingRequestId) {
if (period == state->savingPeriod
&& oneSide == state->savingOneSide) {
if (period == state->savingPeriod) {
return;
}
api.request(state->savingRequestId).cancel();
}
state->savingPeriod = period;
state->savingOneSide = oneSide;
using Flag = MTPmessages_SetHistoryTTL::Flag;
state->savingRequestId = api.request(MTPmessages_SetHistoryTTL(
MTP_flags((oneSide && peer->isUser())
? Flag::f_pm_oneside
: Flag(0)),
peer->input,
MTP_int(period)
)).done([=](const MTPUpdates &result) {
@ -101,12 +82,12 @@ void AutoDeleteSettingsBox(
};
Ui::AutoDeleteSettingsBox(
box,
peer->myMessagesTTL(),
peer->peerMessagesTTL(),
peer->oneSideTTL(),
peer->messagesTTL(),
(peer->isUser()
? std::make_optional(peer->shortName())
: std::nullopt),
? tr::lng_ttl_edit_about(lt_user, rpl::single(peer->shortName()))
: peer->isBroadcast()
? tr::lng_ttl_edit_about_channel()
: tr::lng_ttl_edit_about_group()),
std::move(callback));
}

View File

@ -186,60 +186,53 @@ object_ptr<Ui::RpWidget> CreateSliderForTTL(
void AutoDeleteSettingsBox(
not_null<Ui::GenericBox*> box,
TimeId ttlMyPeriod,
TimeId ttlPeerPeriod,
bool ttlOneSide,
std::optional<QString> userFirstName,
Fn<void(TimeId, bool)> callback) {
TimeId ttlPeriod,
rpl::producer<QString> about,
Fn<void(TimeId)> callback) {
box->setTitle(tr::lng_manage_messages_ttl_title());
box->setWidth(st::boxWideWidth);
struct State {
TimeId my = 0;
bool oneSide = false;
rpl::event_stream<rpl::producer<QString>> aboutTexts;
Fn<void()> update;
TimeId period = 0;
};
const auto state = box->lifetime().make_state<State>(State{
.my = ttlMyPeriod,
.oneSide = ttlOneSide,
.period = ttlPeriod,
});
const auto options = std::vector<QString>{
tr::lng_manage_messages_ttl_never(tr::now),
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_never(tr::now),
};
const auto periodToIndex = [&](TimeId period) {
return !period
? 3
? 0
: (period == 5) AssertIsDebug()
? 0 AssertIsDebug()
? 1 AssertIsDebug()
: (period < 3 * 86400)
? 1
: 2;
? 2
: 3;
};
const auto indexToPeriod = [&](int index) {
return !index
? 5 AssertIsDebug()
? 0
: (index == 1) AssertIsDebug()
? 86400
? 5 AssertIsDebug()
: (index == 2)
? 7 * 86400
: 0;
? 86400
: 7 * 86400;
};
const auto sliderCallback = [=](int index) {
state->my = indexToPeriod(index);
state->update();
state->period = indexToPeriod(index);
};
const auto slider = box->addRow(
CreateSliderForTTL(
box,
options | ranges::to_vector,
periodToIndex(ttlPeerPeriod),
periodToIndex(ttlMyPeriod),
options.size() - 1,
periodToIndex(ttlPeriod),
sliderCallback),
{
st::boxRowPadding.left(),
@ -247,72 +240,21 @@ void AutoDeleteSettingsBox(
st::boxRowPadding.right(),
st::boxMediumSkip });
const auto bothSides = userFirstName
? box->addRow(
object_ptr<Ui::Checkbox>(
box,
tr::lng_ttl_also_checkbox(tr::now, lt_user, *userFirstName),
!ttlOneSide),
{
st::boxRowPadding.left(),
0,
st::boxRowPadding.right(),
st::boxMediumSkip })
: nullptr;
const auto description = box->addRow(
object_ptr<Ui::DividerLabel>(
box,
object_ptr<Ui::FlatLabel>(
box,
state->aboutTexts.events() | rpl::flatten_latest(),
std::move(about),
st::boxDividerLabel),
st::ttlDividerLabelPadding),
style::margins());
if (bothSides) {
bothSides->checkedChanges(
) | rpl::start_with_next([=](bool checked) {
state->oneSide = !checked;
state->update();
}, bothSides->lifetime());
}
state->update = [=] {
const auto his = ttlPeerPeriod;
const auto wrap = [](TimeId period) {
Expects(period > 0);
return (period == 5) AssertIsDebug()
? rpl::single(u"5 seconds"_q) AssertIsDebug()
: (period < 3 * 86400)
? tr::lng_ttl_about_duration1()
: tr::lng_ttl_about_duration2();
};
state->aboutTexts.fire(((!state->my && !his) || !userFirstName)
? tr::lng_ttl_edit_about()
: (his > 0 && (!state->my || his < state->my))
? tr::lng_ttl_edit_about_other(
lt_user,
rpl::single(*userFirstName),
lt_duration,
wrap(his))
: state->oneSide
? tr::lng_ttl_edit_about_you_only(lt_duration, wrap(state->my))
: tr::lng_ttl_edit_about_you(
lt_duration,
wrap(state->my),
lt_user,
rpl::single(*userFirstName)));
};
state->update();
box->addButton(tr::lng_settings_save(), [=] {
const auto period = state->my;
const auto oneSide = state->oneSide;
const auto period = state->period;
box->closeBox();
callback(period, oneSide);
callback(period);
});
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
}

View File

@ -13,10 +13,8 @@ namespace Ui {
void AutoDeleteSettingsBox(
not_null<Ui::GenericBox*> box,
TimeId ttlMyPeriod,
TimeId ttlPeerPeriod,
bool ttlOneSide,
std::optional<QString> userFirstName,
Fn<void(TimeId, bool)> callback);
TimeId ttlPeriod,
rpl::producer<QString> about,
Fn<void(TimeId)> callback);
} // namespace Ui