[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(),
MessageFlag::FakeHistoryItem,
date,
HistoryService::PreparedText{ { .text = text } });
HistoryService::PreparedText{ { .text = text } },
PeerId(0),
nullptr,
false);
}
} // namespace
@ -287,6 +290,7 @@ void RepliesList::injectRootDivider(
text());
} else if (_dividerWithComments != withComments) {
_dividerWithComments = withComments;
_divider->setNeedTime(false);
_divider->setServiceText(HistoryService::PreparedText{ { text() } });
}
slice->ids.push_back(_divider->fullId());

View file

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

View file

@ -1250,7 +1250,7 @@ bool HistoryItem::isEmpty() const {
TextWithEntities HistoryItem::notificationText() const {
const auto result = [&] {
if (_media && !isService()) {
if (_media/* && !isService()*/) {
return _media->notificationText();
} else if (!emptyText()) {
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/text_options.h"
#include "ui/text/text_utilities.h"
#include "ui/text/text_entity.h"
#include "base/unixtime.h"
namespace {
constexpr auto kNotificationTextLimit = 255;
constexpr auto kPinnedMessageTextLimit = 16;
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) {
if (peer->groupCall() != nullptr) {
return true;
@ -108,6 +118,7 @@ using ItemPreview = HistoryView::ItemPreview;
} // namespace
void HistoryService::setMessageByAction(const MTPmessageAction &action) {
setNeedTime(true);
auto prepareChatAddUserText = [this](const MTPDmessageActionChatAddUser &action) {
auto result = PreparedText{};
auto &users = action.vusers().v;
@ -1221,8 +1232,10 @@ HistoryService::HistoryService(
TimeId date,
const PreparedText &message,
PeerId from,
PhotoData *photo)
PhotoData *photo,
bool showTime)
: HistoryItem(history, id, flags, date, from) {
setNeedTime(showTime);
setServiceText(message);
if (photo) {
_media = std::make_unique<Data::MediaPhoto>(
@ -1255,7 +1268,7 @@ ItemPreview HistoryService::toPreview(ToPreviewOptions options) const {
}
TextWithEntities HistoryService::inReplyText() const {
auto result = HistoryService::notificationText();
auto result = TextWithEntities{ notificationText() };
const auto &name = author()->name();
TextUtilities::Trim(result);
if (result.text.startsWith(name)) {
@ -1284,11 +1297,18 @@ void HistoryService::setServiceText(const PreparedText &prepared) {
.session = &history()->session(),
.customEmojiRepaint = [=] { customEmojiRepaint(); },
};
auto preparedText = prepared.text;
_text.setMarkedText(
st::serviceTextStyle,
prepared.text,
(needTime() && !prepared.text.empty()
? preparedText.append(GenerateServiceTime(date()))
: preparedText),
Ui::ItemTextServiceOptions(),
context);
_cleanText.setText(
st::serviceTextStyle,
prepared.text.text,
Ui::ItemTextServiceOptions());
HistoryView::FillTextWithAnimatedSpoilers(_text);
auto linkIndex = 0;
for (const auto &link : prepared.links) {

View file

@ -97,7 +97,8 @@ public:
TimeId date,
const PreparedText &message,
PeerId from = 0,
PhotoData *photo = nullptr);
PhotoData *photo = nullptr,
bool showTime = true);
bool updateDependencyItem() override;
MsgId dependencyMsgId() const override {
@ -132,6 +133,13 @@ public:
HistoryView::Element *replacing = nullptr) override;
void setServiceText(const PreparedText &prepared);
void setNeedTime(bool need) {
_needTime = need;
};
bool needTime() {
return _needTime;
};
void hideSpoilers() override;
@ -187,6 +195,8 @@ private:
friend class HistoryView::Service;
Ui::Text::String _cleanText;
bool _needTime = true;
};
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(