mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added sponsored messages to HistoryWidget.
This commit is contained in:
parent
c2c53df886
commit
419f6345b3
4 changed files with 38 additions and 1 deletions
|
@ -2675,6 +2675,10 @@ QString History::topPromotionMessage() const {
|
|||
return _topPromotedMessage;
|
||||
}
|
||||
|
||||
bool History::canHaveSponsoredMessages() const {
|
||||
return isChannel();
|
||||
}
|
||||
|
||||
bool History::clearUnreadOnClientSide() const {
|
||||
if (!session().supportMode()) {
|
||||
return false;
|
||||
|
|
|
@ -282,6 +282,8 @@ public:
|
|||
[[nodiscard]] bool topPromotionAboutShown() const;
|
||||
void markTopPromotionAboutShown();
|
||||
|
||||
[[nodiscard]] bool canHaveSponsoredMessages() const;
|
||||
|
||||
MsgId minMsgId() const;
|
||||
MsgId maxMsgId() const;
|
||||
MsgId msgIdForRead() const;
|
||||
|
|
|
@ -56,6 +56,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_user.h"
|
||||
#include "data/data_chat_filters.h"
|
||||
#include "data/data_scheduled_messages.h"
|
||||
#include "data/data_sponsored_messages.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_histories.h"
|
||||
#include "data/data_group_call.h"
|
||||
|
@ -109,6 +110,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/chat/group_call_bar.h"
|
||||
#include "ui/chat/chat_theme.h"
|
||||
#include "ui/chat/chat_style.h"
|
||||
#include "ui/chat/continuous_scroll.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/item_text_options.h"
|
||||
#include "ui/unread_badge.h"
|
||||
|
@ -260,6 +262,14 @@ HistoryWidget::HistoryWidget(
|
|||
) | rpl::start_with_next(crl::guard(_list, [=] {
|
||||
_list->onParentGeometryChanged();
|
||||
}), lifetime());
|
||||
_scroll->addContentRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (_history->loadedAtBottom()
|
||||
&& session().data().sponsoredMessages().append(_history)) {
|
||||
_scroll->contentAdded();
|
||||
}
|
||||
}, lifetime());
|
||||
|
||||
_historyDown->addClickHandler([=] { historyDownClicked(); });
|
||||
_unreadMentions->addClickHandler([=] { showNextUnreadMention(); });
|
||||
_fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); });
|
||||
|
@ -1966,6 +1976,8 @@ void HistoryWidget::showHistory(
|
|||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
session().data().sponsoredMessages().clearItems(_history);
|
||||
}
|
||||
session().sendProgressManager().update(
|
||||
_history,
|
||||
|
@ -2169,6 +2181,14 @@ void HistoryWidget::showHistory(
|
|||
}
|
||||
unreadCountUpdated(); // set _historyDown badge.
|
||||
showAboutTopPromotion();
|
||||
|
||||
{
|
||||
const auto hasSponsored = _history->canHaveSponsoredMessages();
|
||||
_scroll->setTrackingContent(hasSponsored);
|
||||
if (hasSponsored) {
|
||||
session().data().sponsoredMessages().request(_history);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_chooseForReport = nullptr;
|
||||
refreshTopBarActiveChat();
|
||||
|
@ -2616,6 +2636,16 @@ void HistoryWidget::newItemAdded(not_null<HistoryItem*> item) {
|
|||
|| item->isScheduled()) {
|
||||
return;
|
||||
}
|
||||
if (item->isSponsored()) {
|
||||
if (const auto view = item->mainView()) {
|
||||
view->resizeGetHeight(width());
|
||||
updateHistoryGeometry(
|
||||
false,
|
||||
true,
|
||||
{ ScrollChangeNoJumpToBottom, 0 });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If we get here in non-resized state we can't rely on results of
|
||||
// doWeReadServerHistory() and mark chat as read.
|
||||
|
|
|
@ -80,6 +80,7 @@ namespace Toast {
|
|||
class Instance;
|
||||
} // namespace Toast
|
||||
class ChooseThemeController;
|
||||
class ContinuousScroll;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Window {
|
||||
|
@ -675,7 +676,7 @@ private:
|
|||
int _delayedShowAtRequest = 0; // Not real mtpRequestId.
|
||||
|
||||
object_ptr<HistoryView::TopBarWidget> _topBar;
|
||||
object_ptr<Ui::ScrollArea> _scroll;
|
||||
object_ptr<Ui::ContinuousScroll> _scroll;
|
||||
QPointer<HistoryInner> _list;
|
||||
History *_migrated = nullptr;
|
||||
History *_history = nullptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue