Beispiel #1
0
void ApiWrap::gotChat(PeerData *peer, const MTPmessages_Chats &result) {
	_peerRequests.remove(peer);
	
	if (result.type() == mtpc_messages_chats) {
		const QVector<MTPChat> &v(result.c_messages_chats().vchats.c_vector().v);
		bool badVersion = (!v.isEmpty() && v.at(0).type() == mtpc_chat && v.at(0).c_chat().vversion.v < peer->asChat()->version);
		ChatData *chat = App::feedChats(result.c_messages_chats().vchats);
		if (chat == peer) {
			if (badVersion) {
				peer->asChat()->version = v.at(0).c_chat().vversion.v;
				requestPeer(peer);
			}
		}
	}
}
Beispiel #2
0
void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result) {
    const MTPDmessages_chatFull &d(result.c_messages_chatFull());
    const MTPDchatFull &f(d.vfull_chat.c_chatFull());

    const QVector<MTPChat> &vc(d.vchats.c_vector().v);
    bool badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_chat && vc.at(0).c_chat().vversion.v < peer->asChat()->version);

    App::feedUsers(d.vusers, false);
    App::feedChats(d.vchats, false);
    App::feedParticipants(f.vparticipants, false, false);
    const QVector<MTPBotInfo> &v(f.vbot_info.c_vector().v);
    for (QVector<MTPBotInfo>::const_iterator i = v.cbegin(), e = v.cend(); i < e; ++i) {
        switch (i->type()) {
        case mtpc_botInfo: {
            const MTPDbotInfo &b(i->c_botInfo());
            UserData *user = App::userLoaded(b.vuser_id.v);
            if (user) {
                user->setBotInfo(*i);
                App::clearPeerUpdated(user);
                emit fullPeerUpdated(user);
            }
        }
        break;
        }
    }
    PhotoData *photo = App::feedPhoto(f.vchat_photo);
    ChatData *chat = peer->asChat();
    if (chat) {
        if (photo) {
            chat->photoId = photo->id;
            photo->chat = chat;
        } else {
            chat->photoId = 0;
        }
        chat->invitationUrl = (f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString();
    }

    App::main()->gotNotifySetting(MTP_inputNotifyPeer(peer->input), f.vnotify_settings);

    _fullPeerRequests.remove(peer);
    if (badVersion) {
        peer->asChat()->version = vc.at(0).c_chat().vversion.v;
        requestPeer(peer);
    }
    App::clearPeerUpdated(peer);
    emit fullPeerUpdated(peer);
    App::emitPeerUpdated();
}
Beispiel #3
0
void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mtpRequestId req) {
	const MTPDmessages_chatFull &d(result.c_messages_chatFull());
	const QVector<MTPChat> &vc(d.vchats.c_vector().v);
	bool badVersion = false;
	if (peer->isChat()) {
		badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_chat && vc.at(0).c_chat().vversion.v < peer->asChat()->version);
	} else if (peer->isChannel()) {
		badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_channel && vc.at(0).c_channel().vversion.v < peer->asChannel()->version);
	}

	App::feedUsers(d.vusers, false);
	App::feedChats(d.vchats, false);

	if (peer->isChat()) {
		if (d.vfull_chat.type() != mtpc_chatFull) {
			LOG(("MTP Error: bad type in gotChatFull for chat: %1").arg(d.vfull_chat.type()));
			return;
		}
		const MTPDchatFull &f(d.vfull_chat.c_chatFull());
		App::feedParticipants(f.vparticipants, false, false);
		const QVector<MTPBotInfo> &v(f.vbot_info.c_vector().v);
		for (QVector<MTPBotInfo>::const_iterator i = v.cbegin(), e = v.cend(); i < e; ++i) {
			switch (i->type()) {
			case mtpc_botInfo: {
				const MTPDbotInfo &b(i->c_botInfo());
				UserData *user = App::userLoaded(b.vuser_id.v);
				if (user) {
					user->setBotInfo(*i);
					App::clearPeerUpdated(user);
					emit fullPeerUpdated(user);
				}
			} break;
			}
		}
		PhotoData *photo = App::feedPhoto(f.vchat_photo);
		ChatData *chat = peer->asChat();
		if (photo) {
			chat->photoId = photo->id;
			photo->peer = chat;
		} else {
			chat->photoId = 0;
		}
		chat->invitationUrl = (f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString();

		App::main()->gotNotifySetting(MTP_inputNotifyPeer(peer->input), f.vnotify_settings);
	} else if (peer->isChannel()) {
		if (d.vfull_chat.type() != mtpc_channelFull) {
			LOG(("MTP Error: bad type in gotChatFull for channel: %1").arg(d.vfull_chat.type()));
			return;
		}
		const MTPDchannelFull &f(d.vfull_chat.c_channelFull());
		PhotoData *photo = App::feedPhoto(f.vchat_photo);
		ChannelData *channel = peer->asChannel();
		channel->flagsFull = f.vflags.v;
		if (photo) {
			channel->photoId = photo->id;
			photo->peer = channel;
		} else {
			channel->photoId = 0;
		}
		if (f.has_migrated_from_chat_id()) {
			if (!channel->mgInfo) {
				channel->flags |= MTPDchannel::flag_megagroup;
				channel->flagsUpdated();
			}
			ChatData *cfrom = App::chat(peerFromChat(f.vmigrated_from_chat_id));
			bool updatedTo = (cfrom->migrateToPtr != channel), updatedFrom = (channel->mgInfo->migrateFromPtr != cfrom);
			if (updatedTo) {
				cfrom->migrateToPtr = channel;
			}
			if (updatedFrom) {
				channel->mgInfo->migrateFromPtr = cfrom;
				if (History *h = App::historyLoaded(cfrom->id)) {
					if (History *hto = App::historyLoaded(channel->id)) {
						if (!h->isEmpty()) {
							h->clear(true);
						}
						if (!hto->dialogs.isEmpty() && !h->dialogs.isEmpty()) {
							App::removeDialog(h);
						}
					}
				}
				Notify::migrateUpdated(channel);
			}
			if (updatedTo) {
				Notify::migrateUpdated(cfrom);
				App::main()->peerUpdated(cfrom);
			}
		}
		const QVector<MTPBotInfo> &v(f.vbot_info.c_vector().v);
		for (QVector<MTPBotInfo>::const_iterator i = v.cbegin(), e = v.cend(); i < e; ++i) {
			switch (i->type()) {
			case mtpc_botInfo: {
				const MTPDbotInfo &b(i->c_botInfo());
				UserData *user = App::userLoaded(b.vuser_id.v);
				if (user) {
					user->setBotInfo(*i);
					App::clearPeerUpdated(user);
					emit fullPeerUpdated(user);
				}
			} break;
			}
		}
		channel->about = qs(f.vabout);
		int32 newCount = f.has_participants_count() ? f.vparticipants_count.v : 0;
		if (newCount != channel->count) {
			if (channel->isMegagroup() && !channel->mgInfo->lastParticipants.isEmpty()) {
				channel->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated;
				channel->mgInfo->lastParticipantsCount = channel->count;
			}
			channel->count = newCount;
		}
		channel->adminsCount = f.has_admins_count() ? f.vadmins_count.v : 0;
		channel->invitationUrl = (f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString();
		if (History *h = App::historyLoaded(channel->id)) {
			if (h->inboxReadBefore < f.vread_inbox_max_id.v + 1) {
				h->setUnreadCount(channel->isMegagroup() ? f.vunread_count.v : f.vunread_important_count.v);
				h->inboxReadBefore = f.vread_inbox_max_id.v + 1;
				h->asChannelHistory()->unreadCountAll = f.vunread_count.v;
			}
		}
		channel->fullUpdated();

		App::main()->gotNotifySetting(MTP_inputNotifyPeer(peer->input), f.vnotify_settings);
	}

	if (req) {
		QMap<PeerData*, mtpRequestId>::iterator i = _fullPeerRequests.find(peer);
		if (i != _fullPeerRequests.cend() && i.value() == req) {
			_fullPeerRequests.erase(i);
		}
	}
	if (badVersion) {
		if (peer->isChat()) {
			peer->asChat()->version = vc.at(0).c_chat().vversion.v;
		} else if (peer->isChannel()) {
			peer->asChannel()->version = vc.at(0).c_channel().vversion.v;
		}
		requestPeer(peer);
	}
	App::clearPeerUpdated(peer);
	emit fullPeerUpdated(peer);
	App::emitPeerUpdated();
}