Support emoji in custom admin badges.

This commit is contained in:
John Preston 2019-07-19 17:05:48 +02:00
parent 6fe36e6534
commit 3f1a2d0b58
5 changed files with 44 additions and 30 deletions

View File

@ -438,7 +438,7 @@ void GroupInfoBox::prepare() {
_initialTitle); _initialTitle);
_title->setMaxLength(kMaxGroupChannelTitle); _title->setMaxLength(kMaxGroupChannelTitle);
_title->setInstantReplaces(Ui::InstantReplaces::Default()); _title->setInstantReplaces(Ui::InstantReplaces::Default());
_title ->setInstantReplacesEnabled(Global::ReplaceEmojiValue()); _title->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(), getDelegate()->outerContainer(),
_title); _title);

View File

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/text_options.h" #include "ui/text_options.h"
#include "ui/special_buttons.h" #include "ui/special_buttons.h"
#include "chat_helpers/emoji_suggestions_widget.h"
#include "info/profile/info_profile_button.h" #include "info/profile/info_profile_button.h"
#include "settings/settings_privacy_security.h" #include "settings/settings_privacy_security.h"
#include "boxes/calendar_box.h" #include "boxes/calendar_box.h"
@ -412,6 +413,11 @@ not_null<Ui::InputField*> EditAdminBox::addRankInput() {
_oldRank), _oldRank),
st::rightsAboutMargin); st::rightsAboutMargin);
result->setMaxLength(kAdminRoleLimit); result->setMaxLength(kAdminRoleLimit);
result->setInstantReplaces(Ui::InstantReplaces::Default());
result->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
result);
addControl( addControl(
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(

View File

@ -421,6 +421,8 @@ HistoryMessage::HistoryMessage(
setGroupId( setGroupId(
MessageGroupId::FromRaw(history->peer->id, groupedId->v)); MessageGroupId::FromRaw(history->peer->id, groupedId->v));
} }
refreshMessageBadge();
} }
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
@ -636,8 +638,11 @@ bool HistoryMessage::updateDependencyItem() {
return true; return true;
} }
void HistoryMessage::updateAdminBadgeState() { void HistoryMessage::refreshMessageBadge() {
_adminBadge = [&] { const auto text = [&] {
if (isDiscussionPost()) {
return tr::lng_channel_badge(tr::now);
}
const auto channel = history()->peer->asMegagroup(); const auto channel = history()->peer->asMegagroup();
const auto user = author()->asUser(); const auto user = author()->asUser();
if (!channel || !user) { if (!channel || !user) {
@ -655,11 +660,19 @@ void HistoryMessage::updateAdminBadgeState() {
? tr::lng_admin_badge(tr::now) ? tr::lng_admin_badge(tr::now)
: i->second; : i->second;
}(); }();
if (text.isEmpty()) {
_messageBadge.clear();
} else {
_messageBadge.setText(
st::defaultTextStyle,
TextUtilities::SingleLine(text));
}
} }
void HistoryMessage::applyGroupAdminChanges( void HistoryMessage::applyGroupAdminChanges(
const base::flat_set<UserId> &changes) { const base::flat_set<UserId> &changes) {
if (!out() && changes.contains(peerToUser(author()->id))) { if (!out() && changes.contains(peerToUser(author()->id))) {
refreshMessageBadge();
history()->owner().requestItemResize(this); history()->owner().requestItemResize(this);
} }
} }
@ -671,10 +684,6 @@ bool HistoryMessage::allowsForward() const {
return !_media || _media->allowsForward(); return !_media || _media->allowsForward();
} }
bool HistoryMessage::hasMessageBadge() const {
return hasAdminBadge() || isDiscussionPost();
}
bool HistoryMessage::isTooOldForEdit(TimeId now) const { bool HistoryMessage::isTooOldForEdit(TimeId now) const {
const auto peer = _history->peer; const auto peer = _history->peer;
if (peer->isSelf()) { if (peer->isSelf()) {

View File

@ -104,13 +104,12 @@ public:
[[nodiscard]] bool allowsEdit(TimeId now) const override; [[nodiscard]] bool allowsEdit(TimeId now) const override;
[[nodiscard]] bool uploading() const; [[nodiscard]] bool uploading() const;
[[nodiscard]] QString adminBadge() const { [[nodiscard]] const Ui::Text::String &messageBadge() const {
return _adminBadge; return _messageBadge;
} }
[[nodiscard]] bool hasAdminBadge() const { [[nodiscard]] bool hasMessageBadge() const {
return !_adminBadge.isEmpty(); return !_messageBadge.isEmpty();
} }
[[nodiscard]] bool hasMessageBadge() const;
void applyGroupAdminChanges( void applyGroupAdminChanges(
const base::flat_set<UserId> &changes) override; const base::flat_set<UserId> &changes) override;
@ -180,9 +179,10 @@ private:
CreateConfig &config, CreateConfig &config,
const MTPDmessageFwdHeader &data); const MTPDmessageFwdHeader &data);
void updateAdminBadgeState(); void refreshMessageBadge();
Ui::Text::String _messageBadge;
QString _adminBadge;
QString _timeText; QString _timeText;
int _timeWidth = 0; int _timeWidth = 0;

View File

@ -123,11 +123,6 @@ int KeyboardStyle::minButtonWidth(
return result; return result;
} }
QString MessageBadgeText(not_null<const HistoryMessage*> message) {
const auto result = message->adminBadge();
return result.isEmpty() ? tr::lng_channel_badge(tr::now) : result;
}
QString FastReplyText() { QString FastReplyText() {
return tr::lng_fast_reply(tr::now); return tr::lng_fast_reply(tr::now);
} }
@ -238,9 +233,6 @@ QSize Message::performCountOptimalSize() {
if (reply) { if (reply) {
reply->updateName(); reply->updateName();
} }
if (displayFromName()) {
item->updateAdminBadgeState();
}
auto mediaDisplayed = false; auto mediaDisplayed = false;
if (media) { if (media) {
@ -306,8 +298,7 @@ QSize Message::performCountOptimalSize() {
? st::msgFont->width(FastReplyText()) ? st::msgFont->width(FastReplyText())
: 0; : 0;
if (item->hasMessageBadge()) { if (item->hasMessageBadge()) {
const auto badgeWidth = st::msgFont->width( const auto badgeWidth = item->messageBadge().maxWidth();
MessageBadgeText(item));
namew += st::msgPadding.right() namew += st::msgPadding.right()
+ std::max(badgeWidth, replyWidth); + std::max(badgeWidth, replyWidth);
} else if (replyWidth) { } else if (replyWidth) {
@ -525,7 +516,7 @@ void Message::paintFromName(
if (displayFromName()) { if (displayFromName()) {
const auto badgeWidth = [&] { const auto badgeWidth = [&] {
if (item->hasMessageBadge()) { if (item->hasMessageBadge()) {
return st::msgFont->width(MessageBadgeText(item)); return item->messageBadge().maxWidth();
} }
return 0; return 0;
}(); }();
@ -577,10 +568,18 @@ void Message::paintFromName(
p.setFont(ClickHandler::showAsActive(_fastReplyLink) p.setFont(ClickHandler::showAsActive(_fastReplyLink)
? st::msgFont->underline() ? st::msgFont->underline()
: st::msgFont); : st::msgFont);
p.drawText( if (replyWidth) {
trect.left() + trect.width() - rightWidth, p.drawText(
trect.top() + st::msgFont->ascent, trect.left() + trect.width() - rightWidth,
replyWidth ? FastReplyText() : MessageBadgeText(item)); trect.top() + st::msgFont->ascent,
FastReplyText());
} else {
item->messageBadge().draw(
p,
trect.left() + trect.width() - rightWidth,
trect.top(),
rightWidth);
}
} }
trect.setY(trect.y() + st::msgNameFont->height); trect.setY(trect.y() + st::msgNameFont->height);
} }
@ -1551,7 +1550,7 @@ void Message::fromNameUpdated(int width) const {
? st::msgFont->width(FastReplyText()) ? st::msgFont->width(FastReplyText())
: 0; : 0;
if (item->hasMessageBadge()) { if (item->hasMessageBadge()) {
const auto badgeWidth = st::msgFont->width(MessageBadgeText(item)); const auto badgeWidth = item->messageBadge().maxWidth();
width -= st::msgPadding.right() + std::max(badgeWidth, replyWidth); width -= st::msgPadding.right() + std::max(badgeWidth, replyWidth);
} else if (replyWidth) { } else if (replyWidth) {
width -= st::msgPadding.right() + replyWidth; width -= st::msgPadding.right() + replyWidth;