Force non-empty text in message bubbles.

This commit is contained in:
John Preston 2020-05-04 17:03:33 +04:00
parent a5977f5f7a
commit 038d8f1781
1 changed files with 24 additions and 20 deletions

View File

@ -53,7 +53,7 @@ namespace {
constexpr auto kPinnedMessageTextLimit = 16; constexpr auto kPinnedMessageTextLimit = 16;
MTPDmessage::Flags NewForwardedFlags( [[nodiscard]] MTPDmessage::Flags NewForwardedFlags(
not_null<PeerData*> peer, not_null<PeerData*> peer,
UserId from, UserId from,
not_null<HistoryMessage*> fwd) { not_null<HistoryMessage*> fwd) {
@ -82,11 +82,11 @@ MTPDmessage::Flags NewForwardedFlags(
return result; return result;
} }
MTPDmessage_ClientFlags NewForwardedClientFlags() { [[nodiscard]] MTPDmessage_ClientFlags NewForwardedClientFlags() {
return NewMessageClientFlags(); return NewMessageClientFlags();
} }
bool CopyMarkupToForward(not_null<const HistoryItem*> item) { [[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
auto mediaOriginal = item->media(); auto mediaOriginal = item->media();
if (mediaOriginal && mediaOriginal->game()) { if (mediaOriginal && mediaOriginal->game()) {
// Copy inline keyboard when forwarding messages with a game. // Copy inline keyboard when forwarding messages with a game.
@ -111,7 +111,7 @@ bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
return true; return true;
} }
bool HasInlineItems(const HistoryItemsList &items) { [[nodiscard]] bool HasInlineItems(const HistoryItemsList &items) {
for (const auto item : items) { for (const auto item : items) {
if (item->viaBot()) { if (item->viaBot()) {
return true; return true;
@ -120,6 +120,14 @@ bool HasInlineItems(const HistoryItemsList &items) {
return false; return false;
} }
[[nodiscard]] TextWithEntities EnsureNonEmpty(
const TextWithEntities &text = TextWithEntities()) {
if (!text.text.isEmpty()) {
return text;
}
return { QString::fromUtf8(":-("), EntitiesInText() };
}
} // namespace } // namespace
QString GetErrorTextForSending( QString GetErrorTextForSending(
@ -448,10 +456,11 @@ HistoryMessage::HistoryMessage(
if (const auto media = data.vmedia()) { if (const auto media = data.vmedia()) {
setMedia(*media); setMedia(*media);
} }
setText({ const auto textWithEntities = TextWithEntities{
TextUtilities::Clean(qs(data.vmessage())), TextUtilities::Clean(qs(data.vmessage())),
Api::EntitiesFromMTP(data.ventities().value_or_empty()) Api::EntitiesFromMTP(data.ventities().value_or_empty())
}); };
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
if (const auto groupedId = data.vgrouped_id()) { if (const auto groupedId = data.vgrouped_id()) {
setGroupId( setGroupId(
MessageGroupId::FromRaw(history->peer->id, groupedId->v)); MessageGroupId::FromRaw(history->peer->id, groupedId->v));
@ -477,17 +486,12 @@ HistoryMessage::HistoryMessage(
createComponents(config); createComponents(config);
switch (data.vaction().type()) { data.vaction().match([&](const MTPDmessageActionPhoneCall &data) {
case mtpc_messageActionPhoneCall: { _media = std::make_unique<Data::MediaCall>(this, data);
_media = std::make_unique<Data::MediaCall>( setEmptyText();
this, }, [](const auto &) {
data.vaction().c_messageActionPhoneCall()); Unexpected("Service message action type in HistoryMessage.");
} break; });
default: Unexpected("Service message action type in HistoryMessage.");
}
setText(TextWithEntities {});
} }
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
@ -676,7 +680,7 @@ HistoryMessage::HistoryMessage(
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup); createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
_media = std::make_unique<Data::MediaGame>(this, game); _media = std::make_unique<Data::MediaGame>(this, game);
setText(TextWithEntities()); setEmptyText();
} }
void HistoryMessage::createComponentsHelper( void HistoryMessage::createComponentsHelper(
@ -1075,7 +1079,7 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
refreshMedia(message.vmedia()); refreshMedia(message.vmedia());
} }
setViewsCount(message.vviews().value_or(-1)); setViewsCount(message.vviews().value_or(-1));
setText(textWithEntities); setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
finishEdition(keyboardTop); finishEdition(keyboardTop);
} }
@ -1220,7 +1224,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
// just replace it with something so that UI won't look buggy. // just replace it with something so that UI won't look buggy.
_text.setMarkedText( _text.setMarkedText(
st::messageTextStyle, st::messageTextStyle,
{ QString::fromUtf8(":-("), EntitiesInText() }, EnsureNonEmpty(),
Ui::ItemTextOptions(this)); Ui::ItemTextOptions(this));
} else if (!_media) { } else if (!_media) {
checkIsolatedEmoji(); checkIsolatedEmoji();