mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Display story repost nicely.
This commit is contained in:
parent
77b2076e0f
commit
8f9123bb96
6 changed files with 50 additions and 61 deletions
|
@ -711,9 +711,9 @@ HistoryItem::HistoryItem(
|
||||||
: tr::lng_sponsored_message_title(tr::now),
|
: tr::lng_sponsored_message_title(tr::now),
|
||||||
from.title,
|
from.title,
|
||||||
textWithEntities,
|
textWithEntities,
|
||||||
from.webpageOrBotPhotoId
|
(from.webpageOrBotPhotoId
|
||||||
? history->owner().photo(from.webpageOrBotPhotoId)
|
? history->owner().photo(from.webpageOrBotPhotoId).get()
|
||||||
: nullptr,
|
: nullptr),
|
||||||
nullptr,
|
nullptr,
|
||||||
WebPageCollage(),
|
WebPageCollage(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_stories.h"
|
#include "data/data_stories.h"
|
||||||
#include "history/view/history_view_reply.h"
|
#include "history/view/history_view_reply.h"
|
||||||
#include "lang/lang_keys.h"
|
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "media/stories/media_stories_controller.h"
|
#include "media/stories/media_stories_controller.h"
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
@ -54,14 +53,24 @@ void RepostView::draw(Painter &p, int x, int y, int availableWidth) {
|
||||||
if (!_maxWidth) {
|
if (!_maxWidth) {
|
||||||
recountDimensions();
|
recountDimensions();
|
||||||
}
|
}
|
||||||
const auto w = std::min(_maxWidth, availableWidth);
|
if (_loading) {
|
||||||
const auto rect = QRect(x, y, w, height());
|
return;
|
||||||
|
}
|
||||||
|
const auto simple = _text.isEmpty();
|
||||||
|
if (simple) {
|
||||||
|
y += st::normalFont->height;
|
||||||
|
}
|
||||||
|
const auto w = std::min(int(_maxWidth), availableWidth);
|
||||||
|
const auto h = height() - (simple ? st::normalFont->height : 0);
|
||||||
|
const auto rect = QRect(x, y, w, h);
|
||||||
const auto colorPeer = _story->repostSourcePeer();
|
const auto colorPeer = _story->repostSourcePeer();
|
||||||
const auto backgroundEmojiId = colorPeer
|
const auto backgroundEmojiId = (!simple && colorPeer)
|
||||||
? colorPeer->backgroundEmojiId()
|
? colorPeer->backgroundEmojiId()
|
||||||
: DocumentId();
|
: DocumentId();
|
||||||
const auto cache = &_quoteCache;
|
const auto cache = &_quoteCache;
|
||||||
const auto "eSt = st::messageQuoteStyle;
|
const auto "eSt = simple
|
||||||
|
? st::storiesRepostSimpleStyle
|
||||||
|
: st::messageQuoteStyle;
|
||||||
const auto backgroundEmoji = backgroundEmojiId
|
const auto backgroundEmoji = backgroundEmojiId
|
||||||
? &_backgroundEmojiData
|
? &_backgroundEmojiData
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
@ -106,27 +115,27 @@ void RepostView::draw(Painter &p, int x, int y, int availableWidth) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto pausedSpoiler = On(PowerSaving::kChatSpoiler);
|
const auto pausedSpoiler = On(PowerSaving::kChatSpoiler);
|
||||||
auto textLeft = x + st::historyReplyPadding.left();
|
|
||||||
auto textTop = y
|
|
||||||
+ st::historyReplyPadding.top()
|
|
||||||
+ st::semiboldFont->height;
|
|
||||||
if (w > st::historyReplyPadding.left()) {
|
if (w > st::historyReplyPadding.left()) {
|
||||||
if (_stateText.isEmpty()) {
|
const auto textw = w
|
||||||
const auto textw = w
|
- st::historyReplyPadding.left()
|
||||||
- st::historyReplyPadding.left()
|
- st::historyReplyPadding.right();
|
||||||
- st::historyReplyPadding.right();
|
const auto namew = textw;
|
||||||
const auto namew = textw;
|
if (namew > 0) {
|
||||||
if (namew > 0) {
|
p.setPen(cache->icon);
|
||||||
p.setPen(cache->icon);
|
_name.drawLeftElided(
|
||||||
_name.drawLeftElided(
|
p,
|
||||||
p,
|
x + st::historyReplyPadding.left(),
|
||||||
x + st::historyReplyPadding.left(),
|
y + st::historyReplyPadding.top(),
|
||||||
y + st::historyReplyPadding.top(),
|
namew,
|
||||||
namew,
|
w + 2 * x);
|
||||||
w + 2 * x);
|
if (!simple) {
|
||||||
|
const auto textLeft = x + st::historyReplyPadding.left();
|
||||||
|
const auto textTop = y
|
||||||
|
+ st::historyReplyPadding.top()
|
||||||
|
+ st::semiboldFont->height;
|
||||||
_text.draw(p, {
|
_text.draw(p, {
|
||||||
.position = { textLeft, textTop },
|
.position = { textLeft, textTop },
|
||||||
.availableWidth = w,
|
.availableWidth = textw,
|
||||||
.palette = &st::mediaviewTextPalette,
|
.palette = &st::mediaviewTextPalette,
|
||||||
.spoiler = Ui::Text::DefaultSpoilerCache(),
|
.spoiler = Ui::Text::DefaultSpoilerCache(),
|
||||||
.pausedEmoji = On(PowerSaving::kEmojiChat),
|
.pausedEmoji = On(PowerSaving::kEmojiChat),
|
||||||
|
@ -134,18 +143,6 @@ void RepostView::draw(Painter &p, int x, int y, int availableWidth) {
|
||||||
.elisionLines = 1,
|
.elisionLines = 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
p.setFont(st::msgDateFont);
|
|
||||||
p.setPen(cache->icon);
|
|
||||||
p.drawTextLeft(
|
|
||||||
textLeft,
|
|
||||||
(y
|
|
||||||
+ st::historyReplyPadding.top()
|
|
||||||
+ (st::msgDateFont->height / 2)),
|
|
||||||
w + 2 * x,
|
|
||||||
st::msgDateFont->elided(
|
|
||||||
_stateText,
|
|
||||||
x + w - textLeft - st::historyReplyPadding.right()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,13 +169,11 @@ void RepostView::recountDimensions() {
|
||||||
_quoteCache.icon = values.name;
|
_quoteCache.icon = values.name;
|
||||||
|
|
||||||
auto text = TextWithEntities();
|
auto text = TextWithEntities();
|
||||||
auto displaying = true;
|
|
||||||
auto unavailable = false;
|
auto unavailable = false;
|
||||||
if (sender && repostId) {
|
if (sender && repostId) {
|
||||||
const auto of = owner->stories().lookup({ sender->id, repostId });
|
const auto of = owner->stories().lookup({ sender->id, repostId });
|
||||||
displaying = of.has_value();
|
unavailable = !of && (of.error() == Data::NoStory::Deleted);
|
||||||
unavailable = !displaying && (of.error() == Data::NoStory::Deleted);
|
if (of) {
|
||||||
if (displaying) {
|
|
||||||
text = (*of)->caption();
|
text = (*of)->caption();
|
||||||
} else if (!unavailable) {
|
} else if (!unavailable) {
|
||||||
const auto done = crl::guard(this, [=] {
|
const auto done = crl::guard(this, [=] {
|
||||||
|
@ -188,9 +183,6 @@ void RepostView::recountDimensions() {
|
||||||
owner->stories().resolve({ sender->id, repostId }, done);
|
owner->stories().resolve({ sender->id, repostId }, done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (displaying && !unavailable && text.empty()) {
|
|
||||||
text = { tr::lng_in_dlg_story(tr::now) };
|
|
||||||
}
|
|
||||||
|
|
||||||
auto nameFull = TextWithEntities();
|
auto nameFull = TextWithEntities();
|
||||||
nameFull.append(HistoryView::Reply::PeerEmoji(owner, sender));
|
nameFull.append(HistoryView::Reply::PeerEmoji(owner, sender));
|
||||||
|
@ -215,21 +207,10 @@ void RepostView::recountDimensions() {
|
||||||
context);
|
context);
|
||||||
|
|
||||||
const auto nameMaxWidth = _name.maxWidth();
|
const auto nameMaxWidth = _name.maxWidth();
|
||||||
const auto optimalTextWidth = std::min(
|
const auto optimalTextWidth = _text.isEmpty()
|
||||||
_text.maxWidth(),
|
? 0
|
||||||
st::maxSignatureSize);
|
: std::min(_text.maxWidth(), st::maxSignatureSize);
|
||||||
_maxWidth = std::max(nameMaxWidth, optimalTextWidth);
|
_maxWidth = std::max(nameMaxWidth, optimalTextWidth);
|
||||||
if (!displaying) {
|
|
||||||
_stateText = !unavailable
|
|
||||||
? tr::lng_profile_loading(tr::now)
|
|
||||||
: tr::lng_deleted_story(tr::now);
|
|
||||||
const auto phraseWidth = st::msgDateFont->width(_stateText);
|
|
||||||
_maxWidth = unavailable
|
|
||||||
? phraseWidth
|
|
||||||
: std::max(_maxWidth, phraseWidth);
|
|
||||||
} else {
|
|
||||||
_stateText = QString();
|
|
||||||
}
|
|
||||||
_maxWidth = st::historyReplyPadding.left()
|
_maxWidth = st::historyReplyPadding.left()
|
||||||
+ _maxWidth
|
+ _maxWidth
|
||||||
+ st::historyReplyPadding.right();
|
+ st::historyReplyPadding.right();
|
||||||
|
|
|
@ -45,9 +45,9 @@ private:
|
||||||
Ui::Text::String _text;
|
Ui::Text::String _text;
|
||||||
Ui::Text::QuotePaintCache _quoteCache;
|
Ui::Text::QuotePaintCache _quoteCache;
|
||||||
Ui::BackgroundEmojiData _backgroundEmojiData;
|
Ui::BackgroundEmojiData _backgroundEmojiData;
|
||||||
QString _stateText;
|
|
||||||
Ui::ColorIndicesCompressed _colorIndices;
|
Ui::ColorIndicesCompressed _colorIndices;
|
||||||
int _maxWidth = 0;
|
uint32 _maxWidth : 31 = 0;
|
||||||
|
uint32 _loading : 1 = 0;
|
||||||
|
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
|
|
|
@ -1009,3 +1009,9 @@ storiesLikeCountStyle: TextStyle(defaultTextStyle) {
|
||||||
font: font(32px semibold);
|
font: font(32px semibold);
|
||||||
}
|
}
|
||||||
storiesChangelogFooterWidthMin: 240px;
|
storiesChangelogFooterWidthMin: 240px;
|
||||||
|
storiesRepostSimpleStyle: QuoteStyle(defaultQuoteStyle) {
|
||||||
|
padding: margins(8px, 2px, 8px, 2px);
|
||||||
|
verticalSkip: 4px;
|
||||||
|
outline: 0px;
|
||||||
|
radius: 10px;
|
||||||
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include <QtCore/QMimeData>
|
#include <QtCore/QMimeData>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
|
#include <QtGui/QScreen>
|
||||||
#include <QtGui/QDrag>
|
#include <QtGui/QDrag>
|
||||||
|
|
||||||
#include <kurlmimedata.h>
|
#include <kurlmimedata.h>
|
||||||
|
|
|
@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
|
#include <QtGui/QScreen>
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
Loading…
Add table
Reference in a new issue