mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Add root message display in replies section.
This commit is contained in:
parent
d42ce87c09
commit
beb623bee2
3 changed files with 92 additions and 15 deletions
|
@ -38,8 +38,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "data/data_channel.h"
|
||||||
#include "data/data_replies_list.h"
|
#include "data/data_replies_list.h"
|
||||||
#include "data/data_user.h"
|
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "storage/storage_media_prepare.h"
|
#include "storage/storage_media_prepare.h"
|
||||||
#include "storage/storage_account.h"
|
#include "storage/storage_account.h"
|
||||||
|
@ -114,9 +114,13 @@ RepliesWidget::RepliesWidget(
|
||||||
this,
|
this,
|
||||||
controller,
|
controller,
|
||||||
ComposeControls::Mode::Normal))
|
ComposeControls::Mode::Normal))
|
||||||
|
, _rootShadow(this)
|
||||||
, _scrollDown(_scroll, st::historyToDown) {
|
, _scrollDown(_scroll, st::historyToDown) {
|
||||||
setupRoot();
|
setupRoot();
|
||||||
|
|
||||||
|
_rootHeight = st::msgReplyPadding.top()
|
||||||
|
+ st::msgReplyBarSize.height()
|
||||||
|
+ st::msgReplyPadding.bottom();
|
||||||
_topBar->setActiveChat(_history, TopBarWidget::Section::Replies);
|
_topBar->setActiveChat(_history, TopBarWidget::Section::Replies);
|
||||||
|
|
||||||
_topBar->move(0, 0);
|
_topBar->move(0, 0);
|
||||||
|
@ -137,6 +141,7 @@ RepliesWidget::RepliesWidget(
|
||||||
}, _topBar->lifetime());
|
}, _topBar->lifetime());
|
||||||
|
|
||||||
_topBarShadow->raise();
|
_topBarShadow->raise();
|
||||||
|
_rootShadow->raise();
|
||||||
updateAdaptiveLayout();
|
updateAdaptiveLayout();
|
||||||
subscribe(Adaptive::Changed(), [=] { updateAdaptiveLayout(); });
|
subscribe(Adaptive::Changed(), [=] { updateAdaptiveLayout(); });
|
||||||
|
|
||||||
|
@ -144,7 +149,7 @@ RepliesWidget::RepliesWidget(
|
||||||
this,
|
this,
|
||||||
controller,
|
controller,
|
||||||
static_cast<ListDelegate*>(this)));
|
static_cast<ListDelegate*>(this)));
|
||||||
_scroll->move(0, _topBar->height());
|
_scroll->move(0, _topBar->height() + _rootHeight);
|
||||||
_scroll->show();
|
_scroll->show();
|
||||||
connect(_scroll, &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
connect(_scroll, &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
||||||
|
|
||||||
|
@ -191,15 +196,40 @@ void RepliesWidget::setupRoot() {
|
||||||
const auto done = crl::guard(this, [=](ChannelData*, MsgId) {
|
const auto done = crl::guard(this, [=](ChannelData*, MsgId) {
|
||||||
_root = lookupRoot();
|
_root = lookupRoot();
|
||||||
if (_root) {
|
if (_root) {
|
||||||
refreshRootView();
|
|
||||||
_areComments = computeAreComments();
|
_areComments = computeAreComments();
|
||||||
}
|
}
|
||||||
|
refreshRootView();
|
||||||
});
|
});
|
||||||
_history->session().api().requestMessageData(channel, _rootId, done);
|
_history->session().api().requestMessageData(channel, _rootId, done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepliesWidget::refreshRootView() {
|
void RepliesWidget::refreshRootView() {
|
||||||
|
const auto sender = (_root && _root->discussionPostOriginalSender())
|
||||||
|
? _root->discussionPostOriginalSender()
|
||||||
|
: _history->peer.get();
|
||||||
|
_rootTitle.setText(
|
||||||
|
st::fwdTextStyle,
|
||||||
|
sender->name,
|
||||||
|
Ui::NameTextOptions());
|
||||||
|
if (_rootTitle.isEmpty()) {
|
||||||
|
_rootTitle.setText(
|
||||||
|
st::fwdTextStyle,
|
||||||
|
"Message",
|
||||||
|
Ui::NameTextOptions());
|
||||||
|
}
|
||||||
|
if (_root) {
|
||||||
|
_rootMessage.setText(
|
||||||
|
st::messageTextStyle,
|
||||||
|
_root->inReplyText(),
|
||||||
|
Ui::DialogTextOptions());
|
||||||
|
} else {
|
||||||
|
_rootMessage.setText(
|
||||||
|
st::messageTextStyle,
|
||||||
|
textcmdLink(1, tr::lng_deleted_message(tr::now)),
|
||||||
|
Ui::DialogTextOptions());
|
||||||
|
}
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryItem *RepliesWidget::lookupRoot() const {
|
HistoryItem *RepliesWidget::lookupRoot() const {
|
||||||
|
@ -988,6 +1018,9 @@ void RepliesWidget::updateAdaptiveLayout() {
|
||||||
_topBarShadow->moveToLeft(
|
_topBarShadow->moveToLeft(
|
||||||
Adaptive::OneColumn() ? 0 : st::lineWidth,
|
Adaptive::OneColumn() ? 0 : st::lineWidth,
|
||||||
_topBar->height());
|
_topBar->height());
|
||||||
|
_rootShadow->moveToLeft(
|
||||||
|
Adaptive::OneColumn() ? 0 : st::lineWidth,
|
||||||
|
_topBar->height() + _rootHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<History*> RepliesWidget::history() const {
|
not_null<History*> RepliesWidget::history() const {
|
||||||
|
@ -1138,10 +1171,11 @@ void RepliesWidget::updateControlsGeometry() {
|
||||||
: base::make_optional(_scroll->scrollTop() + topDelta());
|
: base::make_optional(_scroll->scrollTop() + topDelta());
|
||||||
_topBar->resizeToWidth(contentWidth);
|
_topBar->resizeToWidth(contentWidth);
|
||||||
_topBarShadow->resize(contentWidth, st::lineWidth);
|
_topBarShadow->resize(contentWidth, st::lineWidth);
|
||||||
|
_rootShadow->resize(contentWidth, st::lineWidth);
|
||||||
|
|
||||||
const auto bottom = height();
|
const auto bottom = height();
|
||||||
const auto controlsHeight = _composeControls->heightCurrent();
|
const auto controlsHeight = _composeControls->heightCurrent();
|
||||||
const auto scrollHeight = bottom - _topBar->height() - controlsHeight;
|
const auto scrollHeight = bottom - _topBar->height() - _rootHeight - controlsHeight;
|
||||||
const auto scrollSize = QSize(contentWidth, scrollHeight);
|
const auto scrollSize = QSize(contentWidth, scrollHeight);
|
||||||
if (_scroll->size() != scrollSize) {
|
if (_scroll->size() != scrollSize) {
|
||||||
_skipScrollEvent = true;
|
_skipScrollEvent = true;
|
||||||
|
@ -1164,18 +1198,56 @@ void RepliesWidget::paintEvent(QPaintEvent *e) {
|
||||||
if (animating()) {
|
if (animating()) {
|
||||||
SectionWidget::paintEvent(e);
|
SectionWidget::paintEvent(e);
|
||||||
return;
|
return;
|
||||||
}
|
} else if (Ui::skipPaintEvent(this, e)) {
|
||||||
if (Ui::skipPaintEvent(this, e)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//if (hasPendingResizedItems()) {
|
|
||||||
// updateListSize();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//auto ms = crl::now();
|
const auto aboveHeight = _topBar->height() + _rootHeight;
|
||||||
//_historyDownShown.step(ms);
|
const auto bg = e->rect().intersected(
|
||||||
|
QRect(0, aboveHeight, width(), height() - aboveHeight));
|
||||||
|
SectionWidget::PaintBackground(controller(), this, bg);
|
||||||
|
|
||||||
SectionWidget::PaintBackground(controller(), this, e->rect());
|
auto p = Painter(this);
|
||||||
|
paintRoot(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RepliesWidget::paintRoot(Painter &p) {
|
||||||
|
auto top = _topBar->bottomNoMargins();
|
||||||
|
p.fillRect(myrtlrect(0, top, width(), st::historyReplyHeight), st::historyPinnedBg);
|
||||||
|
|
||||||
|
top += st::msgReplyPadding.top();
|
||||||
|
QRect rbar(myrtlrect(st::msgReplyBarSkip + st::msgReplyBarPos.x(), top + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height()));
|
||||||
|
p.fillRect(rbar, st::msgInReplyBarColor);
|
||||||
|
|
||||||
|
int32 left = st::msgReplyBarSkip + st::msgReplyBarSkip;
|
||||||
|
if (!_rootTitle.isEmpty()) {
|
||||||
|
const auto media = _root ? _root->media() : nullptr;
|
||||||
|
if (media && media->hasReplyPreview()) {
|
||||||
|
if (const auto image = media->replyPreview()) {
|
||||||
|
QRect to(left, top, st::msgReplyBarSize.height(), st::msgReplyBarSize.height());
|
||||||
|
p.drawPixmap(to.x(), to.y(), image->pixSingle(image->width() / cIntRetinaFactor(), image->height() / cIntRetinaFactor(), to.width(), to.height(), ImageRoundRadius::Small));
|
||||||
|
}
|
||||||
|
left += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x();
|
||||||
|
}
|
||||||
|
p.setPen(st::historyReplyNameFg);
|
||||||
|
p.setFont(st::msgServiceNameFont);
|
||||||
|
const auto poll = media ? media->poll() : nullptr;
|
||||||
|
const auto pinnedHeader = !poll
|
||||||
|
? tr::lng_pinned_message(tr::now)
|
||||||
|
: poll->quiz()
|
||||||
|
? tr::lng_pinned_quiz(tr::now)
|
||||||
|
: tr::lng_pinned_poll(tr::now);
|
||||||
|
_rootTitle.drawElided(p, left, top, width() - left - st::msgReplyPadding.right());
|
||||||
|
|
||||||
|
p.setPen(st::historyComposeAreaFg);
|
||||||
|
p.setTextPalette(st::historyComposeAreaPalette);
|
||||||
|
_rootMessage.drawElided(p, left, top + st::msgServiceNameFont->height, width() - left - st::msgReplyPadding.right());
|
||||||
|
p.restoreTextPalette();
|
||||||
|
} else {
|
||||||
|
p.setFont(st::msgDateFont);
|
||||||
|
p.setPen(st::historyComposeAreaFgService);
|
||||||
|
p.drawText(left, top + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2 + st::msgDateFont->ascent, st::msgDateFont->elided(tr::lng_profile_loading(tr::now), width() - left - st::msgReplyPadding.right()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepliesWidget::onScroll() {
|
void RepliesWidget::onScroll() {
|
||||||
|
|
|
@ -217,6 +217,8 @@ private:
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
|
|
||||||
|
void paintRoot(Painter &p);
|
||||||
|
|
||||||
const not_null<History*> _history;
|
const not_null<History*> _history;
|
||||||
const MsgId _rootId = 0;
|
const MsgId _rootId = 0;
|
||||||
HistoryItem *_root = nullptr;
|
HistoryItem *_root = nullptr;
|
||||||
|
@ -229,6 +231,11 @@ private:
|
||||||
std::unique_ptr<ComposeControls> _composeControls;
|
std::unique_ptr<ComposeControls> _composeControls;
|
||||||
bool _skipScrollEvent = false;
|
bool _skipScrollEvent = false;
|
||||||
|
|
||||||
|
Ui::Text::String _rootTitle;
|
||||||
|
Ui::Text::String _rootMessage;
|
||||||
|
object_ptr<Ui::PlainShadow> _rootShadow;
|
||||||
|
int _rootHeight = 0;
|
||||||
|
|
||||||
std::vector<MsgId> _replyReturns;
|
std::vector<MsgId> _replyReturns;
|
||||||
HistoryItem *_replyReturn = nullptr;
|
HistoryItem *_replyReturn = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -105,9 +105,7 @@ void SessionNavigation::showRepliesForMessage(
|
||||||
const auto channelId = history->channelId();
|
const auto channelId = history->channelId();
|
||||||
const auto item = _session->data().message(channelId, rootId);
|
const auto item = _session->data().message(channelId, rootId);
|
||||||
if (!item || !item->repliesAreComments()) {
|
if (!item || !item->repliesAreComments()) {
|
||||||
if (item->repliesCount() > 0) {
|
showSection(HistoryView::RepliesMemento(history, rootId));
|
||||||
showSection(HistoryView::RepliesMemento(history, rootId));
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
} else if (const auto id = item->commentsItemId()) {
|
} else if (const auto id = item->commentsItemId()) {
|
||||||
if (const auto item = _session->data().message(id)) {
|
if (const auto item = _session->data().message(id)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue