Skip to content

Commit

Permalink
Added userpic views to headers of forwarded messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd authored and john-preston committed May 28, 2024
1 parent 470b3a2 commit 8a6b167
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
41 changes: 29 additions & 12 deletions Telegram/SourceFiles/history/history_item_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,11 @@ bool HiddenSenderInfo::paintCustomUserpic(
return valid;
}

void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
void HistoryMessageForwarded::create(
const HistoryMessageVia *via,
not_null<const HistoryItem*> item) const {
auto phrase = TextWithEntities();
auto context = Core::MarkedTextContext{};
const auto fromChannel = originalSender
&& originalSender->isChannel()
&& !originalSender->isMegagroup();
Expand All @@ -193,16 +196,27 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
? originalSender->name()
: originalHiddenSenderInfo->name)
};
if (originalSender) {
context.session = &originalSender->owner().session();
context.customEmojiRepaint = [=] {
originalSender->owner().requestItemRepaint(item);
};
phrase = Ui::Text::SingleCustomEmoji(
context.session->data().customEmojiManager().peerUserpicEmojiData(
originalSender,
st::fwdTextUserpicPadding));
}
if (!originalPostAuthor.isEmpty()) {
phrase = tr::lng_forwarded_signed(
tr::now,
lt_channel,
name,
lt_user,
{ .text = originalPostAuthor },
Ui::Text::WithEntities);
phrase.append(
tr::lng_forwarded_signed(
tr::now,
lt_channel,
name,
lt_user,
{ .text = originalPostAuthor },
Ui::Text::WithEntities));
} else {
phrase = name;
phrase.append(name);
}
if (story) {
phrase = tr::lng_forwarded_story(
Expand Down Expand Up @@ -248,18 +262,21 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
: tr::lng_forwarded_psa_default)(
tr::now,
lt_channel,
Ui::Text::Link(phrase.text, QString()), // Link 1.
Ui::Text::Wrapped(
phrase,
EntityType::CustomUrl,
QString()), // Link 1.
Ui::Text::WithEntities);
}
} else {
phrase = tr::lng_forwarded(
tr::now,
lt_user,
Ui::Text::Link(phrase.text, QString()), // Link 1.
Ui::Text::Wrapped(phrase, EntityType::CustomUrl, QString()), // Link 1.
Ui::Text::WithEntities);
}
}
text.setMarkedText(st::fwdTextStyle, phrase);
text.setMarkedText(st::fwdTextStyle, phrase, kMarkupTextOptions, context);

text.setLink(1, fromChannel
? JumpToMessageClickHandler(originalSender, originalId)
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/history/history_item_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ class HiddenSenderInfo {
};

struct HistoryMessageForwarded : public RuntimeComponent<HistoryMessageForwarded, HistoryItem> {
void create(const HistoryMessageVia *via) const;
void create(
const HistoryMessageVia *via,
not_null<const HistoryItem*> item) const;

[[nodiscard]] bool forwardOfForward() const {
return savedFromSender || savedFromHiddenSenderInfo;
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/history/view/history_view_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ QSize Message::performCountOptimalSize() {
const auto via = item->Get<HistoryMessageVia>();
const auto entry = logEntryOriginal();
if (forwarded) {
forwarded->create(via);
forwarded->create(via, item);
}

auto mediaDisplayed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ QSize Gif::countOptimalSize() {
auto reply = _parent->Get<Reply>();
auto forwarded = item->Get<HistoryMessageForwarded>();
if (forwarded) {
forwarded->create(via);
forwarded->create(via, item);
}
maxWidth += additionalWidth(reply, via, forwarded);
accumulate_max(maxWidth, _parent->reactionsOptimalWidth());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ QSize UnwrappedMedia::countOptimalSize() {
const auto topic = _parent->displayedTopicButton();
const auto forwarded = getDisplayedForwardedInfo();
if (forwarded) {
forwarded->create(via);
forwarded->create(via, item);
}
maxWidth += additionalWidth(topic, reply, via, forwarded);
accumulate_max(maxWidth, _parent->reactionsOptimalWidth());
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/ui/chat/chat.style
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ outTextPaletteSelected: TextPalette(outTextPalette) {
monoFg: msgOutMonoFgSelected;
spoilerFg: msgOutDateFgSelected;
}
fwdTextUserpicPadding: margins(0px, 1px, 3px, 0px);
fwdTextStyle: TextStyle(semiboldTextStyle) {
linkUnderline: kLinkUnderlineNever;
}
Expand Down

0 comments on commit 8a6b167

Please sign in to comment.