mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Load similar channels correctly.
This commit is contained in:
parent
2df6729f2d
commit
4dbe5c0a0f
10 changed files with 84 additions and 19 deletions
|
@ -587,9 +587,6 @@ void ChatParticipants::requestSelf(not_null<ChannelData*> channel) {
|
||||||
} else {
|
} else {
|
||||||
history->owner().histories().requestDialogEntry(history);
|
history->owner().histories().requestDialogEntry(history);
|
||||||
}
|
}
|
||||||
if (dateChanged) {
|
|
||||||
loadSimilarChannels(channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_selfParticipantRequests.emplace(channel);
|
_selfParticipantRequests.emplace(channel);
|
||||||
|
@ -713,9 +710,17 @@ void ChatParticipants::loadSimilarChannels(not_null<ChannelData*> channel) {
|
||||||
_similar[channel].requestId = _api.request(
|
_similar[channel].requestId = _api.request(
|
||||||
MTPchannels_GetChannelRecommendations(channel->inputChannel)
|
MTPchannels_GetChannelRecommendations(channel->inputChannel)
|
||||||
).done([=](const MTPmessages_Chats &result) {
|
).done([=](const MTPmessages_Chats &result) {
|
||||||
_similar[channel] = {
|
auto &similar = _similar[channel];
|
||||||
.list = ParseSimilar(channel, result),
|
auto list = ParseSimilar(channel, result);
|
||||||
};
|
if (similar.list == list) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
similar.list = std::move(list);
|
||||||
|
if (const auto history = channel->owner().historyLoaded(channel)) {
|
||||||
|
if (const auto item = history->joinedMessageInstance()) {
|
||||||
|
history->owner().requestItemResize(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
_similarLoaded.fire_copy(channel);
|
_similarLoaded.fire_copy(channel);
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,8 @@ public:
|
||||||
not_null<ChannelData*> channel,
|
not_null<ChannelData*> channel,
|
||||||
not_null<PeerData*> participant);
|
not_null<PeerData*> participant);
|
||||||
|
|
||||||
|
void loadSimilarChannels(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<not_null<ChannelData*>> &similar(
|
[[nodiscard]] const std::vector<not_null<ChannelData*>> &similar(
|
||||||
not_null<ChannelData*> channel);
|
not_null<ChannelData*> channel);
|
||||||
[[nodiscard]] auto similarLoaded() const
|
[[nodiscard]] auto similarLoaded() const
|
||||||
|
@ -131,8 +133,6 @@ private:
|
||||||
mtpRequestId requestId = 0;
|
mtpRequestId requestId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void loadSimilarChannels(not_null<ChannelData*> channel);
|
|
||||||
|
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
|
|
||||||
using PeerRequests = base::flat_map<PeerData*, mtpRequestId>;
|
using PeerRequests = base::flat_map<PeerData*, mtpRequestId>;
|
||||||
|
|
|
@ -1739,6 +1739,10 @@ void ApiWrap::joinChannel(not_null<ChannelData*> channel) {
|
||||||
}).send();
|
}).send();
|
||||||
|
|
||||||
_channelAmInRequests.emplace(channel, requestId);
|
_channelAmInRequests.emplace(channel, requestId);
|
||||||
|
|
||||||
|
using Flag = ChannelDataFlag;
|
||||||
|
chatParticipants().loadSimilarChannels(channel);
|
||||||
|
channel->setFlags(channel->flags() | Flag::SimilarExpanded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ void ChannelData::setFlags(ChannelDataFlags which) {
|
||||||
session().changes().peerUpdated(this, UpdateFlag::Migration);
|
session().changes().peerUpdated(this, UpdateFlag::Migration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (diff & (Flag::Forum | Flag::CallNotEmpty)) {
|
if (diff & (Flag::Forum | Flag::CallNotEmpty | Flag::SimilarExpanded)) {
|
||||||
if (const auto history = this->owner().historyLoaded(this)) {
|
if (const auto history = this->owner().historyLoaded(this)) {
|
||||||
if (diff & Flag::CallNotEmpty) {
|
if (diff & Flag::CallNotEmpty) {
|
||||||
history->updateChatListEntry();
|
history->updateChatListEntry();
|
||||||
|
@ -189,6 +189,11 @@ void ChannelData::setFlags(ChannelDataFlags which) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (diff & Flag::SimilarExpanded) {
|
||||||
|
if (const auto item = history->joinedMessageInstance()) {
|
||||||
|
history->owner().requestItemResize(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (const auto raw = taken.get()) {
|
if (const auto raw = taken.get()) {
|
||||||
|
|
|
@ -64,6 +64,7 @@ enum class ChannelDataFlag {
|
||||||
HasUnreadStories = (1 << 28),
|
HasUnreadStories = (1 << 28),
|
||||||
CanGetStatistics = (1 << 29),
|
CanGetStatistics = (1 << 29),
|
||||||
ViewAsMessages = (1 << 30),
|
ViewAsMessages = (1 << 30),
|
||||||
|
SimilarExpanded = (1 << 31),
|
||||||
};
|
};
|
||||||
inline constexpr bool is_flag_type(ChannelDataFlag) { return true; };
|
inline constexpr bool is_flag_type(ChannelDataFlag) { return true; };
|
||||||
using ChannelDataFlags = base::flags<ChannelDataFlag>;
|
using ChannelDataFlags = base::flags<ChannelDataFlag>;
|
||||||
|
|
|
@ -3190,6 +3190,7 @@ void History::insertMessageToBlocks(not_null<HistoryItem*> item) {
|
||||||
const auto lastDate = chatListTimeId();
|
const auto lastDate = chatListTimeId();
|
||||||
if (!lastDate || itemDate >= lastDate) {
|
if (!lastDate || itemDate >= lastDate) {
|
||||||
setLastMessage(item);
|
setLastMessage(item);
|
||||||
|
owner().notifyHistoryChangeDelayed(this);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3227,6 +3228,10 @@ void History::checkLocalMessages() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HistoryItem *History::joinedMessageInstance() const {
|
||||||
|
return _joinedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
void History::removeJoinedMessage() {
|
void History::removeJoinedMessage() {
|
||||||
if (_joinedMessage) {
|
if (_joinedMessage) {
|
||||||
_joinedMessage->destroy();
|
_joinedMessage->destroy();
|
||||||
|
|
|
@ -99,6 +99,8 @@ public:
|
||||||
not_null<History*> migrateToOrMe() const;
|
not_null<History*> migrateToOrMe() const;
|
||||||
History *migrateFrom() const;
|
History *migrateFrom() const;
|
||||||
MsgRange rangeForDifferenceRequest() const;
|
MsgRange rangeForDifferenceRequest() const;
|
||||||
|
|
||||||
|
HistoryItem *joinedMessageInstance() const;
|
||||||
void checkLocalMessages();
|
void checkLocalMessages();
|
||||||
void removeJoinedMessage();
|
void removeJoinedMessage();
|
||||||
|
|
||||||
|
|
|
@ -639,6 +639,12 @@ TextState Service::textState(QPoint point, StateRequest request) const {
|
||||||
} else if (mediaDisplayed) {
|
} else if (mediaDisplayed) {
|
||||||
g.setHeight(g.height() - (st::msgServiceMargin.top() + media->height()));
|
g.setHeight(g.height() - (st::msgServiceMargin.top() + media->height()));
|
||||||
}
|
}
|
||||||
|
const auto mediaLeft = st::msgServiceMargin.left()
|
||||||
|
+ (media ? ((g.width() - media->width()) / 2) : 0);
|
||||||
|
const auto mediaTop = st::msgServiceMargin.top()
|
||||||
|
+ g.height()
|
||||||
|
+ st::msgServiceMargin.top();
|
||||||
|
const auto mediaPoint = point - QPoint(mediaLeft, mediaTop);
|
||||||
auto trect = g.marginsAdded(-st::msgServicePadding);
|
auto trect = g.marginsAdded(-st::msgServicePadding);
|
||||||
if (trect.contains(point)) {
|
if (trect.contains(point)) {
|
||||||
auto textRequest = request.forText();
|
auto textRequest = request.forText();
|
||||||
|
@ -667,10 +673,12 @@ TextState Service::textState(QPoint point, StateRequest request) const {
|
||||||
}
|
}
|
||||||
} else if (const auto same = item->Get<HistoryServiceSameBackground>()) {
|
} else if (const auto same = item->Get<HistoryServiceSameBackground>()) {
|
||||||
result.link = same->lnk;
|
result.link = same->lnk;
|
||||||
|
} else if (media && data()->showSimilarChannels()) {
|
||||||
|
result = media->textState(mediaPoint, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mediaDisplayed) {
|
} else if (mediaDisplayed && point.y() >= mediaTop) {
|
||||||
result = media->textState(point - QPoint(st::msgServiceMargin.left() + (g.width() - media->width()) / 2, st::msgServiceMargin.top() + g.height() + st::msgServiceMargin.top()), request);
|
result = media->textState(mediaPoint, request);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,9 @@ void SimilarChannels::clickHandlerPressedChanged(
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimilarChannels::draw(Painter &p, const PaintContext &context) const {
|
void SimilarChannels::draw(Painter &p, const PaintContext &context) const {
|
||||||
|
if (!_toggled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto large = Ui::BubbleCornerRounding::Large;
|
const auto large = Ui::BubbleCornerRounding::Large;
|
||||||
const auto geometry = QRect(0, 0, width(), height());
|
const auto geometry = QRect(0, 0, width(), height());
|
||||||
Ui::PaintBubble(
|
Ui::PaintBubble(
|
||||||
|
@ -334,6 +337,23 @@ void SimilarChannels::validateParticipansBg(const Channel &channel) const {
|
||||||
channel.participantsBg = std::move(result);
|
channel.participantsBg = std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClickHandlerPtr SimilarChannels::ensureToggleLink() const {
|
||||||
|
if (_toggleLink) {
|
||||||
|
return _toggleLink;
|
||||||
|
}
|
||||||
|
_toggleLink = std::make_shared<LambdaClickHandler>(crl::guard(this, [=](
|
||||||
|
ClickContext context) {
|
||||||
|
const auto channel = history()->peer->asChannel();
|
||||||
|
Assert(channel != nullptr);
|
||||||
|
using Flag = ChannelDataFlag;
|
||||||
|
const auto flags = channel->flags();
|
||||||
|
channel->setFlags((flags & Flag::SimilarExpanded)
|
||||||
|
? (flags & ~Flag::SimilarExpanded)
|
||||||
|
: (flags | Flag::SimilarExpanded));
|
||||||
|
}));
|
||||||
|
return _toggleLink;
|
||||||
|
}
|
||||||
|
|
||||||
void SimilarChannels::ensureCacheReady(QSize size) const {
|
void SimilarChannels::ensureCacheReady(QSize size) const {
|
||||||
const auto ratio = style::DevicePixelRatio();
|
const auto ratio = style::DevicePixelRatio();
|
||||||
if (_roundedCache.size() != size * ratio) {
|
if (_roundedCache.size() != size * ratio) {
|
||||||
|
@ -352,6 +372,10 @@ TextState SimilarChannels::textState(
|
||||||
QPoint point,
|
QPoint point,
|
||||||
StateRequest request) const {
|
StateRequest request) const {
|
||||||
auto result = TextState();
|
auto result = TextState();
|
||||||
|
if (point.y() < 0 && !_empty) {
|
||||||
|
result.link = ensureToggleLink();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
result.horizontalScroll = (_scrollMax > 0);
|
result.horizontalScroll = (_scrollMax > 0);
|
||||||
const auto skip = st::chatSimilarTitlePosition;
|
const auto skip = st::chatSimilarTitlePosition;
|
||||||
const auto viewWidth = _hasViewAll ? (_viewAllWidth + 2 * skip.x()) : 0;
|
const auto viewWidth = _hasViewAll ? (_viewAllWidth + 2 * skip.x()) : 0;
|
||||||
|
@ -362,7 +386,7 @@ TextState SimilarChannels::textState(
|
||||||
const auto channel = parent()->history()->peer->asChannel();
|
const auto channel = parent()->history()->peer->asChannel();
|
||||||
Assert(channel != nullptr);
|
Assert(channel != nullptr);
|
||||||
_viewAllLink = std::make_shared<LambdaClickHandler>([=](
|
_viewAllLink = std::make_shared<LambdaClickHandler>([=](
|
||||||
ClickContext context) {
|
ClickContext context) {
|
||||||
Assert(channel != nullptr);
|
Assert(channel != nullptr);
|
||||||
const auto api = &channel->session().api();
|
const auto api = &channel->session().api();
|
||||||
const auto &list = api->chatParticipants().similar(channel);
|
const auto &list = api->chatParticipants().similar(channel);
|
||||||
|
@ -396,8 +420,12 @@ QSize SimilarChannels::countOptimalSize() {
|
||||||
|
|
||||||
_channels.clear();
|
_channels.clear();
|
||||||
const auto api = &channel->session().api();
|
const auto api = &channel->session().api();
|
||||||
|
api->chatParticipants().loadSimilarChannels(channel);
|
||||||
const auto similar = api->chatParticipants().similar(channel);
|
const auto similar = api->chatParticipants().similar(channel);
|
||||||
if (similar.empty()) {
|
_empty = similar.empty() ? 1 : 0;
|
||||||
|
using Flag = ChannelDataFlag;
|
||||||
|
_toggled = (channel->flags() & Flag::SimilarExpanded) ? 1 : 0;
|
||||||
|
if (_empty || !_toggled) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,7 +469,7 @@ QSize SimilarChannels::countOptimalSize() {
|
||||||
_title = tr::lng_similar_channels_title(tr::now);
|
_title = tr::lng_similar_channels_title(tr::now);
|
||||||
_titleWidth = st::chatSimilarTitle->width(_title);
|
_titleWidth = st::chatSimilarTitle->width(_title);
|
||||||
_viewAll = tr::lng_similar_channels_view_all(tr::now);
|
_viewAll = tr::lng_similar_channels_view_all(tr::now);
|
||||||
_viewAllWidth = st::normalFont->width(_viewAll);
|
_viewAllWidth = std::max(st::normalFont->width(_viewAll), 0);
|
||||||
const auto count = int(_channels.size());
|
const auto count = int(_channels.size());
|
||||||
const auto desired = (count ? (x - skip) : x)
|
const auto desired = (count ? (x - skip) : x)
|
||||||
- st::chatSimilarPadding.left();
|
- st::chatSimilarPadding.left();
|
||||||
|
@ -451,7 +479,7 @@ QSize SimilarChannels::countOptimalSize() {
|
||||||
const auto titleSkip = st::chatSimilarTitlePosition.x();
|
const auto titleSkip = st::chatSimilarTitlePosition.x();
|
||||||
const auto min = _titleWidth + 2 * titleSkip;
|
const auto min = _titleWidth + 2 * titleSkip;
|
||||||
const auto limited = std::max(
|
const auto limited = std::max(
|
||||||
std::min(_fullWidth, st::chatSimilarWidthMax),
|
std::min(int(_fullWidth), st::chatSimilarWidthMax),
|
||||||
min);
|
min);
|
||||||
if (limited > _fullWidth) {
|
if (limited > _fullWidth) {
|
||||||
const auto shift = (limited - _fullWidth) / 2;
|
const auto shift = (limited - _fullWidth) / 2;
|
||||||
|
@ -463,7 +491,10 @@ QSize SimilarChannels::countOptimalSize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize SimilarChannels::countCurrentSize(int newWidth) {
|
QSize SimilarChannels::countCurrentSize(int newWidth) {
|
||||||
_scrollMax = std::max(_fullWidth - newWidth, 0);
|
if (!_toggled) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
_scrollMax = std::max(int(_fullWidth) - newWidth, 0);
|
||||||
_scrollLeft = std::clamp(_scrollLeft, uint32(), _scrollMax);
|
_scrollLeft = std::clamp(_scrollLeft, uint32(), _scrollMax);
|
||||||
_hasViewAll = (_scrollMax != 0) ? 1 : 0;
|
_hasViewAll = (_scrollMax != 0) ? 1 : 0;
|
||||||
return { newWidth, minHeight() };
|
return { newWidth, minHeight() };
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool isDisplayed() const override {
|
bool isDisplayed() const override {
|
||||||
return !_channels.empty();
|
return !_empty && _toggled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unloadHeavyPart() override;
|
void unloadHeavyPart() override;
|
||||||
|
@ -74,6 +74,7 @@ private:
|
||||||
|
|
||||||
void ensureCacheReady(QSize size) const;
|
void ensureCacheReady(QSize size) const;
|
||||||
void validateParticipansBg(const Channel &channel) const;
|
void validateParticipansBg(const Channel &channel) const;
|
||||||
|
[[nodiscard]] ClickHandlerPtr ensureToggleLink() const;
|
||||||
|
|
||||||
QSize countOptimalSize() override;
|
QSize countOptimalSize() override;
|
||||||
QSize countCurrentSize(int newWidth) override;
|
QSize countCurrentSize(int newWidth) override;
|
||||||
|
@ -83,8 +84,10 @@ private:
|
||||||
mutable std::array<QImage, 4> _roundedCorners;
|
mutable std::array<QImage, 4> _roundedCorners;
|
||||||
mutable QPoint _lastPoint;
|
mutable QPoint _lastPoint;
|
||||||
int _titleWidth = 0;
|
int _titleWidth = 0;
|
||||||
int _viewAllWidth = 0;
|
uint32 _viewAllWidth : 15 = 0;
|
||||||
int _fullWidth = 0;
|
uint32 _fullWidth : 15 = 0;
|
||||||
|
uint32 _empty : 1 = 0;
|
||||||
|
mutable uint32 _toggled : 1 = 0;
|
||||||
uint32 _scrollLeft : 15 = 0;
|
uint32 _scrollLeft : 15 = 0;
|
||||||
uint32 _scrollMax : 15 = 0;
|
uint32 _scrollMax : 15 = 0;
|
||||||
uint32 _hasViewAll : 1 = 0;
|
uint32 _hasViewAll : 1 = 0;
|
||||||
|
@ -92,6 +95,7 @@ private:
|
||||||
|
|
||||||
std::vector<Channel> _channels;
|
std::vector<Channel> _channels;
|
||||||
mutable ClickHandlerPtr _viewAllLink;
|
mutable ClickHandlerPtr _viewAllLink;
|
||||||
|
mutable ClickHandlerPtr _toggleLink;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue