min channels handled, delayed getDifference request with old updDate value added

This commit is contained in:
John Preston 2016-03-11 18:01:32 +03:00
parent 5cab9569c3
commit 02b0512761
3 changed files with 42 additions and 14 deletions

View file

@ -486,6 +486,7 @@ namespace App {
for (QVector<MTPChat>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) {
const MTPchat &chat(*i);
data = 0;
bool minimal = false;
switch (chat.type()) {
case mtpc_chat: {
const MTPDchat &d(chat.c_chat());
@ -566,24 +567,36 @@ namespace App {
const MTPDchannel &d(chat.c_channel());
PeerId peer(peerFromChannel(d.vid.v));
data = App::channel(peer);
data->input = MTP_inputPeerChannel(d.vid, d.vaccess_hash);
minimal = d.is_min();
if (minimal) {
data = App::channelLoaded(peer);
if (!data) {
continue; // minimal is not loaded, need to make getDifference
}
} else {
data = App::channel(peer);
data->input = MTP_inputPeerChannel(d.vid, d.has_access_hash() ? d.vaccess_hash : MTP_long(0));
}
ChannelData *cdata = data->asChannel();
cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash);
if (minimal) {
int32 mask = MTPDchannel::flag_broadcast | MTPDchannel::flag_verified | MTPDchannel::flag_megagroup | MTPDchannel::flag_democracy;
cdata->flags = (cdata->flags & ~mask) | (d.vflags.v & mask);
} else {
cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash);
cdata->access = d.vaccess_hash.v;
cdata->date = d.vdate.v;
cdata->flags = d.vflags.v;
if (cdata->version < d.vversion.v) {
cdata->version = d.vversion.v;
}
}
QString uname = d.has_username() ? textOneLine(qs(d.vusername)) : QString();
cdata->setName(qs(d.vtitle), uname);
cdata->access = d.vaccess_hash.v;
cdata->date = d.vdate.v;
cdata->flags = d.vflags.v;
cdata->isForbidden = false;
cdata->flagsUpdated();
cdata->setPhoto(d.vphoto);
if (cdata->version < d.vversion.v) {
cdata->version = d.vversion.v;
}
} break;
case mtpc_channelForbidden: {
const MTPDchannelForbidden &d(chat.c_channelForbidden());

View file

@ -431,6 +431,7 @@ MainWidget::MainWidget(Window *window) : TWidget(window)
connect(&_idleFinishTimer, SIGNAL(timeout()), this, SLOT(checkIdleFinish()));
connect(&_bySeqTimer, SIGNAL(timeout()), this, SLOT(getDifference()));
connect(&_byPtsTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeByPts()));
connect(&_byMinChannelTimer, SIGNAL(timeout()), this, SLOT(getDifference()));
connect(&_failDifferenceTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeAfterFail()));
connect(_api, SIGNAL(fullPeerUpdated(PeerData*)), this, SLOT(onFullPeerUpdated(PeerData*)));
connect(this, SIGNAL(peerUpdated(PeerData*)), &history, SLOT(peerUpdated(PeerData*)));
@ -2915,8 +2916,12 @@ bool MainWidget::updateFail(const RPCError &e) {
}
void MainWidget::updSetState(int32 pts, int32 date, int32 qts, int32 seq) {
if (pts) _ptsWaiter.init(pts);
if (updDate < date) updDate = date;
if (pts) {
_ptsWaiter.init(pts);
}
if (updDate < date && !_byMinChannelTimer.isActive()) {
updDate = date;
}
if (qts && updQts < qts) {
updQts = qts;
}
@ -4507,7 +4512,13 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_updateNewChannelMessage: {
const MTPDupdateNewChannelMessage &d(update.c_updateNewChannelMessage());
ChannelData *channel = App::channelLoaded(peerToChannel(peerFromMessage(d.vmessage)));
if (!channel && !_ptsWaiter.requesting()) {
MTP_LOG(0, ("getDifference { good - after no channel in updateNewChannelMessage }%1").arg(cTestMode() ? " TESTMODE" : ""));
if (!_byMinChannelTimer.isActive()) { // getDifference after timeout
_byMinChannelTimer.start(WaitForSkippedTimeout);
}
return;
}
if (channel && !_handlingChannelDifference) {
if (channel->ptsRequesting()) { // skip global updates while getting channel difference
return;
@ -4605,7 +4616,9 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_updateChannelTooLong: {
const MTPDupdateChannelTooLong &d(update.c_updateChannelTooLong());
if (ChannelData *channel = App::channelLoaded(d.vchannel_id.v)) {
getChannelDifference(channel);
if (!d.has_pts() || channel->pts() < d.vpts.v) {
getChannelDifference(channel);
}
}
} break;

View file

@ -625,6 +625,8 @@ private:
QMap<int32, MTPUpdates> _bySeqUpdates;
SingleTimer _bySeqTimer;
SingleTimer _byMinChannelTimer;
mtpRequestId _onlineRequest;
SingleTimer _onlineTimer, _onlineUpdater, _idleFinishTimer;
bool _lastWasOnline;