[Improvement] Show time of service messages

This commit is contained in:
Eric Kotato 2022-09-11 05:08:19 +03:00
parent 041f3f4224
commit 7b55777eb0
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

@ -700,10 +700,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(),
@ -711,7 +712,8 @@ void GenerateItems(
date,
message,
peerToUser(from->id),
photo));
photo,
showTime));
};
const auto createChangeTitle = [&](const LogTitle &action) {
@ -762,7 +764,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()));
@ -787,7 +789,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()
@ -863,7 +865,7 @@ void GenerateItems(
lt_from,
fromLinkText,
Ui::Text::WithEntities);
addSimpleServiceMessage(text);
addSimpleServiceMessage(text, nullptr, false);
const auto detachExistingItem = false;
addPart(
@ -898,7 +900,7 @@ void GenerateItems(
lt_from,
fromLinkText,
Ui::Text::WithEntities);
addSimpleServiceMessage(text);
addSimpleServiceMessage(text, nullptr, false);
auto oldValue = ExtractEditedText(
session,
@ -930,7 +932,7 @@ void GenerateItems(
lt_from,
fromLinkText,
Ui::Text::WithEntities);
addSimpleServiceMessage(text);
addSimpleServiceMessage(text, nullptr, false);
const auto detachExistingItem = false;
addPart(
@ -1063,7 +1065,7 @@ void GenerateItems(
lt_from,
fromLinkText,
Ui::Text::WithEntities);
addSimpleServiceMessage(text);
addSimpleServiceMessage(text, nullptr, false);
const auto detachExistingItem = false;
addPart(

View file

@ -1226,7 +1226,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

@ -41,13 +41,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;
@ -105,6 +115,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;
@ -1160,8 +1171,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>(
@ -1194,7 +1207,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)) {
@ -1219,9 +1232,16 @@ ClickHandlerPtr HistoryService::fromLink() const {
}
void HistoryService::setServiceText(const PreparedText &prepared) {
auto preparedText = prepared.text;
_text.setMarkedText(
st::serviceTextStyle,
prepared.text,
(needTime() && !prepared.text.empty()
? preparedText.append(GenerateServiceTime(date()))
: preparedText),
Ui::ItemTextServiceOptions());
_cleanText.setText(
st::serviceTextStyle,
prepared.text.text,
Ui::ItemTextServiceOptions());
HistoryView::FillTextWithAnimatedSpoilers(_text);
auto linkIndex = 0;

View file

@ -84,7 +84,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 {
@ -119,6 +120,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;
@ -172,6 +180,8 @@ private:
friend class HistoryView::Service;
Ui::Text::String _cleanText;
bool _needTime = true;
};
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(