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()");
|
||||
}
|
||||
};
|
||||
_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!"));
|
||||
onDone(MTP_messages_allStickersNotModified());
|
||||
}).send();
|
||||
|
@ -2654,7 +2656,7 @@ void ApiWrap::requestFeedMessages(
|
|||
}
|
||||
Unexpected("Direction in PrepareSearchRequest");
|
||||
}();
|
||||
const auto sourcesHash = int32(0);
|
||||
const auto sourcesHash = int32(0);// feed->channelsHash(); // #TODO
|
||||
const auto hash = int32(0);
|
||||
const auto flags = (messageId && messageId.fullId.channel)
|
||||
? MTPchannels_GetFeed::Flag::f_offset_position
|
||||
|
@ -2712,13 +2714,11 @@ void ApiWrap::feedMessagesDone(
|
|||
till = candidate;
|
||||
}
|
||||
};
|
||||
const auto checkPosition = [&](const auto &position) {
|
||||
if (slice == SliceType::Before && !(position < messageId)) {
|
||||
return false;
|
||||
} else if (slice == SliceType::After && !(messageId < position)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
const auto tooLargePosition = [&](const auto &position) {
|
||||
return (slice == SliceType::Before) && !(position < messageId);
|
||||
};
|
||||
const auto tooSmallPosition = [&](const auto &position) {
|
||||
return (slice == SliceType::After) && !(messageId < position);
|
||||
};
|
||||
App::feedUsers(data.vusers);
|
||||
App::feedChats(data.vchats);
|
||||
|
@ -2727,7 +2727,11 @@ void ApiWrap::feedMessagesDone(
|
|||
for (const auto &msg : messages) {
|
||||
if (const auto item = App::histories().addNewMessage(msg, type)) {
|
||||
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;
|
||||
}
|
||||
ids.push_back(position);
|
||||
|
@ -2741,14 +2745,14 @@ void ApiWrap::feedMessagesDone(
|
|||
accumulateFrom(
|
||||
noSkipRange.from,
|
||||
Data::FeedPositionFromMTP(data.vmin_position));
|
||||
} else {
|
||||
} else if (slice == SliceType::Before) {
|
||||
noSkipRange.from = Data::MinMessagePosition;
|
||||
}
|
||||
if (data.has_max_position() && !ids.empty()) {
|
||||
accumulateTill(
|
||||
noSkipRange.till,
|
||||
Data::FeedPositionFromMTP(data.vmax_position));
|
||||
} else {
|
||||
} else if (slice == SliceType::After) {
|
||||
noSkipRange.till = Data::MaxMessagePosition;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,16 @@ inline const MTPVector<MTPChat> *getChatsFromMessagesChats(const MTPmessages_Cha
|
|||
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
|
||||
|
||||
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_feed_messages.h"
|
||||
#include "auth_session.h"
|
||||
#include "apiwrap.h"
|
||||
#include "mainwidget.h"
|
||||
|
||||
namespace Data {
|
||||
|
||||
|
@ -100,12 +102,13 @@ void Feed::unregisterOne(not_null<ChannelData*> channel) {
|
|||
_parent->session().storage().remove(
|
||||
Storage::FeedMessagesRemoveAll(_id, channel->bareId()));
|
||||
|
||||
history->updateChatListExistence();
|
||||
if (visible && _channels.size() < 2) {
|
||||
updateChatListExistence();
|
||||
for (const auto history : _channels) {
|
||||
history->updateChatListExistence();
|
||||
}
|
||||
} else {
|
||||
history->updateChatListExistence();
|
||||
}
|
||||
_parent->notifyFeedUpdated(this, FeedUpdateFlag::Channels);
|
||||
}
|
||||
|
@ -151,6 +154,14 @@ const std::vector<not_null<History*>> &Feed::channels() const {
|
|||
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) {
|
||||
if (_lastMessage && item->position() <= _lastMessage->position()) {
|
||||
return false;
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
int size) const override;
|
||||
|
||||
const std::vector<not_null<History*>> &channels() const;
|
||||
int32 channelsHash() const;
|
||||
|
||||
private:
|
||||
void indexNameParts();
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
}
|
||||
void updateChatListSortPosition();
|
||||
void setChatsListDate(const QDateTime &date);
|
||||
void updateChatListExistence();
|
||||
virtual void updateChatListExistence();
|
||||
bool needUpdateInChatList() const;
|
||||
|
||||
virtual bool toImportant() const = 0;
|
||||
|
|
|
@ -707,8 +707,11 @@ void DialogsWidget::searchReceived(
|
|||
switch (result.type()) {
|
||||
case mtpc_messages_messages: {
|
||||
auto &d = result.c_messages_messages();
|
||||
App::feedUsers(d.vusers);
|
||||
App::feedChats(d.vchats);
|
||||
if (_searchRequest != 0) {
|
||||
// Don't apply cached data!
|
||||
App::feedUsers(d.vusers);
|
||||
App::feedChats(d.vchats);
|
||||
}
|
||||
auto &msgs = d.vmessages.v;
|
||||
if (!_inner->searchReceived(msgs, type, msgs.size())) {
|
||||
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
||||
|
@ -721,8 +724,11 @@ void DialogsWidget::searchReceived(
|
|||
|
||||
case mtpc_messages_messagesSlice: {
|
||||
auto &d = result.c_messages_messagesSlice();
|
||||
App::feedUsers(d.vusers);
|
||||
App::feedChats(d.vchats);
|
||||
if (_searchRequest != 0) {
|
||||
// Don't apply cached data!
|
||||
App::feedUsers(d.vusers);
|
||||
App::feedChats(d.vchats);
|
||||
}
|
||||
auto &msgs = d.vmessages.v;
|
||||
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
||||
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
||||
|
@ -740,8 +746,11 @@ void DialogsWidget::searchReceived(
|
|||
} else {
|
||||
LOG(("API Error: received messages.channelMessages when no channel was passed! (DialogsWidget::searchReceived)"));
|
||||
}
|
||||
App::feedUsers(d.vusers);
|
||||
App::feedChats(d.vchats);
|
||||
if (_searchRequest != 0) {
|
||||
// Don't apply cached data!
|
||||
App::feedUsers(d.vusers);
|
||||
App::feedChats(d.vchats);
|
||||
}
|
||||
auto &msgs = d.vmessages.v;
|
||||
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
||||
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 {
|
||||
if (peer->migrateTo()) {
|
||||
return false;
|
||||
|
|
|
@ -312,6 +312,7 @@ public:
|
|||
HistoryItemsList validateForwardDraft();
|
||||
void setForwardDraft(MessageIdsList &&items);
|
||||
|
||||
void updateChatListExistence() override;
|
||||
bool shouldBeInChatList() const override;
|
||||
bool toImportant() const override {
|
||||
return !mute();
|
||||
|
|
|
@ -804,12 +804,12 @@ void ListWidget::checkMoveToOtherViewer() {
|
|||
+ (visibleHeight / minItemHeight);
|
||||
|
||||
auto preloadBefore = kPreloadIfLessThanScreens * visibleHeight;
|
||||
auto after = _slice.skippedAfter;
|
||||
auto preloadTop = (_visibleTop < preloadBefore);
|
||||
auto topLoaded = after && (*after == 0);
|
||||
auto before = _slice.skippedBefore;
|
||||
auto preloadTop = (_visibleTop < preloadBefore);
|
||||
auto topLoaded = before && (*before == 0);
|
||||
auto after = _slice.skippedAfter;
|
||||
auto preloadBottom = (height() - _visibleBottom < preloadBefore);
|
||||
auto bottomLoaded = before && (*before == 0);
|
||||
auto bottomLoaded = after && (*after == 0);
|
||||
|
||||
auto minScreenDelta = kPreloadedScreensCount
|
||||
- kPreloadIfLessThanScreens;
|
||||
|
|
|
@ -343,7 +343,7 @@ QSize Service::performCountCurrentSize(int newWidth) {
|
|||
}
|
||||
newHeight += st::msgServicePadding.top() + st::msgServicePadding.bottom() + st::msgServiceMargin.top() + st::msgServiceMargin.bottom();
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -350,10 +350,13 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
|
|||
void Filler::addChannelActions(not_null<ChannelData*> channel) {
|
||||
auto isGroup = channel->isMegagroup();
|
||||
if (!isGroup) {
|
||||
const auto grouped = (channel->feed() != nullptr);
|
||||
_addAction(
|
||||
lang(grouped ? lng_feed_ungroup : lng_feed_group),
|
||||
[=] { ToggleChannelGrouping(channel, !grouped); });
|
||||
const auto feed = channel->feed();
|
||||
const auto grouped = (feed != nullptr);
|
||||
if (!grouped || feed->channels().size() > 1) {
|
||||
_addAction(
|
||||
lang(grouped ? lng_feed_ungroup : lng_feed_group),
|
||||
[=] { ToggleChannelGrouping(channel, !grouped); });
|
||||
}
|
||||
}
|
||||
if (_source != PeerMenuSource::ChatsList) {
|
||||
if (ManagePeerBox::Available(channel)) {
|
||||
|
|
Loading…
Reference in New Issue