[Improvement] Show time of service messages

This commit is contained in:
Eric Kotato 2022-09-11 05:08:19 +03:00 committed by Eric Kotato
parent 6ee5d55e73
commit 0fe3f6b35e
5 changed files with 52 additions and 16 deletions

View file

@ -32,7 +32,10 @@ constexpr auto kMessagesPerPage = 50;
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MessageFlag::FakeHistoryItem, MessageFlag::FakeHistoryItem,
date, date,
HistoryService::PreparedText{ { .text = text } }); HistoryService::PreparedText{ { .text = text } },
PeerId(0),
nullptr,
false);
} }
} // namespace } // namespace
@ -287,6 +290,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

@ -736,10 +736,11 @@ void GenerateItems(
const auto fromLink = from->createOpenLink(); const auto fromLink = from->createOpenLink();
const auto fromLinkText = Ui::Text::Link(fromName, QString()); const auto fromLinkText = Ui::Text::Link(fromName, QString());
const auto addSimpleServiceMessage = [&]( auto addSimpleServiceMessage = [&](
const TextWithEntities &text, const TextWithEntities &text,
PhotoData *photo = nullptr) { PhotoData *photo = nullptr,
auto message = HistoryService::PreparedText{ text }; bool showTime = true) {
auto message = HistoryService::PreparedText { text };
message.links.push_back(fromLink); message.links.push_back(fromLink);
addPart(history->makeServiceMessage( addPart(history->makeServiceMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
@ -747,7 +748,8 @@ void GenerateItems(
date, date,
message, message,
peerToUser(from->id), peerToUser(from->id),
photo)); photo,
showTime));
}; };
const auto createChangeTitle = [&](const LogTitle &action) { const auto createChangeTitle = [&](const LogTitle &action) {
@ -798,7 +800,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, Ui::Text::WithEntities); )(tr::now, lt_from, fromLinkText, Ui::Text::WithEntities);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
const auto body = makeSimpleTextMessage( const auto body = makeSimpleTextMessage(
PrepareText(newValue, QString())); PrepareText(newValue, QString()));
@ -823,7 +825,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, Ui::Text::WithEntities); )(tr::now, lt_from, fromLinkText, Ui::Text::WithEntities);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
const auto body = makeSimpleTextMessage(newValue.isEmpty() const auto body = makeSimpleTextMessage(newValue.isEmpty()
? TextWithEntities() ? TextWithEntities()
@ -899,7 +901,7 @@ void GenerateItems(
lt_from, lt_from,
fromLinkText, fromLinkText,
Ui::Text::WithEntities); Ui::Text::WithEntities);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
const auto detachExistingItem = false; const auto detachExistingItem = false;
addPart( addPart(
@ -951,7 +953,7 @@ void GenerateItems(
lt_from, lt_from,
fromLinkText, fromLinkText,
Ui::Text::WithEntities); Ui::Text::WithEntities);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
const auto detachExistingItem = false; const auto detachExistingItem = false;
const auto body = history->createItem( const auto body = history->createItem(
@ -980,7 +982,7 @@ void GenerateItems(
lt_from, lt_from,
fromLinkText, fromLinkText,
Ui::Text::WithEntities); Ui::Text::WithEntities);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
const auto detachExistingItem = false; const auto detachExistingItem = false;
addPart( addPart(
@ -1114,7 +1116,7 @@ void GenerateItems(
lt_from, lt_from,
fromLinkText, fromLinkText,
Ui::Text::WithEntities); Ui::Text::WithEntities);
addSimpleServiceMessage(text); addSimpleServiceMessage(text, nullptr, false);
const auto detachExistingItem = false; const auto detachExistingItem = false;
addPart( addPart(

View file

@ -1250,7 +1250,7 @@ bool HistoryItem::isEmpty() const {
TextWithEntities HistoryItem::notificationText() const { TextWithEntities HistoryItem::notificationText() const {
const auto result = [&] { const auto result = [&] {
if (_media && !isService()) { if (_media/* && !isService()*/) {
return _media->notificationText(); return _media->notificationText();
} else if (!emptyText()) { } else if (!emptyText()) {
return _text.toTextWithEntities(); return _text.toTextWithEntities();

View file

@ -44,13 +44,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "ui/text/text_options.h" #include "ui/text/text_options.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/text/text_entity.h"
#include "base/unixtime.h"
namespace { namespace {
constexpr auto kNotificationTextLimit = 255;
constexpr auto kPinnedMessageTextLimit = 16; constexpr auto kPinnedMessageTextLimit = 16;
using ItemPreview = HistoryView::ItemPreview; using ItemPreview = HistoryView::ItemPreview;
QString GenerateServiceTime(TimeId date) {
if (date > 0) {
return qs(" · ") + base::unixtime::parse(date).toString(cTimeFormat());
}
return QString();
}
[[nodiscard]] bool PeerCallKnown(not_null<PeerData*> peer) { [[nodiscard]] bool PeerCallKnown(not_null<PeerData*> peer) {
if (peer->groupCall() != nullptr) { if (peer->groupCall() != nullptr) {
return true; return true;
@ -108,6 +118,7 @@ using ItemPreview = HistoryView::ItemPreview;
} // 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;
@ -1221,8 +1232,10 @@ HistoryService::HistoryService(
TimeId date, TimeId date,
const PreparedText &message, const PreparedText &message,
PeerId from, PeerId from,
PhotoData *photo) PhotoData *photo,
bool showTime)
: HistoryItem(history, id, flags, date, from) { : HistoryItem(history, id, flags, date, from) {
setNeedTime(showTime);
setServiceText(message); setServiceText(message);
if (photo) { if (photo) {
_media = std::make_unique<Data::MediaPhoto>( _media = std::make_unique<Data::MediaPhoto>(
@ -1255,7 +1268,7 @@ ItemPreview HistoryService::toPreview(ToPreviewOptions options) const {
} }
TextWithEntities HistoryService::inReplyText() const { TextWithEntities HistoryService::inReplyText() const {
auto result = HistoryService::notificationText(); auto result = TextWithEntities{ notificationText() };
const auto &name = author()->name(); const auto &name = author()->name();
TextUtilities::Trim(result); TextUtilities::Trim(result);
if (result.text.startsWith(name)) { if (result.text.startsWith(name)) {
@ -1284,11 +1297,18 @@ void HistoryService::setServiceText(const PreparedText &prepared) {
.session = &history()->session(), .session = &history()->session(),
.customEmojiRepaint = [=] { customEmojiRepaint(); }, .customEmojiRepaint = [=] { customEmojiRepaint(); },
}; };
auto preparedText = prepared.text;
_text.setMarkedText( _text.setMarkedText(
st::serviceTextStyle, st::serviceTextStyle,
prepared.text, (needTime() && !prepared.text.empty()
? preparedText.append(GenerateServiceTime(date()))
: preparedText),
Ui::ItemTextServiceOptions(), Ui::ItemTextServiceOptions(),
context); context);
_cleanText.setText(
st::serviceTextStyle,
prepared.text.text,
Ui::ItemTextServiceOptions());
HistoryView::FillTextWithAnimatedSpoilers(_text); HistoryView::FillTextWithAnimatedSpoilers(_text);
auto linkIndex = 0; auto linkIndex = 0;
for (const auto &link : prepared.links) { for (const auto &link : prepared.links) {

View file

@ -97,7 +97,8 @@ public:
TimeId date, TimeId date,
const PreparedText &message, const PreparedText &message,
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 {
@ -132,6 +133,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;
};
void hideSpoilers() override; void hideSpoilers() override;
@ -187,6 +195,8 @@ private:
friend class HistoryView::Service; friend class HistoryView::Service;
Ui::Text::String _cleanText;
bool _needTime = true;
}; };
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage( [[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(