Ejemplo n.º 1
0
void ApiWrap::resolveReplyTo() {
	if (_replyToRequests.isEmpty() && _channelReplyToRequests.isEmpty()) return;

	MessageIds ids = collectMessageIds(_replyToRequests);
	if (!ids.isEmpty()) {
		mtpRequestId req = MTP::send(MTPmessages_GetMessages(MTP_vector<MTPint>(ids)), rpcDone(&ApiWrap::gotReplyTo, (ChannelData*)0), RPCFailHandlerPtr(), 0, 5);
		for (ReplyToRequests::iterator i = _replyToRequests.begin(); i != _replyToRequests.cend(); ++i) {
			if (i.value().req > 0) continue;
			i.value().req = req;
		}
	}
	for (ChannelReplyToRequests::iterator j = _channelReplyToRequests.begin(); j != _channelReplyToRequests.cend();) {
		if (j->isEmpty()) {
			j = _channelReplyToRequests.erase(j);
			continue;
		}
		MessageIds ids = collectMessageIds(j.value());
		if (!ids.isEmpty()) {
			mtpRequestId req = MTP::send(MTPchannels_GetMessages(j.key()->inputChannel, MTP_vector<MTPint>(ids)), rpcDone(&ApiWrap::gotReplyTo, j.key()), RPCFailHandlerPtr(), 0, 5);
			for (ReplyToRequests::iterator i = j->begin(); i != j->cend(); ++i) {
				if (i.value().req > 0) continue;
				i.value().req = req;
			}
		}
		++j;
	}
}
Ejemplo n.º 2
0
void ApiWrap::gotReplyTo(const MTPmessages_Messages &msgs, mtpRequestId req) {
	switch (msgs.type()) {
	case mtpc_messages_messages:
		App::feedUsers(msgs.c_messages_messages().vusers);
		App::feedChats(msgs.c_messages_messages().vchats);
		App::feedMsgs(msgs.c_messages_messages().vmessages, -1);
		break;

	case mtpc_messages_messagesSlice:
		App::feedUsers(msgs.c_messages_messagesSlice().vusers);
		App::feedChats(msgs.c_messages_messagesSlice().vchats);
		App::feedMsgs(msgs.c_messages_messagesSlice().vmessages, -1);
		break;
	}
	for (ReplyToRequests::iterator i = _replyToRequests.begin(); i != _replyToRequests.cend();) {
		if (i.value().req == req) {
			for (QList<HistoryReply*>::const_iterator j = i.value().replies.cbegin(), e = i.value().replies.cend(); j != e; ++j) {
				if (*j) {
					(*j)->updateReplyTo(true);
				} else {
					App::main()->updateReplyTo();
				}
			}
			i = _replyToRequests.erase(i);
		} else {
			++i;
		}
	}
}
Ejemplo n.º 3
0
void ApiWrap::gotReplyTo(ChannelData *channel, const MTPmessages_Messages &msgs, mtpRequestId req) {
	switch (msgs.type()) {
	case mtpc_messages_messages: {
		const MTPDmessages_messages &d(msgs.c_messages_messages());
		App::feedUsers(d.vusers);
		App::feedChats(d.vchats);
		App::feedMsgs(d.vmessages, NewMessageExisting);
	} break;

	case mtpc_messages_messagesSlice: {
		const MTPDmessages_messagesSlice &d(msgs.c_messages_messagesSlice());
		App::feedUsers(d.vusers);
		App::feedChats(d.vchats);
		App::feedMsgs(d.vmessages, NewMessageExisting);
	} break;

	case mtpc_messages_channelMessages: {
		const MTPDmessages_channelMessages &d(msgs.c_messages_channelMessages());
		if (channel) {
			channel->ptsReceived(d.vpts.v);
		} else {
			LOG(("App Error: received messages.channelMessages when no channel was passed! (ApiWrap::gotReplyTo)"));
		}
		if (d.has_collapsed()) { // should not be returned
			LOG(("API Error: channels.getMessages and messages.getMessages should not return collapsed groups! (ApiWrap::gotReplyTo)"));
		}

		App::feedUsers(d.vusers);
		App::feedChats(d.vchats);
		App::feedMsgs(d.vmessages, NewMessageExisting);
	} break;
	}
	ReplyToRequests *requests(replyToRequests(channel, true));
	if (requests) {
		for (ReplyToRequests::iterator i = requests->begin(); i != requests->cend();) {
			if (i.value().req == req) {
				for (QList<HistoryReply*>::const_iterator j = i.value().replies.cbegin(), e = i.value().replies.cend(); j != e; ++j) {
					if (*j) {
						(*j)->updateReplyTo(true);
					} else {
						App::main()->updateReplyTo();
					}
				}
				i = requests->erase(i);
			} else {
				++i;
			}
		}
		if (channel && requests->isEmpty()) {
			_channelReplyToRequests.remove(channel);
		}
	}
}
Ejemplo n.º 4
0
void ApiWrap::resolveReplyTo() {
	if (_replyToRequests.isEmpty()) return;

	QVector<MTPint> ids;
	ids.reserve(_replyToRequests.size());
	for (ReplyToRequests::const_iterator i = _replyToRequests.cbegin(), e = _replyToRequests.cend(); i != e; ++i) {
		if (!i.value().req) {
			ids.push_back(MTP_int(i.key()));
		}
	}
	if (!ids.isEmpty()) {
		mtpRequestId req = MTP::send(MTPmessages_GetMessages(MTP_vector<MTPint>(ids)), rpcDone(&ApiWrap::gotReplyTo));
		for (ReplyToRequests::iterator i = _replyToRequests.begin(), e = _replyToRequests.end(); i != e; ++i) {
			i.value().req = req;
		}
	}
}