Handle errors in getMessages().

This commit is contained in:
John Preston 2017-11-23 19:41:13 +04:00
parent 39428841e4
commit efdba3a482
6 changed files with 57 additions and 11 deletions

View File

@ -171,8 +171,12 @@ void ApiWrap::resolveMessageDatas() {
auto ids = collectMessageIds(_messageDataRequests);
if (!ids.isEmpty()) {
auto requestId = request(MTPmessages_GetMessages(MTP_vector<MTPint>(ids))).done([this](const MTPmessages_Messages &result, mtpRequestId requestId) {
auto requestId = request(MTPmessages_GetMessages(
MTP_vector<MTPint>(ids)
)).done([this](const MTPmessages_Messages &result, mtpRequestId requestId) {
gotMessageDatas(nullptr, result, requestId);
}).fail([this](const RPCError &error, mtpRequestId requestId) {
finalizeMessageDataRequest(nullptr, requestId);
}).after(kSmallDelayMs).send();
for (auto &request : _messageDataRequests) {
if (request.requestId > 0) continue;
@ -186,8 +190,14 @@ void ApiWrap::resolveMessageDatas() {
}
auto ids = collectMessageIds(j.value());
if (!ids.isEmpty()) {
auto requestId = request(MTPchannels_GetMessages(j.key()->inputChannel, MTP_vector<MTPint>(ids))).done([this, channel = j.key()](const MTPmessages_Messages &result, mtpRequestId requestId) {
auto channel = j.key();
auto requestId = request(MTPchannels_GetMessages(
j.key()->inputChannel,
MTP_vector<MTPint>(ids)
)).done([=](const MTPmessages_Messages &result, mtpRequestId requestId) {
gotMessageDatas(channel, result, requestId);
}).fail([=](const RPCError &error, mtpRequestId requestId) {
finalizeMessageDataRequest(channel, requestId);
}).after(kSmallDelayMs).send();
for (auto &request : *j) {
@ -225,6 +235,12 @@ void ApiWrap::gotMessageDatas(ChannelData *channel, const MTPmessages_Messages &
LOG(("API Error: received messages.messagesNotModified! (ApiWrap::gotDependencyItem)"));
break;
}
finalizeMessageDataRequest(channel, requestId);
}
void ApiWrap::finalizeMessageDataRequest(
ChannelData *channel,
mtpRequestId requestId) {
auto requests = messageDataRequests(channel, true);
if (requests) {
for (auto i = requests->begin(); i != requests->cend();) {

View File

@ -173,6 +173,9 @@ private:
void resolveMessageDatas();
void gotMessageDatas(ChannelData *channel, const MTPmessages_Messages &result, mtpRequestId requestId);
void finalizeMessageDataRequest(
ChannelData *channel,
mtpRequestId requestId);
QVector<MTPint> collectMessageIds(const MessageDataRequests &requests);
MessageDataRequests *messageDataRequests(ChannelData *channel, bool onlyExisting = false);

View File

@ -414,7 +414,13 @@ bool HistoryMessageReply::updateData(HistoryMessage *holder, bool force) {
if (!replyToMsg) {
replyToMsg = App::histItemById(holder->channelId(), replyToMsgId);
if (replyToMsg) {
App::historyRegDependency(holder, replyToMsg);
if (replyToMsg->isEmpty()) {
// Really it is deleted.
replyToMsg = nullptr;
force = true;
} else {
App::historyRegDependency(holder, replyToMsg);
}
}
}
@ -869,7 +875,10 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
if (auto reply = Get<HistoryMessageReply>()) {
reply->replyToMsgId = config.replyTo;
if (!reply->updateData(this)) {
Auth().api().requestMessageData(history()->peer->asChannel(), reply->replyToMsgId, HistoryDependentItemCallback(fullId()));
Auth().api().requestMessageData(
history()->peer->asChannel(),
reply->replyToMsgId,
HistoryDependentItemCallback(fullId()));
}
}
if (auto via = Get<HistoryMessageVia>()) {

View File

@ -248,12 +248,18 @@ bool HistoryService::updateDependent(bool force) {
if (!dependent->lnk) {
dependent->lnk = goToMessageClickHandler(history()->peer, dependent->msgId);
}
bool gotDependencyItem = false;
auto gotDependencyItem = false;
if (!dependent->msg) {
dependent->msg = App::histItemById(channelId(), dependent->msgId);
if (dependent->msg) {
App::historyRegDependency(this, dependent->msg);
gotDependencyItem = true;
if (dependent->msg->isEmpty()) {
// Really it is deleted.
dependent->msg = nullptr;
force = true;
} else {
App::historyRegDependency(this, dependent->msg);
gotDependencyItem = true;
}
}
}
if (dependent->msg) {
@ -687,7 +693,10 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) {
if (auto dependent = GetDependentData()) {
dependent->msgId = message.vreply_to_msg_id.v;
if (!updateDependent()) {
Auth().api().requestMessageData(history()->peer->asChannel(), dependent->msgId, HistoryDependentItemCallback(fullId()));
Auth().api().requestMessageData(
history()->peer->asChannel(),
dependent->msgId,
HistoryDependentItemCallback(fullId()));
}
}
}

View File

@ -1613,7 +1613,10 @@ void HistoryWidget::applyDraft(bool parseLinks, Ui::FlatTextarea::UndoHistoryAct
if (_editMsgId || _replyToId) {
updateReplyEditTexts();
if (!_replyEditMsg) {
Auth().api().requestMessageData(_peer->asChannel(), _editMsgId ? _editMsgId : _replyToId, replyEditMessageDataCallback());
Auth().api().requestMessageData(
_peer->asChannel(),
_editMsgId ? _editMsgId : _replyToId,
replyEditMessageDataCallback());
}
}
}
@ -5306,7 +5309,10 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() {
updatePinnedBar();
}
if (!_pinnedBar->msg) {
Auth().api().requestMessageData(_peer->asChannel(), _pinnedBar->msgId, replyEditMessageDataCallback());
Auth().api().requestMessageData(
_peer->asChannel(),
_pinnedBar->msgId,
replyEditMessageDataCallback());
}
} else if (_pinnedBar) {
destroyPinnedBar();

View File

@ -4931,7 +4931,10 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
if (peerId) {
if (auto item = App::histItemById(peerToChannel(peerId), d.vid.v)) {
if (d.has_entities() && !mentionUsersLoaded(d.ventities)) {
Auth().api().requestMessageData(item->history()->peer->asChannel(), item->id, ApiWrap::RequestMessageDataCallback());
Auth().api().requestMessageData(
item->history()->peer->asChannel(),
item->id,
ApiWrap::RequestMessageDataCallback());
}
auto entities = d.has_entities() ? TextUtilities::EntitiesFromMTP(d.ventities.v) : EntitiesInText();
item->setText({ text, entities });