mirror of https://github.com/procxx/kepka.git
Requesting getDifference if some users or channels are not loaded
while processing updateNewChannelMessage update.
This commit is contained in:
parent
13310206fa
commit
80b0667ff9
|
@ -399,7 +399,7 @@ void ApiWrap::requestLastParticipants(ChannelData *peer, bool fromStart) {
|
||||||
if ((needAdmins && adminsOutdated) || peer->lastParticipantsCountOutdated()) {
|
if ((needAdmins && adminsOutdated) || peer->lastParticipantsCountOutdated()) {
|
||||||
fromStart = true;
|
fromStart = true;
|
||||||
}
|
}
|
||||||
QMap<PeerData*, mtpRequestId>::iterator i = _participantsRequests.find(peer);
|
auto i = _participantsRequests.find(peer);
|
||||||
if (i != _participantsRequests.cend()) {
|
if (i != _participantsRequests.cend()) {
|
||||||
if (fromStart && i.value() < 0) { // was not loading from start
|
if (fromStart && i.value() < 0) { // was not loading from start
|
||||||
_participantsRequests.erase(i);
|
_participantsRequests.erase(i);
|
||||||
|
|
|
@ -145,6 +145,7 @@ inline MTPMessagesFilter typeToMediaFilter(MediaOverviewType &type) {
|
||||||
case OverviewFiles: return MTP_inputMessagesFilterDocument();
|
case OverviewFiles: return MTP_inputMessagesFilterDocument();
|
||||||
case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice();
|
case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice();
|
||||||
case OverviewLinks: return MTP_inputMessagesFilterUrl();
|
case OverviewLinks: return MTP_inputMessagesFilterUrl();
|
||||||
|
case OverviewCount: break;
|
||||||
default: type = OverviewCount; break;
|
default: type = OverviewCount; break;
|
||||||
}
|
}
|
||||||
return MTPMessagesFilter();
|
return MTPMessagesFilter();
|
||||||
|
@ -1756,7 +1757,7 @@ inline MediaOverviewType mediaToOverviewType(HistoryMedia *media) {
|
||||||
case MediaTypeMusicFile: return media->getDocument()->isMusic() ? OverviewMusicFiles : OverviewFiles;
|
case MediaTypeMusicFile: return media->getDocument()->isMusic() ? OverviewMusicFiles : OverviewFiles;
|
||||||
case MediaTypeVoiceFile: return OverviewVoiceFiles;
|
case MediaTypeVoiceFile: return OverviewVoiceFiles;
|
||||||
case MediaTypeGif: return media->getDocument()->isGifv() ? OverviewCount : OverviewFiles;
|
case MediaTypeGif: return media->getDocument()->isGifv() ? OverviewCount : OverviewFiles;
|
||||||
// case MediaTypeSticker: return OverviewFiles;
|
default: break;
|
||||||
}
|
}
|
||||||
return OverviewCount;
|
return OverviewCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3579,6 +3579,9 @@ void MainWidget::openPeerByName(const QString &username, MsgId msgId, const QStr
|
||||||
if (peer->isUser() && peer->asUser()->botInfo && !peer->asUser()->botInfo->cantJoinGroups && !startToken.isEmpty()) {
|
if (peer->isUser() && peer->asUser()->botInfo && !peer->asUser()->botInfo->cantJoinGroups && !startToken.isEmpty()) {
|
||||||
peer->asUser()->botInfo->startGroupToken = startToken;
|
peer->asUser()->botInfo->startGroupToken = startToken;
|
||||||
Ui::showLayer(new ContactsBox(peer->asUser()));
|
Ui::showLayer(new ContactsBox(peer->asUser()));
|
||||||
|
} else if (peer->isUser() && peer->asUser()->botInfo) {
|
||||||
|
// Always open bot chats, even from mention links.
|
||||||
|
Ui::showPeerHistoryAsync(peer->id, ShowAtUnreadMsgId);
|
||||||
} else {
|
} else {
|
||||||
showPeerProfile(peer);
|
showPeerProfile(peer);
|
||||||
}
|
}
|
||||||
|
@ -4242,6 +4245,73 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
enum class DataIsLoadedResult {
|
||||||
|
NotLoaded = 0,
|
||||||
|
FromNotLoaded = 1,
|
||||||
|
Ok = 2,
|
||||||
|
};
|
||||||
|
DataIsLoadedResult allDataLoadedForMessage(const MTPMessage &msg) {
|
||||||
|
switch (msg.type()) {
|
||||||
|
case mtpc_message: {
|
||||||
|
const MTPDmessage &d(msg.c_message());
|
||||||
|
if (!d.is_post() && d.has_from_id()) {
|
||||||
|
if (!App::userLoaded(peerFromUser(d.vfrom_id))) {
|
||||||
|
return DataIsLoadedResult::FromNotLoaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d.has_via_bot_id()) {
|
||||||
|
if (!App::userLoaded(peerFromUser(d.vvia_bot_id))) {
|
||||||
|
return DataIsLoadedResult::NotLoaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d.has_fwd_from() && d.vfwd_from.type() == mtpc_messageFwdHeader) {
|
||||||
|
ChannelId fromChannelId = d.vfwd_from.c_messageFwdHeader().vchannel_id.v;
|
||||||
|
if (fromChannelId) {
|
||||||
|
if (!App::channelLoaded(peerFromChannel(fromChannelId))) {
|
||||||
|
return DataIsLoadedResult::NotLoaded;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!App::userLoaded(peerFromUser(d.vfwd_from.c_messageFwdHeader().vfrom_id))) {
|
||||||
|
return DataIsLoadedResult::NotLoaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case mtpc_messageService: {
|
||||||
|
const MTPDmessageService &d(msg.c_messageService());
|
||||||
|
if (!d.is_post() && d.has_from_id()) {
|
||||||
|
if (!App::userLoaded(peerFromUser(d.vfrom_id))) {
|
||||||
|
return DataIsLoadedResult::FromNotLoaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (d.vaction.type()) {
|
||||||
|
case mtpc_messageActionChatAddUser: {
|
||||||
|
for_const(const MTPint &userId, d.vaction.c_messageActionChatAddUser().vusers.c_vector().v) {
|
||||||
|
if (!App::userLoaded(peerFromUser(userId))) {
|
||||||
|
return DataIsLoadedResult::NotLoaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case mtpc_messageActionChatJoinedByLink: {
|
||||||
|
if (!App::userLoaded(peerFromUser(d.vaction.c_messageActionChatJoinedByLink().vinviter_id))) {
|
||||||
|
return DataIsLoadedResult::NotLoaded;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case mtpc_messageActionChatDeleteUser: {
|
||||||
|
if (!App::userLoaded(peerFromUser(d.vaction.c_messageActionChatDeleteUser().vuser_id))) {
|
||||||
|
return DataIsLoadedResult::NotLoaded;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
return DataIsLoadedResult::Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void MainWidget::feedUpdate(const MTPUpdate &update) {
|
void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||||
if (!MTP::authedId()) return;
|
if (!MTP::authedId()) return;
|
||||||
|
|
||||||
|
@ -4601,8 +4671,18 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||||
case mtpc_updateNewChannelMessage: {
|
case mtpc_updateNewChannelMessage: {
|
||||||
const MTPDupdateNewChannelMessage &d(update.c_updateNewChannelMessage());
|
const MTPDupdateNewChannelMessage &d(update.c_updateNewChannelMessage());
|
||||||
ChannelData *channel = App::channelLoaded(peerToChannel(peerFromMessage(d.vmessage)));
|
ChannelData *channel = App::channelLoaded(peerToChannel(peerFromMessage(d.vmessage)));
|
||||||
if (!channel && !_ptsWaiter.requesting()) {
|
DataIsLoadedResult isDataLoaded = allDataLoadedForMessage(d.vmessage);
|
||||||
MTP_LOG(0, ("getDifference { good - after no channel in updateNewChannelMessage }%1").arg(cTestMode() ? " TESTMODE" : ""));
|
if (!_ptsWaiter.requesting() && (!channel || isDataLoaded != DataIsLoadedResult::Ok)) {
|
||||||
|
MTP_LOG(0, ("getDifference { good - after not all data loaded in updateNewChannelMessage }%1").arg(cTestMode() ? " TESTMODE" : ""));
|
||||||
|
|
||||||
|
// Request last active supergroup participants if the 'from' user was not loaded yet.
|
||||||
|
// This will optimize similar getDifference() calls for almost all next messages.
|
||||||
|
if (isDataLoaded == DataIsLoadedResult::FromNotLoaded && channel && channel->isMegagroup() && App::api()) {
|
||||||
|
if (channel->mgInfo->lastParticipants.size() < Global::ChatSizeMax() && (channel->mgInfo->lastParticipants.isEmpty() || channel->mgInfo->lastParticipants.size() < channel->count)) {
|
||||||
|
App::api()->requestLastParticipants(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!_byMinChannelTimer.isActive()) { // getDifference after timeout
|
if (!_byMinChannelTimer.isActive()) { // getDifference after timeout
|
||||||
_byMinChannelTimer.start(WaitForSkippedTimeout);
|
_byMinChannelTimer.start(WaitForSkippedTimeout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ inline StorageFileType mtpToStorageType(mtpTypeId type) {
|
||||||
}
|
}
|
||||||
inline mtpTypeId mtpFromStorageType(StorageFileType type) {
|
inline mtpTypeId mtpFromStorageType(StorageFileType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case StorageFileJpeg: return mtpc_storage_fileJpeg;
|
||||||
case StorageFileGif: return mtpc_storage_fileGif;
|
case StorageFileGif: return mtpc_storage_fileGif;
|
||||||
case StorageFilePng: return mtpc_storage_filePng;
|
case StorageFilePng: return mtpc_storage_filePng;
|
||||||
case StorageFilePdf: return mtpc_storage_filePdf;
|
case StorageFilePdf: return mtpc_storage_filePdf;
|
||||||
|
|
|
@ -118,9 +118,7 @@ inline PeerId peerFromMessage(const MTPmessage &msg) {
|
||||||
inline MTPDmessage::Flags flagsFromMessage(const MTPmessage &msg) {
|
inline MTPDmessage::Flags flagsFromMessage(const MTPmessage &msg) {
|
||||||
switch (msg.type()) {
|
switch (msg.type()) {
|
||||||
case mtpc_message: return msg.c_message().vflags.v;
|
case mtpc_message: return msg.c_message().vflags.v;
|
||||||
|
case mtpc_messageService: return mtpCastFlags(msg.c_messageService().vflags.v);
|
||||||
// dirty type hack :( we assume that MTPDmessage::Flags has the same flags and perhaps more
|
|
||||||
case mtpc_messageService: return MTPDmessage::Flags(QFlag(msg.c_messageService().vflags.v));
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<AdditionalOptions>/Zm152 %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/Zm152 %(AdditionalOptions)</AdditionalOptions>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
@ -109,6 +110,8 @@
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||||
<AdditionalOptions>/Zm110 %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/Zm110 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
@ -140,6 +143,8 @@
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||||
<AdditionalOptions>/Zm110 %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/Zm110 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
|
@ -71,6 +71,8 @@
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<AdditionalIncludeDirectories>.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||||
|
<WarningLevel>EnableAllWarnings</WarningLevel>
|
||||||
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|
Loading…
Reference in New Issue