Don't show time for service messages with additional data

This commit is contained in:
Eric Kotato 2020-12-27 22:10:22 +03:00
parent 22f2fa2f19
commit c528820713
4 changed files with 30 additions and 12 deletions

View file

@ -32,7 +32,11 @@ constexpr auto kMessagesPerPage = 50;
history->session().data().nextNonHistoryEntryId(), history->session().data().nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_fake_history_item, MTPDmessage_ClientFlag::f_fake_history_item,
date, date,
HistoryService::PreparedText{ text }); HistoryService::PreparedText{ text },
MTPDmessage::Flags(0),
PeerId(0),
nullptr,
false);
} }
} // namespace } // namespace
@ -237,6 +241,7 @@ void RepliesList::injectRootDivider(
text()); text());
} else if (_dividerWithComments != withComments) { } else if (_dividerWithComments != withComments) {
_dividerWithComments = withComments; _dividerWithComments = withComments;
_divider->setNeedTime(false);
_divider->setServiceText(HistoryService::PreparedText{ text() }); _divider->setServiceText(HistoryService::PreparedText{ text() });
} }
slice->ids.push_back(_divider->fullId()); slice->ids.push_back(_divider->fullId());

View file

@ -398,7 +398,7 @@ void GenerateItems(
const auto fromLink = from->createOpenLink(); const auto fromLink = from->createOpenLink();
const auto fromLinkText = textcmdLink(1, fromName); const auto fromLinkText = textcmdLink(1, fromName);
auto addSimpleServiceMessage = [&](const QString &text, PhotoData *photo = nullptr) { auto addSimpleServiceMessage = [&](const QString &text, PhotoData *photo = nullptr, bool showTime = true) {
auto message = HistoryService::PreparedText { text }; auto message = HistoryService::PreparedText { text };
message.links.push_back(fromLink); message.links.push_back(fromLink);
addPart(history->makeServiceMessage( addPart(history->makeServiceMessage(
@ -408,7 +408,8 @@ void GenerateItems(
message, message,
MTPDmessage::Flags(0), MTPDmessage::Flags(0),
peerToUser(from->id), peerToUser(from->id),
photo)); photo,
showTime));
}; };
auto createChangeTitle = [&](const MTPDchannelAdminLogEventActionChangeTitle &action) { auto createChangeTitle = [&](const MTPDchannelAdminLogEventActionChangeTitle &action) {
@ -434,7 +435,7 @@ void GenerateItems(
? tr::lng_admin_log_removed_description_channel ? tr::lng_admin_log_removed_description_channel
: tr::lng_admin_log_changed_description_channel) : tr::lng_admin_log_changed_description_channel)
)(tr::now, lt_from, fromLinkText); )(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
auto bodyFlags = Flag::f_entities | Flag::f_from_id; auto bodyFlags = Flag::f_entities | Flag::f_from_id;
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
@ -469,7 +470,7 @@ void GenerateItems(
? tr::lng_admin_log_removed_link_channel ? tr::lng_admin_log_removed_link_channel
: tr::lng_admin_log_changed_link_channel) : tr::lng_admin_log_changed_link_channel)
)(tr::now, lt_from, fromLinkText); )(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
auto bodyFlags = Flag::f_entities | Flag::f_from_id; auto bodyFlags = Flag::f_entities | Flag::f_from_id;
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
@ -542,7 +543,7 @@ void GenerateItems(
auto text = (pinned auto text = (pinned
? tr::lng_admin_log_pinned_message ? tr::lng_admin_log_pinned_message
: tr::lng_admin_log_unpinned_message)(tr::now, lt_from, fromLinkText); : tr::lng_admin_log_unpinned_message)(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
auto detachExistingItem = false; auto detachExistingItem = false;
addPart(history->createItem( addPart(history->createItem(
@ -569,7 +570,7 @@ void GenerateItems(
tr::now, tr::now,
lt_from, lt_from,
fromLinkText); fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
auto oldValue = ExtractEditedText(session, action.vprev_message()); auto oldValue = ExtractEditedText(session, action.vprev_message());
auto detachExistingItem = false; auto detachExistingItem = false;
@ -595,7 +596,7 @@ void GenerateItems(
auto createDeleteMessage = [&](const MTPDchannelAdminLogEventActionDeleteMessage &action) { auto createDeleteMessage = [&](const MTPDchannelAdminLogEventActionDeleteMessage &action) {
auto text = tr::lng_admin_log_deleted_message(tr::now, lt_from, fromLinkText); auto text = tr::lng_admin_log_deleted_message(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
auto detachExistingItem = false; auto detachExistingItem = false;
addPart(history->createItem( addPart(history->createItem(
@ -737,7 +738,7 @@ void GenerateItems(
auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) { auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) {
auto text = tr::lng_admin_log_stopped_poll(tr::now, lt_from, fromLinkText); auto text = tr::lng_admin_log_stopped_poll(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
auto detachExistingItem = false; auto detachExistingItem = false;
addPart(history->createItem( addPart(history->createItem(

View file

@ -115,6 +115,7 @@ QString GenerateServiceTime(TimeId date) {
} // namespace } // namespace
void HistoryService::setMessageByAction(const MTPmessageAction &action) { void HistoryService::setMessageByAction(const MTPmessageAction &action) {
setNeedTime(true);
auto prepareChatAddUserText = [this](const MTPDmessageActionChatAddUser &action) { auto prepareChatAddUserText = [this](const MTPDmessageActionChatAddUser &action) {
auto result = PreparedText{}; auto result = PreparedText{};
auto &users = action.vusers().v; auto &users = action.vusers().v;
@ -781,8 +782,10 @@ HistoryService::HistoryService(
const PreparedText &message, const PreparedText &message,
MTPDmessage::Flags flags, MTPDmessage::Flags flags,
PeerId from, PeerId from,
PhotoData *photo) PhotoData *photo,
bool showTime)
: HistoryItem(history, id, flags, clientFlags, date, from) { : HistoryItem(history, id, flags, clientFlags, date, from) {
setNeedTime(showTime);
setServiceText(message); setServiceText(message);
if (photo) { if (photo) {
_media = std::make_unique<Data::MediaPhoto>( _media = std::make_unique<Data::MediaPhoto>(
@ -837,7 +840,7 @@ void HistoryService::setServiceText(const PreparedText &prepared) {
Ui::ItemTextServiceOptions()); Ui::ItemTextServiceOptions());
_postfixedText.setText( _postfixedText.setText(
st::serviceTextStyle, st::serviceTextStyle,
prepared.text + GenerateServiceTime(date()), (needTime() ? prepared.text + GenerateServiceTime(date()) : prepared.text),
Ui::ItemTextServiceOptions()); Ui::ItemTextServiceOptions());
auto linkIndex = 0; auto linkIndex = 0;
for_const (auto &link, prepared.links) { for_const (auto &link, prepared.links) {

View file

@ -80,7 +80,8 @@ public:
const PreparedText &message, const PreparedText &message,
MTPDmessage::Flags flags = 0, MTPDmessage::Flags flags = 0,
PeerId from = 0, PeerId from = 0,
PhotoData *photo = nullptr); PhotoData *photo = nullptr,
bool showTime = true);
bool updateDependencyItem() override; bool updateDependencyItem() override;
MsgId dependencyMsgId() const override { MsgId dependencyMsgId() const override {
@ -113,6 +114,13 @@ public:
HistoryView::Element *replacing = nullptr) override; HistoryView::Element *replacing = nullptr) override;
void setServiceText(const PreparedText &prepared); void setServiceText(const PreparedText &prepared);
void setNeedTime(bool need) {
_needTime = need;
};
bool needTime() {
return _needTime;
};
~HistoryService(); ~HistoryService();
@ -165,6 +173,7 @@ private:
friend class HistoryView::Service; friend class HistoryView::Service;
Ui::Text::String _postfixedText; Ui::Text::String _postfixedText;
bool _needTime = true;
}; };