mirror of https://github.com/procxx/kepka.git
Optimize getPeerDialog requests.
This commit is contained in:
parent
2a5bcd3eec
commit
287b3509ab
|
@ -257,26 +257,23 @@ void ApiWrap::getProxyPromotionDelayed(TimeId now, TimeId next) {
|
||||||
};
|
};
|
||||||
|
|
||||||
void ApiWrap::proxyPromotionDone(const MTPhelp_ProxyData &proxy) {
|
void ApiWrap::proxyPromotionDone(const MTPhelp_ProxyData &proxy) {
|
||||||
if (proxy.type() == mtpc_help_proxyDataEmpty) {
|
_proxyPromotionNextRequestTime = proxy.match([&](const auto &data) {
|
||||||
const auto &data = proxy.c_help_proxyDataEmpty();
|
return data.vexpires.v;
|
||||||
const auto next = _proxyPromotionNextRequestTime = data.vexpires.v;
|
});
|
||||||
getProxyPromotionDelayed(unixtime(), next);
|
getProxyPromotionDelayed(unixtime(), _proxyPromotionNextRequestTime);
|
||||||
_session->data().setProxyPromoted(nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Assert(proxy.type() == mtpc_help_proxyDataPromo);
|
|
||||||
const auto &data = proxy.c_help_proxyDataPromo();
|
|
||||||
const auto next = _proxyPromotionNextRequestTime = data.vexpires.v;
|
|
||||||
getProxyPromotionDelayed(unixtime(), next);
|
|
||||||
|
|
||||||
App::feedChats(data.vchats);
|
proxy.match([&](const MTPDhelp_proxyDataEmpty &data) {
|
||||||
App::feedUsers(data.vusers);
|
_session->data().setProxyPromoted(nullptr);
|
||||||
const auto peerId = peerFromMTP(data.vpeer);
|
}, [&](const MTPDhelp_proxyDataPromo &data) {
|
||||||
const auto peer = App::peer(peerId);
|
App::feedChats(data.vchats);
|
||||||
_session->data().setProxyPromoted(peer);
|
App::feedUsers(data.vusers);
|
||||||
if (const auto history = App::historyLoaded(peer)) {
|
const auto peerId = peerFromMTP(data.vpeer);
|
||||||
requestDialogEntry(history);
|
const auto peer = _session->data().peer(peerId);
|
||||||
}
|
_session->data().setProxyPromoted(peer);
|
||||||
|
if (const auto history = App::historyLoaded(peer)) {
|
||||||
|
requestDialogEntry(history);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::requestDeepLinkInfo(
|
void ApiWrap::requestDeepLinkInfo(
|
||||||
|
@ -687,69 +684,78 @@ void ApiWrap::requestDialogEntry(not_null<Data::Feed*> feed) {
|
||||||
void ApiWrap::requestDialogEntry(
|
void ApiWrap::requestDialogEntry(
|
||||||
not_null<History*> history,
|
not_null<History*> history,
|
||||||
Fn<void()> callback) {
|
Fn<void()> callback) {
|
||||||
const auto[i, ok] = _dialogRequests.try_emplace(history);
|
const auto i = _dialogRequests.find(history);
|
||||||
|
if (i != end(_dialogRequests)) {
|
||||||
|
if (callback) {
|
||||||
|
i->second.push_back(std::move(callback));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto [j, ok] = _dialogRequestsPending.try_emplace(history);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
i->second.push_back(std::move(callback));
|
j->second.push_back(std::move(callback));
|
||||||
}
|
}
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (_dialogRequestsPending.size() > 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Core::App().postponeCall(crl::guard(_session, [=] {
|
||||||
|
sendDialogRequests();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApiWrap::sendDialogRequests() {
|
||||||
|
if (_dialogRequestsPending.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto histories = std::vector<not_null<History*>>();
|
||||||
|
ranges::transform(
|
||||||
|
_dialogRequestsPending,
|
||||||
|
ranges::back_inserter(histories),
|
||||||
|
[](const auto &pair) { return pair.first; });
|
||||||
|
auto peers = QVector<MTPInputDialogPeer>();
|
||||||
|
const auto dialogPeer = [](not_null<History*> history) {
|
||||||
|
return MTP_inputDialogPeer(history->peer->input);
|
||||||
|
};
|
||||||
|
ranges::transform(
|
||||||
|
histories,
|
||||||
|
ranges::back_inserter(peers),
|
||||||
|
dialogPeer);
|
||||||
|
for (auto &[history, callbacks] : base::take(_dialogRequestsPending)) {
|
||||||
|
_dialogRequests.emplace(history, std::move(callbacks));
|
||||||
|
}
|
||||||
|
|
||||||
const auto finalize = [=] {
|
const auto finalize = [=] {
|
||||||
if (const auto callbacks = _dialogRequests.take(history)) {
|
for (const auto history : histories) {
|
||||||
for (const auto &callback : *callbacks) {
|
dialogEntryApplied(history);
|
||||||
callback();
|
history->updateChatListExistence();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto peers = QVector<MTPInputDialogPeer>(
|
|
||||||
1,
|
|
||||||
MTP_inputDialogPeer(history->peer->input));
|
|
||||||
request(MTPmessages_GetPeerDialogs(
|
request(MTPmessages_GetPeerDialogs(
|
||||||
MTP_vector(std::move(peers))
|
MTP_vector(std::move(peers))
|
||||||
)).done([=](const MTPmessages_PeerDialogs &result) {
|
)).done([=](const MTPmessages_PeerDialogs &result) {
|
||||||
applyPeerDialogs(result);
|
applyPeerDialogs(result);
|
||||||
history->dialogEntryApplied();
|
|
||||||
finalize();
|
finalize();
|
||||||
}).fail([=](const RPCError &error) {
|
}).fail([=](const RPCError &error) {
|
||||||
finalize();
|
finalize();
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::requestDialogEntries(
|
void ApiWrap::dialogEntryApplied(not_null<History*> history) {
|
||||||
std::vector<not_null<History*>> histories) {
|
history->dialogEntryApplied();
|
||||||
const auto already = [&](not_null<History*> history) {
|
if (const auto callbacks = _dialogRequestsPending.take(history)) {
|
||||||
const auto [i, ok] = _dialogRequests.try_emplace(history);
|
for (const auto &callback : *callbacks) {
|
||||||
return !ok;
|
callback();
|
||||||
};
|
|
||||||
histories.erase(ranges::remove_if(histories, already), end(histories));
|
|
||||||
if (histories.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto peers = QVector<MTPInputDialogPeer>();
|
|
||||||
peers.reserve(histories.size());
|
|
||||||
for (const auto history : histories) {
|
|
||||||
peers.push_back(MTP_inputDialogPeer(history->peer->input));
|
|
||||||
}
|
|
||||||
const auto finalize = [=](std::vector<not_null<History*>> histories) {
|
|
||||||
for (const auto history : histories) {
|
|
||||||
if (const auto callbacks = _dialogRequests.take(history)) {
|
|
||||||
for (const auto &callback : *callbacks) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
request(MTPmessages_GetPeerDialogs(
|
if (const auto callbacks = _dialogRequests.take(history)) {
|
||||||
MTP_vector(std::move(peers))
|
for (const auto &callback : *callbacks) {
|
||||||
)).done([=](const MTPmessages_PeerDialogs &result) {
|
callback();
|
||||||
applyPeerDialogs(result);
|
|
||||||
for (const auto history : histories) {
|
|
||||||
history->dialogEntryApplied();
|
|
||||||
}
|
}
|
||||||
finalize(histories);
|
}
|
||||||
}).fail([=](const RPCError &error) {
|
|
||||||
finalize(histories);
|
|
||||||
}).send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::applyPeerDialogs(const MTPmessages_PeerDialogs &dialogs) {
|
void ApiWrap::applyPeerDialogs(const MTPmessages_PeerDialogs &dialogs) {
|
||||||
|
@ -1490,7 +1496,7 @@ void ApiWrap::applyLastParticipantsList(
|
||||||
Notify::peerUpdatedDelayed(update);
|
Notify::peerUpdatedDelayed(update);
|
||||||
|
|
||||||
channel->mgInfo->botStatus = botStatus;
|
channel->mgInfo->botStatus = botStatus;
|
||||||
if (App::main()) fullPeerUpdated().notify(channel);
|
fullPeerUpdated().notify(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::applyBotsList(
|
void ApiWrap::applyBotsList(
|
||||||
|
@ -1532,7 +1538,7 @@ void ApiWrap::applyBotsList(
|
||||||
}
|
}
|
||||||
|
|
||||||
channel->mgInfo->botStatus = botStatus;
|
channel->mgInfo->botStatus = botStatus;
|
||||||
if (App::main()) fullPeerUpdated().notify(channel);
|
fullPeerUpdated().notify(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::applyAdminsList(
|
void ApiWrap::applyAdminsList(
|
||||||
|
@ -1568,58 +1574,58 @@ void ApiWrap::applyAdminsList(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::requestSelfParticipant(ChannelData *channel) {
|
void ApiWrap::requestSelfParticipant(not_null<ChannelData*> channel) {
|
||||||
if (_selfParticipantRequests.contains(channel)) {
|
if (_selfParticipantRequests.contains(channel)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto requestId = request(MTPchannels_GetParticipant(
|
const auto finalize = [=](UserId inviter, TimeId inviteDate) {
|
||||||
|
channel->inviter = inviter;
|
||||||
|
channel->inviteDate = inviteDate;
|
||||||
|
if (const auto history = App::historyLoaded(channel)) {
|
||||||
|
if (history->lastMessageKnown()) {
|
||||||
|
history->checkJoinedMessage(true);
|
||||||
|
history->owner().sendHistoryChangeNotifications();
|
||||||
|
} else {
|
||||||
|
requestDialogEntry(history);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
_selfParticipantRequests.emplace(channel);
|
||||||
|
request(MTPchannels_GetParticipant(
|
||||||
channel->inputChannel,
|
channel->inputChannel,
|
||||||
MTP_inputUserSelf()
|
MTP_inputUserSelf()
|
||||||
)).done([this, channel](const MTPchannels_ChannelParticipant &result) {
|
)).done([=](const MTPchannels_ChannelParticipant &result) {
|
||||||
_selfParticipantRequests.remove(channel);
|
_selfParticipantRequests.erase(channel);
|
||||||
if (result.type() != mtpc_channels_channelParticipant) {
|
result.match([&](const MTPDchannels_channelParticipant &data) {
|
||||||
LOG(("API Error: unknown type in gotSelfParticipant (%1)").arg(result.type()));
|
App::feedUsers(data.vusers);
|
||||||
channel->inviter = -1;
|
|
||||||
if (App::main()) App::main()->onSelfParticipantUpdated(channel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto &p = result.c_channels_channelParticipant();
|
const auto &participant = data.vparticipant;
|
||||||
App::feedUsers(p.vusers);
|
participant.match([&](const MTPDchannelParticipantSelf &data) {
|
||||||
|
finalize(data.vinviter_id.v, data.vdate.v);
|
||||||
switch (p.vparticipant.type()) {
|
}, [&](const MTPDchannelParticipantCreator &) {
|
||||||
case mtpc_channelParticipantSelf: {
|
if (channel->mgInfo) {
|
||||||
auto &d = p.vparticipant.c_channelParticipantSelf();
|
channel->mgInfo->creator = _session->user();
|
||||||
channel->inviter = d.vinviter_id.v;
|
}
|
||||||
channel->inviteDate = d.vdate.v;
|
finalize(_session->userId(), channel->date);
|
||||||
} break;
|
}, [&](const MTPDchannelParticipantAdmin &data) {
|
||||||
case mtpc_channelParticipantCreator: {
|
const auto inviter = (data.is_self()
|
||||||
auto &d = p.vparticipant.c_channelParticipantCreator();
|
&& data.has_inviter_id())
|
||||||
channel->inviter = _session->userId();
|
? data.vinviter_id.v
|
||||||
channel->inviteDate = channel->date;
|
: -1;
|
||||||
if (channel->mgInfo) {
|
finalize(inviter, data.vdate.v);
|
||||||
channel->mgInfo->creator = _session->user();
|
}, [&](const MTPDchannelParticipantBanned &data) {
|
||||||
}
|
LOG(("API Error: Got self banned participant."));
|
||||||
} break;
|
finalize(-1, 0);
|
||||||
case mtpc_channelParticipantAdmin: {
|
}, [&](const MTPDchannelParticipant &data) {
|
||||||
auto &d = p.vparticipant.c_channelParticipantAdmin();
|
LOG(("API Error: Got self regular participant."));
|
||||||
channel->inviter = (d.is_self() && d.has_inviter_id())
|
finalize(-1, 0);
|
||||||
? d.vinviter_id.v
|
});
|
||||||
: 0;
|
});
|
||||||
channel->inviteDate = d.vdate.v;
|
}).fail([=](const RPCError &error) {
|
||||||
} break;
|
_selfParticipantRequests.erase(channel);
|
||||||
}
|
finalize(-1, 0);
|
||||||
|
|
||||||
if (App::main()) App::main()->onSelfParticipantUpdated(channel);
|
|
||||||
}).fail([this, channel](const RPCError &error) {
|
|
||||||
_selfParticipantRequests.remove(channel);
|
|
||||||
if (error.type() == qstr("USER_NOT_PARTICIPANT")) {
|
|
||||||
channel->inviter = -1;
|
|
||||||
}
|
|
||||||
}).afterDelay(kSmallDelayMs).send();
|
}).afterDelay(kSmallDelayMs).send();
|
||||||
|
|
||||||
_selfParticipantRequests.insert(channel, requestId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::kickParticipant(
|
void ApiWrap::kickParticipant(
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
void requestDialogEntry(
|
void requestDialogEntry(
|
||||||
not_null<History*> history,
|
not_null<History*> history,
|
||||||
Fn<void()> callback = nullptr);
|
Fn<void()> callback = nullptr);
|
||||||
void requestDialogEntries(std::vector<not_null<History*>> histories);
|
void dialogEntryApplied(not_null<History*> history);
|
||||||
//void applyFeedSources(const MTPDchannels_feedSources &data); // #feed
|
//void applyFeedSources(const MTPDchannels_feedSources &data); // #feed
|
||||||
//void setFeedChannels(
|
//void setFeedChannels(
|
||||||
// not_null<Data::Feed*> feed,
|
// not_null<Data::Feed*> feed,
|
||||||
|
@ -146,7 +146,7 @@ public:
|
||||||
void markMediaRead(const base::flat_set<not_null<HistoryItem*>> &items);
|
void markMediaRead(const base::flat_set<not_null<HistoryItem*>> &items);
|
||||||
void markMediaRead(not_null<HistoryItem*> item);
|
void markMediaRead(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
void requestSelfParticipant(ChannelData *channel);
|
void requestSelfParticipant(not_null<ChannelData*> channel);
|
||||||
void kickParticipant(not_null<ChatData*> chat, not_null<UserData*> user);
|
void kickParticipant(not_null<ChatData*> chat, not_null<UserData*> user);
|
||||||
void kickParticipant(
|
void kickParticipant(
|
||||||
not_null<ChannelData*> channel,
|
not_null<ChannelData*> channel,
|
||||||
|
@ -592,6 +592,8 @@ private:
|
||||||
not_null<ChannelData*> channel);
|
not_null<ChannelData*> channel);
|
||||||
void migrateFail(not_null<PeerData*> peer, const RPCError &error);
|
void migrateFail(not_null<PeerData*> peer, const RPCError &error);
|
||||||
|
|
||||||
|
void sendDialogRequests();
|
||||||
|
|
||||||
not_null<AuthSession*> _session;
|
not_null<AuthSession*> _session;
|
||||||
|
|
||||||
MessageDataRequests _messageDataRequests;
|
MessageDataRequests _messageDataRequests;
|
||||||
|
@ -624,7 +626,7 @@ private:
|
||||||
not_null<PeerData*>,
|
not_null<PeerData*>,
|
||||||
mtpRequestId> _defaultRestrictionsRequests;
|
mtpRequestId> _defaultRestrictionsRequests;
|
||||||
|
|
||||||
QMap<ChannelData*, mtpRequestId> _selfParticipantRequests;
|
base::flat_set<not_null<ChannelData*>> _selfParticipantRequests;
|
||||||
|
|
||||||
base::flat_map<
|
base::flat_map<
|
||||||
not_null<ChannelData*>,
|
not_null<ChannelData*>,
|
||||||
|
@ -666,6 +668,9 @@ private:
|
||||||
base::flat_map<
|
base::flat_map<
|
||||||
not_null<History*>,
|
not_null<History*>,
|
||||||
std::vector<Fn<void()>>> _dialogRequests;
|
std::vector<Fn<void()>>> _dialogRequests;
|
||||||
|
base::flat_map<
|
||||||
|
not_null<History*>,
|
||||||
|
std::vector<Fn<void()>>> _dialogRequestsPending;
|
||||||
base::flat_set<not_null<History*>> _fakeChatListRequests;
|
base::flat_set<not_null<History*>> _fakeChatListRequests;
|
||||||
|
|
||||||
base::flat_map<not_null<History*>, mtpRequestId> _unreadMentionsRequests;
|
base::flat_map<not_null<History*>, mtpRequestId> _unreadMentionsRequests;
|
||||||
|
|
|
@ -1298,14 +1298,14 @@ void DialogsInner::createDialog(Dialogs::Key key) {
|
||||||
|
|
||||||
const auto from = dialogsOffset() + changed.movedFrom * st::dialogsRowHeight;
|
const auto from = dialogsOffset() + changed.movedFrom * st::dialogsRowHeight;
|
||||||
const auto to = dialogsOffset() + changed.movedTo * st::dialogsRowHeight;
|
const auto to = dialogsOffset() + changed.movedTo * st::dialogsRowHeight;
|
||||||
if (!_dragging) {
|
if (!_dragging && from != to) {
|
||||||
// Don't jump in chats list scroll position while dragging.
|
// Don't jump in chats list scroll position while dragging.
|
||||||
emit dialogMoved(from, to);
|
emit dialogMoved(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (creating) {
|
if (creating) {
|
||||||
refresh();
|
refresh();
|
||||||
} else if (_state == State::Default && changed.movedFrom != changed.movedTo) {
|
} else if (_state == State::Default && from != to) {
|
||||||
update(0, qMin(from, to), getFullWidth(), qAbs(from - to) + st::dialogsRowHeight);
|
update(0, qMin(from, to), getFullWidth(), qAbs(from - to) + st::dialogsRowHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1948,7 +1948,6 @@ bool DialogsInner::searchReceived(
|
||||||
auto isGlobalSearch = (type == DialogsSearchFromStart || type == DialogsSearchFromOffset);
|
auto isGlobalSearch = (type == DialogsSearchFromStart || type == DialogsSearchFromOffset);
|
||||||
auto isMigratedSearch = (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset);
|
auto isMigratedSearch = (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset);
|
||||||
|
|
||||||
auto unknownUnreadCounts = std::vector<not_null<History*>>();
|
|
||||||
TimeId lastDateFound = 0;
|
TimeId lastDateFound = 0;
|
||||||
for (const auto &message : messages) {
|
for (const auto &message : messages) {
|
||||||
auto msgId = IdFromMessage(message);
|
auto msgId = IdFromMessage(message);
|
||||||
|
@ -1966,7 +1965,7 @@ bool DialogsInner::searchReceived(
|
||||||
_searchInChat,
|
_searchInChat,
|
||||||
item));
|
item));
|
||||||
if (uniquePeers && !history->unreadCountKnown()) {
|
if (uniquePeers && !history->unreadCountKnown()) {
|
||||||
unknownUnreadCounts.push_back(history);
|
history->session().api().requestDialogEntry(history);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastDateFound = lastDate;
|
lastDateFound = lastDate;
|
||||||
|
@ -2001,9 +2000,6 @@ bool DialogsInner::searchReceived(
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
if (!unknownUnreadCounts.empty()) {
|
|
||||||
Auth().api().requestDialogEntries(std::move(unknownUnreadCounts));
|
|
||||||
}
|
|
||||||
return lastDateFound != 0;
|
return lastDateFound != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2123,16 +2119,15 @@ void DialogsInner::notify_historyMuteUpdated(History *history) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int from = dialogsOffset() + changed.movedFrom * st::dialogsRowHeight;
|
const auto from = dialogsOffset() + changed.movedFrom * st::dialogsRowHeight;
|
||||||
int to = dialogsOffset() + changed.movedTo * st::dialogsRowHeight;
|
const auto to = dialogsOffset() + changed.movedTo * st::dialogsRowHeight;
|
||||||
if (!_dragging) {
|
if (!_dragging && from != to) {
|
||||||
// Don't jump in chats list scroll position while dragging.
|
// Don't jump in chats list scroll position while dragging.
|
||||||
emit dialogMoved(from, to);
|
emit dialogMoved(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (creating) {
|
if (creating) {
|
||||||
refresh();
|
refresh();
|
||||||
} else if (_state == State::Default && changed.movedFrom != changed.movedTo) {
|
} else if (_state == State::Default && from != to) {
|
||||||
update(0, qMin(from, to), getFullWidth(), qAbs(from - to) + st::dialogsRowHeight);
|
update(0, qMin(from, to), getFullWidth(), qAbs(from - to) + st::dialogsRowHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,36 +481,29 @@ void DialogsWidget::updateDialogsOffset(
|
||||||
auto lastDate = TimeId(0);
|
auto lastDate = TimeId(0);
|
||||||
auto lastPeer = PeerId(0);
|
auto lastPeer = PeerId(0);
|
||||||
auto lastMsgId = MsgId(0);
|
auto lastMsgId = MsgId(0);
|
||||||
const auto fillFromDialog = [&](const auto &dialog) {
|
for (const auto &dialog : ranges::view::reverse(dialogs)) {
|
||||||
const auto peer = peerFromMTP(dialog.vpeer);
|
dialog.match([&](const auto &dialog) {
|
||||||
const auto msgId = dialog.vtop_message.v;
|
const auto peer = peerFromMTP(dialog.vpeer);
|
||||||
if (!peer || !msgId) {
|
const auto messageId = dialog.vtop_message.v;
|
||||||
return;
|
if (!peer || !messageId) {
|
||||||
}
|
|
||||||
if (!lastPeer) {
|
|
||||||
lastPeer = peer;
|
|
||||||
}
|
|
||||||
if (!lastMsgId) {
|
|
||||||
lastMsgId = msgId;
|
|
||||||
}
|
|
||||||
for (auto j = messages.size(); j != 0;) {
|
|
||||||
const auto &message = messages[--j];
|
|
||||||
if (IdFromMessage(message) == msgId
|
|
||||||
&& PeerFromMessage(message) == peer) {
|
|
||||||
if (const auto date = DateFromMessage(message)) {
|
|
||||||
lastDate = date;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
if (!lastPeer) {
|
||||||
};
|
lastPeer = peer;
|
||||||
for (auto i = dialogs.size(); i != 0;) {
|
}
|
||||||
const auto &dialog = dialogs[--i];
|
if (!lastMsgId) {
|
||||||
switch (dialog.type()) {
|
lastMsgId = messageId;
|
||||||
case mtpc_dialog: fillFromDialog(dialog.c_dialog()); break;
|
}
|
||||||
// case mtpc_dialogFeed: fillFromDialog(dialog.c_dialogFeed()); break; // #feed
|
for (const auto &message : ranges::view::reverse(messages)) {
|
||||||
default: Unexpected("Type in DialogsWidget::updateDialogsOffset");
|
if (IdFromMessage(message) == messageId
|
||||||
}
|
&& PeerFromMessage(message) == peer) {
|
||||||
|
if (const auto date = DateFromMessage(message)) {
|
||||||
|
lastDate = date;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
if (lastDate) {
|
if (lastDate) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
#include "application.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "observer_peer.h"
|
#include "observer_peer.h"
|
||||||
|
@ -2178,7 +2179,9 @@ void History::setChatListMessageFromLast() {
|
||||||
|
|
||||||
void History::requestChatListMessage() {
|
void History::requestChatListMessage() {
|
||||||
if (!lastMessageKnown()) {
|
if (!lastMessageKnown()) {
|
||||||
session().api().requestDialogEntry(this);
|
session().api().requestDialogEntry(this, [=] {
|
||||||
|
requestChatListMessage();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
} else if (chatListMessageKnown()) {
|
} else if (chatListMessageKnown()) {
|
||||||
return;
|
return;
|
||||||
|
@ -2336,13 +2339,16 @@ void History::applyDialog(const MTPDdialog &data) {
|
||||||
if (data.has_draft() && data.vdraft.type() == mtpc_draftMessage) {
|
if (data.has_draft() && data.vdraft.type() == mtpc_draftMessage) {
|
||||||
Data::applyPeerCloudDraft(peer->id, data.vdraft.c_draftMessage());
|
Data::applyPeerCloudDraft(peer->id, data.vdraft.c_draftMessage());
|
||||||
}
|
}
|
||||||
|
session().api().dialogEntryApplied(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void History::dialogEntryApplied() {
|
void History::dialogEntryApplied() {
|
||||||
if (!lastMessageKnown()) {
|
if (!lastMessageKnown()) {
|
||||||
setLastMessage(nullptr);
|
setLastMessage(nullptr);
|
||||||
}
|
}
|
||||||
if (!chatListMessageKnown()) {
|
if (peer->migrateTo()) {
|
||||||
|
return;
|
||||||
|
} else if (!chatListMessageKnown()) {
|
||||||
requestChatListMessage();
|
requestChatListMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2371,7 +2377,7 @@ void History::dialogEntryApplied() {
|
||||||
if (chatListTimeId() != 0 && loadedAtBottom()) {
|
if (chatListTimeId() != 0 && loadedAtBottom()) {
|
||||||
if (const auto channel = peer->asChannel()) {
|
if (const auto channel = peer->asChannel()) {
|
||||||
const auto inviter = channel->inviter;
|
const auto inviter = channel->inviter;
|
||||||
if (inviter != 0
|
if (inviter > 0
|
||||||
&& chatListTimeId() <= channel->inviteDate
|
&& chatListTimeId() <= channel->inviteDate
|
||||||
&& channel->amIn()) {
|
&& channel->amIn()) {
|
||||||
if (const auto from = App::userLoaded(inviter)) {
|
if (const auto from = App::userLoaded(inviter)) {
|
||||||
|
@ -2380,7 +2386,6 @@ void History::dialogEntryApplied() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateChatListExistence();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool History::clearUnreadOnClientSide() const {
|
bool History::clearUnreadOnClientSide() const {
|
||||||
|
|
|
@ -306,7 +306,7 @@ void NotificationsController::applyFeedDialogs(
|
||||||
const auto history = App::history(peerId);
|
const auto history = App::history(peerId);
|
||||||
const auto channel = history->peer->asChannel();
|
const auto channel = history->peer->asChannel();
|
||||||
history->applyDialog(dialog.c_dialog());
|
history->applyDialog(dialog.c_dialog());
|
||||||
channels.push_back(channel);
|
channels.emplace_back(channel);
|
||||||
} else {
|
} else {
|
||||||
LOG(("API Error: "
|
LOG(("API Error: "
|
||||||
"Unexpected non-channel in feed dialogs list."));
|
"Unexpected non-channel in feed dialogs list."));
|
||||||
|
|
|
@ -3305,24 +3305,6 @@ void MainWidget::openPeerByName(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::onSelfParticipantUpdated(ChannelData *channel) {
|
|
||||||
auto history = App::historyLoaded(channel->id);
|
|
||||||
if (_updatedChannels.contains(channel)) {
|
|
||||||
_updatedChannels.remove(channel);
|
|
||||||
if (!history) {
|
|
||||||
history = App::history(channel);
|
|
||||||
}
|
|
||||||
if (history->isEmpty()) {
|
|
||||||
Auth().api().requestDialogEntry(history);
|
|
||||||
} else {
|
|
||||||
history->checkJoinedMessage(true);
|
|
||||||
}
|
|
||||||
} else if (history) {
|
|
||||||
history->checkJoinedMessage();
|
|
||||||
}
|
|
||||||
Auth().data().sendHistoryChangeNotifications();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWidget::contentOverlapped(const QRect &globalRect) {
|
bool MainWidget::contentOverlapped(const QRect &globalRect) {
|
||||||
return (_history->contentOverlapped(globalRect)
|
return (_history->contentOverlapped(globalRect)
|
||||||
|| _playerPanel->overlaps(globalRect)
|
|| _playerPanel->overlaps(globalRect)
|
||||||
|
@ -4461,22 +4443,21 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||||
auto &d = update.c_updateChannel();
|
auto &d = update.c_updateChannel();
|
||||||
if (const auto channel = App::channelLoaded(d.vchannel_id.v)) {
|
if (const auto channel = App::channelLoaded(d.vchannel_id.v)) {
|
||||||
channel->inviter = UserId(0);
|
channel->inviter = UserId(0);
|
||||||
if (channel->amIn()
|
if (channel->amIn()) {
|
||||||
&& !channel->amCreator()
|
const auto history = App::history(channel);
|
||||||
&& App::history(channel->id)) {
|
if (const auto feed = channel->feed()) {
|
||||||
_updatedChannels.insert(channel, true);
|
feed->requestChatListMessage();
|
||||||
Auth().api().requestSelfParticipant(channel);
|
if (!feed->unreadCountKnown()) {
|
||||||
}
|
feed->session().api().requestDialogEntry(feed);
|
||||||
if (const auto feed = channel->feed()) {
|
}
|
||||||
feed->requestChatListMessage();
|
} else {
|
||||||
if (!feed->unreadCountKnown()) {
|
history->requestChatListMessage();
|
||||||
feed->session().api().requestDialogEntry(feed);
|
if (!history->unreadCountKnown()) {
|
||||||
|
history->session().api().requestDialogEntry(history);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (channel->amIn()) {
|
if (!channel->amCreator()) {
|
||||||
const auto history = App::history(channel->id);
|
Auth().api().requestSelfParticipant(channel);
|
||||||
history->requestChatListMessage();
|
|
||||||
if (!history->unreadCountKnown()) {
|
|
||||||
history->session().api().requestDialogEntry(history);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,6 @@ public:
|
||||||
|
|
||||||
void scheduleViewIncrement(HistoryItem *item);
|
void scheduleViewIncrement(HistoryItem *item);
|
||||||
|
|
||||||
void onSelfParticipantUpdated(ChannelData *channel);
|
|
||||||
void feedChannelDifference(const MTPDupdates_channelDifference &data);
|
void feedChannelDifference(const MTPDupdates_channelDifference &data);
|
||||||
|
|
||||||
// Mayde public for ApiWrap, while it is still here.
|
// Mayde public for ApiWrap, while it is still here.
|
||||||
|
@ -537,9 +536,6 @@ private:
|
||||||
int _cachedY = 0;
|
int _cachedY = 0;
|
||||||
SingleTimer _cacheBackgroundTimer;
|
SingleTimer _cacheBackgroundTimer;
|
||||||
|
|
||||||
typedef QMap<ChannelData*, bool> UpdatedChannels;
|
|
||||||
UpdatedChannels _updatedChannels;
|
|
||||||
|
|
||||||
PhotoData *_deletingPhoto = nullptr;
|
PhotoData *_deletingPhoto = nullptr;
|
||||||
|
|
||||||
typedef QMap<MsgId, bool> ViewsIncrementMap;
|
typedef QMap<MsgId, bool> ViewsIncrementMap;
|
||||||
|
|
Loading…
Reference in New Issue