mirror of https://github.com/procxx/kepka.git
Fix feed messages loading both ways.
This commit is contained in:
parent
366ea1edc3
commit
17b913fb13
|
@ -1892,7 +1892,9 @@ void ApiWrap::requestStickers(TimeId now) {
|
||||||
default: Unexpected("Type in ApiWrap::stickersDone()");
|
default: Unexpected("Type in ApiWrap::stickersDone()");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_stickersUpdateRequest = request(MTPmessages_GetAllStickers(MTP_int(Local::countStickersHash(true)))).done(onDone).fail([this, onDone](const RPCError &error) {
|
_stickersUpdateRequest = request(MTPmessages_GetAllStickers(
|
||||||
|
MTP_int(Local::countStickersHash(true))
|
||||||
|
)).done(onDone).fail([this, onDone](const RPCError &error) {
|
||||||
LOG(("App Fail: Failed to get stickers!"));
|
LOG(("App Fail: Failed to get stickers!"));
|
||||||
onDone(MTP_messages_allStickersNotModified());
|
onDone(MTP_messages_allStickersNotModified());
|
||||||
}).send();
|
}).send();
|
||||||
|
@ -2654,7 +2656,7 @@ void ApiWrap::requestFeedMessages(
|
||||||
}
|
}
|
||||||
Unexpected("Direction in PrepareSearchRequest");
|
Unexpected("Direction in PrepareSearchRequest");
|
||||||
}();
|
}();
|
||||||
const auto sourcesHash = int32(0);
|
const auto sourcesHash = int32(0);// feed->channelsHash(); // #TODO
|
||||||
const auto hash = int32(0);
|
const auto hash = int32(0);
|
||||||
const auto flags = (messageId && messageId.fullId.channel)
|
const auto flags = (messageId && messageId.fullId.channel)
|
||||||
? MTPchannels_GetFeed::Flag::f_offset_position
|
? MTPchannels_GetFeed::Flag::f_offset_position
|
||||||
|
@ -2712,13 +2714,11 @@ void ApiWrap::feedMessagesDone(
|
||||||
till = candidate;
|
till = candidate;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto checkPosition = [&](const auto &position) {
|
const auto tooLargePosition = [&](const auto &position) {
|
||||||
if (slice == SliceType::Before && !(position < messageId)) {
|
return (slice == SliceType::Before) && !(position < messageId);
|
||||||
return false;
|
};
|
||||||
} else if (slice == SliceType::After && !(messageId < position)) {
|
const auto tooSmallPosition = [&](const auto &position) {
|
||||||
return false;
|
return (slice == SliceType::After) && !(messageId < position);
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
App::feedUsers(data.vusers);
|
App::feedUsers(data.vusers);
|
||||||
App::feedChats(data.vchats);
|
App::feedChats(data.vchats);
|
||||||
|
@ -2727,7 +2727,11 @@ void ApiWrap::feedMessagesDone(
|
||||||
for (const auto &msg : messages) {
|
for (const auto &msg : messages) {
|
||||||
if (const auto item = App::histories().addNewMessage(msg, type)) {
|
if (const auto item = App::histories().addNewMessage(msg, type)) {
|
||||||
const auto position = item->position();
|
const auto position = item->position();
|
||||||
if (!checkPosition(position)) {
|
if (tooLargePosition(position)) {
|
||||||
|
accumulateTill(noSkipRange.till, position);
|
||||||
|
continue;
|
||||||
|
} else if (tooSmallPosition(position)) {
|
||||||
|
accumulateFrom(noSkipRange.from, position);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ids.push_back(position);
|
ids.push_back(position);
|
||||||
|
@ -2741,14 +2745,14 @@ void ApiWrap::feedMessagesDone(
|
||||||
accumulateFrom(
|
accumulateFrom(
|
||||||
noSkipRange.from,
|
noSkipRange.from,
|
||||||
Data::FeedPositionFromMTP(data.vmin_position));
|
Data::FeedPositionFromMTP(data.vmin_position));
|
||||||
} else {
|
} else if (slice == SliceType::Before) {
|
||||||
noSkipRange.from = Data::MinMessagePosition;
|
noSkipRange.from = Data::MinMessagePosition;
|
||||||
}
|
}
|
||||||
if (data.has_max_position() && !ids.empty()) {
|
if (data.has_max_position() && !ids.empty()) {
|
||||||
accumulateTill(
|
accumulateTill(
|
||||||
noSkipRange.till,
|
noSkipRange.till,
|
||||||
Data::FeedPositionFromMTP(data.vmax_position));
|
Data::FeedPositionFromMTP(data.vmax_position));
|
||||||
} else {
|
} else if (slice == SliceType::After) {
|
||||||
noSkipRange.till = Data::MaxMessagePosition;
|
noSkipRange.till = Data::MaxMessagePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,16 @@ inline const MTPVector<MTPChat> *getChatsFromMessagesChats(const MTPmessages_Cha
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename IntRange>
|
||||||
|
inline int32 CountHash(IntRange &&range) {
|
||||||
|
uint32 acc = 0;
|
||||||
|
for (auto value : range) {
|
||||||
|
acc += (acc * 20261) + uint32(value);
|
||||||
|
}
|
||||||
|
return int32(acc & 0x7FFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
||||||
class ApiWrap : private MTP::Sender, private base::Subscriber {
|
class ApiWrap : private MTP::Sender, private base::Subscriber {
|
||||||
|
|
|
@ -15,6 +15,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "storage/storage_facade.h"
|
#include "storage/storage_facade.h"
|
||||||
#include "storage/storage_feed_messages.h"
|
#include "storage/storage_feed_messages.h"
|
||||||
#include "auth_session.h"
|
#include "auth_session.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "mainwidget.h"
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
|
@ -100,12 +102,13 @@ void Feed::unregisterOne(not_null<ChannelData*> channel) {
|
||||||
_parent->session().storage().remove(
|
_parent->session().storage().remove(
|
||||||
Storage::FeedMessagesRemoveAll(_id, channel->bareId()));
|
Storage::FeedMessagesRemoveAll(_id, channel->bareId()));
|
||||||
|
|
||||||
history->updateChatListExistence();
|
|
||||||
if (visible && _channels.size() < 2) {
|
if (visible && _channels.size() < 2) {
|
||||||
updateChatListExistence();
|
updateChatListExistence();
|
||||||
for (const auto history : _channels) {
|
for (const auto history : _channels) {
|
||||||
history->updateChatListExistence();
|
history->updateChatListExistence();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
history->updateChatListExistence();
|
||||||
}
|
}
|
||||||
_parent->notifyFeedUpdated(this, FeedUpdateFlag::Channels);
|
_parent->notifyFeedUpdated(this, FeedUpdateFlag::Channels);
|
||||||
}
|
}
|
||||||
|
@ -151,6 +154,14 @@ const std::vector<not_null<History*>> &Feed::channels() const {
|
||||||
return _channels;
|
return _channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 Feed::channelsHash() const {
|
||||||
|
return Api::CountHash(ranges::view::all(
|
||||||
|
_channels
|
||||||
|
) | ranges::view::transform([](not_null<History*> history) {
|
||||||
|
return history->peer->bareId();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
bool Feed::justSetLastMessage(not_null<HistoryItem*> item) {
|
bool Feed::justSetLastMessage(not_null<HistoryItem*> item) {
|
||||||
if (_lastMessage && item->position() <= _lastMessage->position()) {
|
if (_lastMessage && item->position() <= _lastMessage->position()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -65,6 +65,7 @@ public:
|
||||||
int size) const override;
|
int size) const override;
|
||||||
|
|
||||||
const std::vector<not_null<History*>> &channels() const;
|
const std::vector<not_null<History*>> &channels() const;
|
||||||
|
int32 channelsHash() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void indexNameParts();
|
void indexNameParts();
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
}
|
}
|
||||||
void updateChatListSortPosition();
|
void updateChatListSortPosition();
|
||||||
void setChatsListDate(const QDateTime &date);
|
void setChatsListDate(const QDateTime &date);
|
||||||
void updateChatListExistence();
|
virtual void updateChatListExistence();
|
||||||
bool needUpdateInChatList() const;
|
bool needUpdateInChatList() const;
|
||||||
|
|
||||||
virtual bool toImportant() const = 0;
|
virtual bool toImportant() const = 0;
|
||||||
|
|
|
@ -707,8 +707,11 @@ void DialogsWidget::searchReceived(
|
||||||
switch (result.type()) {
|
switch (result.type()) {
|
||||||
case mtpc_messages_messages: {
|
case mtpc_messages_messages: {
|
||||||
auto &d = result.c_messages_messages();
|
auto &d = result.c_messages_messages();
|
||||||
App::feedUsers(d.vusers);
|
if (_searchRequest != 0) {
|
||||||
App::feedChats(d.vchats);
|
// Don't apply cached data!
|
||||||
|
App::feedUsers(d.vusers);
|
||||||
|
App::feedChats(d.vchats);
|
||||||
|
}
|
||||||
auto &msgs = d.vmessages.v;
|
auto &msgs = d.vmessages.v;
|
||||||
if (!_inner->searchReceived(msgs, type, msgs.size())) {
|
if (!_inner->searchReceived(msgs, type, msgs.size())) {
|
||||||
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
||||||
|
@ -721,8 +724,11 @@ void DialogsWidget::searchReceived(
|
||||||
|
|
||||||
case mtpc_messages_messagesSlice: {
|
case mtpc_messages_messagesSlice: {
|
||||||
auto &d = result.c_messages_messagesSlice();
|
auto &d = result.c_messages_messagesSlice();
|
||||||
App::feedUsers(d.vusers);
|
if (_searchRequest != 0) {
|
||||||
App::feedChats(d.vchats);
|
// Don't apply cached data!
|
||||||
|
App::feedUsers(d.vusers);
|
||||||
|
App::feedChats(d.vchats);
|
||||||
|
}
|
||||||
auto &msgs = d.vmessages.v;
|
auto &msgs = d.vmessages.v;
|
||||||
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
||||||
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
||||||
|
@ -740,8 +746,11 @@ void DialogsWidget::searchReceived(
|
||||||
} else {
|
} else {
|
||||||
LOG(("API Error: received messages.channelMessages when no channel was passed! (DialogsWidget::searchReceived)"));
|
LOG(("API Error: received messages.channelMessages when no channel was passed! (DialogsWidget::searchReceived)"));
|
||||||
}
|
}
|
||||||
App::feedUsers(d.vusers);
|
if (_searchRequest != 0) {
|
||||||
App::feedChats(d.vchats);
|
// Don't apply cached data!
|
||||||
|
App::feedUsers(d.vusers);
|
||||||
|
App::feedChats(d.vchats);
|
||||||
|
}
|
||||||
auto &msgs = d.vmessages.v;
|
auto &msgs = d.vmessages.v;
|
||||||
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
||||||
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
||||||
|
|
|
@ -2271,6 +2271,19 @@ void History::setLastMessage(HistoryItem *msg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void History::updateChatListExistence() {
|
||||||
|
Entry::updateChatListExistence();
|
||||||
|
if (!lastMsg
|
||||||
|
&& (!loadedAtBottom() || !loadedAtTop())) {
|
||||||
|
if (const auto channel = peer->asChannel()) {
|
||||||
|
if (!channel->feed()) {
|
||||||
|
// After ungrouping from a feed we need to load lastMsg.
|
||||||
|
App::main()->checkPeerHistory(peer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool History::shouldBeInChatList() const {
|
bool History::shouldBeInChatList() const {
|
||||||
if (peer->migrateTo()) {
|
if (peer->migrateTo()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -312,6 +312,7 @@ public:
|
||||||
HistoryItemsList validateForwardDraft();
|
HistoryItemsList validateForwardDraft();
|
||||||
void setForwardDraft(MessageIdsList &&items);
|
void setForwardDraft(MessageIdsList &&items);
|
||||||
|
|
||||||
|
void updateChatListExistence() override;
|
||||||
bool shouldBeInChatList() const override;
|
bool shouldBeInChatList() const override;
|
||||||
bool toImportant() const override {
|
bool toImportant() const override {
|
||||||
return !mute();
|
return !mute();
|
||||||
|
|
|
@ -804,12 +804,12 @@ void ListWidget::checkMoveToOtherViewer() {
|
||||||
+ (visibleHeight / minItemHeight);
|
+ (visibleHeight / minItemHeight);
|
||||||
|
|
||||||
auto preloadBefore = kPreloadIfLessThanScreens * visibleHeight;
|
auto preloadBefore = kPreloadIfLessThanScreens * visibleHeight;
|
||||||
auto after = _slice.skippedAfter;
|
|
||||||
auto preloadTop = (_visibleTop < preloadBefore);
|
|
||||||
auto topLoaded = after && (*after == 0);
|
|
||||||
auto before = _slice.skippedBefore;
|
auto before = _slice.skippedBefore;
|
||||||
|
auto preloadTop = (_visibleTop < preloadBefore);
|
||||||
|
auto topLoaded = before && (*before == 0);
|
||||||
|
auto after = _slice.skippedAfter;
|
||||||
auto preloadBottom = (height() - _visibleBottom < preloadBefore);
|
auto preloadBottom = (height() - _visibleBottom < preloadBefore);
|
||||||
auto bottomLoaded = before && (*before == 0);
|
auto bottomLoaded = after && (*after == 0);
|
||||||
|
|
||||||
auto minScreenDelta = kPreloadedScreensCount
|
auto minScreenDelta = kPreloadedScreensCount
|
||||||
- kPreloadIfLessThanScreens;
|
- kPreloadIfLessThanScreens;
|
||||||
|
|
|
@ -343,7 +343,7 @@ QSize Service::performCountCurrentSize(int newWidth) {
|
||||||
}
|
}
|
||||||
newHeight += st::msgServicePadding.top() + st::msgServicePadding.bottom() + st::msgServiceMargin.top() + st::msgServiceMargin.bottom();
|
newHeight += st::msgServicePadding.top() + st::msgServicePadding.bottom() + st::msgServiceMargin.top() + st::msgServiceMargin.bottom();
|
||||||
if (media) {
|
if (media) {
|
||||||
newHeight += st::msgServiceMargin.top() + media->resizeGetHeight(media->width());
|
newHeight += st::msgServiceMargin.top() + media->resizeGetHeight(media->maxWidth());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1282,6 +1282,7 @@ void MainWidget::checkedHistory(PeerData *peer, const MTPmessages_Messages &resu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
history->updateChatListExistence();
|
||||||
}
|
}
|
||||||
Auth().data().sendHistoryChangeNotifications();
|
Auth().data().sendHistoryChangeNotifications();
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,10 +350,13 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
|
||||||
void Filler::addChannelActions(not_null<ChannelData*> channel) {
|
void Filler::addChannelActions(not_null<ChannelData*> channel) {
|
||||||
auto isGroup = channel->isMegagroup();
|
auto isGroup = channel->isMegagroup();
|
||||||
if (!isGroup) {
|
if (!isGroup) {
|
||||||
const auto grouped = (channel->feed() != nullptr);
|
const auto feed = channel->feed();
|
||||||
_addAction(
|
const auto grouped = (feed != nullptr);
|
||||||
lang(grouped ? lng_feed_ungroup : lng_feed_group),
|
if (!grouped || feed->channels().size() > 1) {
|
||||||
[=] { ToggleChannelGrouping(channel, !grouped); });
|
_addAction(
|
||||||
|
lang(grouped ? lng_feed_ungroup : lng_feed_group),
|
||||||
|
[=] { ToggleChannelGrouping(channel, !grouped); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_source != PeerMenuSource::ChatsList) {
|
if (_source != PeerMenuSource::ChatsList) {
|
||||||
if (ManagePeerBox::Available(channel)) {
|
if (ManagePeerBox::Available(channel)) {
|
||||||
|
|
Loading…
Reference in New Issue