Show 'channel' badge for discussed messages.

This commit is contained in:
John Preston 2019-05-24 14:13:16 +02:00
parent 7fbec0dbca
commit 8aaaef3ff4
4 changed files with 41 additions and 30 deletions

View File

@ -1070,6 +1070,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_edited" = "edited"; "lng_edited" = "edited";
"lng_edited_date" = "Edited: {date}"; "lng_edited_date" = "Edited: {date}";
"lng_admin_badge" = "admin"; "lng_admin_badge" = "admin";
"lng_channel_badge" = "channel";
"lng_fast_reply" = "Reply"; "lng_fast_reply" = "Reply";
"lng_cancel_edit_post_sure" = "Cancel editing?"; "lng_cancel_edit_post_sure" = "Cancel editing?";
"lng_cancel_edit_post_yes" = "Yes"; "lng_cancel_edit_post_yes" = "Yes";

View File

@ -610,6 +610,11 @@ bool HistoryMessage::allowsForward() const {
return !_media || _media->allowsForward(); return !_media || _media->allowsForward();
} }
bool HistoryMessage::hasMessageBadge() const {
return hasAdminBadge()
|| (displayForwardedAsOriginal() && !history()->peer->isSelf());
}
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

@ -90,13 +90,18 @@ public:
void refreshSentMedia(const MTPMessageMedia *media); void refreshSentMedia(const MTPMessageMedia *media);
void returnSavedMedia() override; void returnSavedMedia() override;
void setMedia(const MTPMessageMedia &media); void setMedia(const MTPMessageMedia &media);
static std::unique_ptr<Data::Media> CreateMedia( [[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
not_null<HistoryMessage*> item, not_null<HistoryMessage*> item,
const MTPMessageMedia &media); const MTPMessageMedia &media);
bool allowsForward() const override; [[nodiscard]] bool allowsForward() const override;
bool allowsEdit(TimeId now) const override; [[nodiscard]] bool allowsEdit(TimeId now) const override;
bool uploading() const; [[nodiscard]] bool uploading() const;
[[nodiscard]] bool hasAdminBadge() const {
return _flags & MTPDmessage_ClientFlag::f_has_admin_badge;
}
[[nodiscard]] bool hasMessageBadge() const;
void applyGroupAdminChanges( void applyGroupAdminChanges(
const base::flat_map<UserId, bool> &changes) override; const base::flat_map<UserId, bool> &changes) override;
@ -106,7 +111,7 @@ public:
void dependencyItemRemoved(HistoryItem *dependency) override; void dependencyItemRemoved(HistoryItem *dependency) override;
QString notificationHeader() const override; [[nodiscard]] QString notificationHeader() const override;
void applyEdition(const MTPDmessage &message) override; void applyEdition(const MTPDmessage &message) override;
void applyEdition(const MTPDmessageService &message) override; void applyEdition(const MTPDmessageService &message) override;
@ -118,40 +123,38 @@ public:
void addToUnreadMentions(UnreadMentionType type) override; void addToUnreadMentions(UnreadMentionType type) override;
void eraseFromUnreadMentions() override; void eraseFromUnreadMentions() override;
Storage::SharedMediaTypesMask sharedMediaTypes() const override; [[nodiscard]] Storage::SharedMediaTypesMask sharedMediaTypes() const override;
void setText(const TextWithEntities &textWithEntities) override; void setText(const TextWithEntities &textWithEntities) override;
TextWithEntities originalText() const override; [[nodiscard]] TextWithEntities originalText() const override;
TextForMimeData clipboardText() const override; [[nodiscard]] TextForMimeData clipboardText() const override;
bool textHasLinks() const override; [[nodiscard]] bool textHasLinks() const override;
int viewsCount() const override; [[nodiscard]] int viewsCount() const override;
PeerData *displayFrom() const; [[nodiscard]] PeerData *displayFrom() const;
bool updateDependencyItem() override; bool updateDependencyItem() override;
MsgId dependencyMsgId() const override { [[nodiscard]] MsgId dependencyMsgId() const override {
return replyToId(); return replyToId();
} }
bool displayForwardedAsOriginal() const; [[nodiscard]] bool displayForwardedAsOriginal() const;
HistoryMessage *toHistoryMessage() override { // dynamic_cast optimize // dynamic_cast optimization.
[[nodiscard]] HistoryMessage *toHistoryMessage() override {
return this; return this;
} }
const HistoryMessage *toHistoryMessage() const override { // dynamic_cast optimize [[nodiscard]] const HistoryMessage *toHistoryMessage() const override {
return this; return this;
} }
std::unique_ptr<HistoryView::Element> createView( [[nodiscard]] std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate) override; not_null<HistoryView::ElementDelegate*> delegate) override;
~HistoryMessage(); ~HistoryMessage();
private: private:
void setEmptyText(); void setEmptyText();
bool hasAdminBadge() const { [[nodiscard]] bool isTooOldForEdit(TimeId now) const;
return _flags & MTPDmessage_ClientFlag::f_has_admin_badge; [[nodiscard]] bool isLegacyMessage() const {
}
bool isTooOldForEdit(TimeId now) const;
bool isLegacyMessage() const {
return _flags & MTPDmessage::Flag::f_legacy; return _flags & MTPDmessage::Flag::f_legacy;
} }

View File

@ -121,8 +121,10 @@ int KeyboardStyle::minButtonWidth(
return result; return result;
} }
QString AdminBadgeText() { QString MessageBadgeText(not_null<const HistoryMessage*> message) {
return lang(lng_admin_badge); return lang(message->hasAdminBadge()
? lng_admin_badge
: lng_channel_badge);
} }
QString FastReplyText() { QString FastReplyText() {
@ -302,9 +304,9 @@ QSize Message::performCountOptimalSize() {
const auto replyWidth = hasFastReply() const auto replyWidth = hasFastReply()
? st::msgFont->width(FastReplyText()) ? st::msgFont->width(FastReplyText())
: 0; : 0;
if (item->hasAdminBadge()) { if (item->hasMessageBadge()) {
const auto badgeWidth = st::msgFont->width( const auto badgeWidth = st::msgFont->width(
AdminBadgeText()); MessageBadgeText(item));
namew += st::msgPadding.right() namew += st::msgPadding.right()
+ std::max(badgeWidth, replyWidth); + std::max(badgeWidth, replyWidth);
} else if (replyWidth) { } else if (replyWidth) {
@ -521,8 +523,8 @@ void Message::paintFromName(
const auto item = message(); const auto item = message();
if (displayFromName()) { if (displayFromName()) {
const auto badgeWidth = [&] { const auto badgeWidth = [&] {
if (item->hasAdminBadge()) { if (item->hasMessageBadge()) {
return st::msgFont->width(AdminBadgeText()); return st::msgFont->width(MessageBadgeText(item));
} }
return 0; return 0;
}(); }();
@ -577,7 +579,7 @@ void Message::paintFromName(
p.drawText( p.drawText(
trect.left() + trect.width() - rightWidth, trect.left() + trect.width() - rightWidth,
trect.top() + st::msgFont->ascent, trect.top() + st::msgFont->ascent,
replyWidth ? FastReplyText() : AdminBadgeText()); replyWidth ? FastReplyText() : MessageBadgeText(item));
} }
trect.setY(trect.y() + st::msgNameFont->height); trect.setY(trect.y() + st::msgNameFont->height);
} }
@ -1541,8 +1543,8 @@ void Message::fromNameUpdated(int width) const {
const auto replyWidth = hasFastReply() const auto replyWidth = hasFastReply()
? st::msgFont->width(FastReplyText()) ? st::msgFont->width(FastReplyText())
: 0; : 0;
if (item->hasAdminBadge()) { if (item->hasMessageBadge()) {
const auto badgeWidth = st::msgFont->width(AdminBadgeText()); const auto badgeWidth = st::msgFont->width(MessageBadgeText(item));
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;