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);
_title->setMaxLength(kMaxGroupChannelTitle);
_title->setInstantReplaces(Ui::InstantReplaces::Default());
_title ->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
_title->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
_title);

View File

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

View File

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

View File

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

View File

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