コード例 #1
0
std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
		not_null<HistoryMessage*> item,
		const MTPMessageMedia &media) {
	switch (media.type()) {
	case mtpc_messageMediaContact: {
		const auto &data = media.c_messageMediaContact();
		return std::make_unique<Data::MediaContact>(
			item,
			data.vuser_id.v,
			qs(data.vfirst_name),
			qs(data.vlast_name),
			qs(data.vphone_number));
	} break;
	case mtpc_messageMediaGeo: {
		const auto &data = media.c_messageMediaGeo().vgeo;
		if (data.type() == mtpc_geoPoint) {
			return std::make_unique<Data::MediaLocation>(
				item,
				LocationCoords(data.c_geoPoint()));
		}
	} break;
	case mtpc_messageMediaGeoLive: {
		const auto &data = media.c_messageMediaGeoLive().vgeo;
		if (data.type() == mtpc_geoPoint) {
			return std::make_unique<Data::MediaLocation>(
				item,
				LocationCoords(data.c_geoPoint()));
		}
	} break;
	case mtpc_messageMediaVenue: {
		const auto &data = media.c_messageMediaVenue();
		if (data.vgeo.type() == mtpc_geoPoint) {
			return std::make_unique<Data::MediaLocation>(
				item,
				LocationCoords(data.vgeo.c_geoPoint()),
				qs(data.vtitle),
				qs(data.vaddress));
		}
	} break;
	case mtpc_messageMediaPhoto: {
		const auto &data = media.c_messageMediaPhoto();
		if (data.has_ttl_seconds()) {
			LOG(("App Error: "
				"Unexpected MTPMessageMediaPhoto "
				"with ttl_seconds in HistoryMessage."));
		} else if (data.has_photo() && data.vphoto.type() == mtpc_photo) {
			return std::make_unique<Data::MediaPhoto>(
				item,
				Auth().data().photo(data.vphoto.c_photo()));
		} else {
			LOG(("API Error: "
				"Got MTPMessageMediaPhoto "
				"without photo and without ttl_seconds."));
		}
	} break;
	case mtpc_messageMediaDocument: {
		const auto &data = media.c_messageMediaDocument();
		if (data.has_ttl_seconds()) {
			LOG(("App Error: "
				"Unexpected MTPMessageMediaDocument "
				"with ttl_seconds in HistoryMessage."));
		} else if (data.has_document()
			&& data.vdocument.type() == mtpc_document) {
			return std::make_unique<Data::MediaFile>(
				item,
				Auth().data().document(data.vdocument.c_document()));
		} else {
			LOG(("API Error: "
				"Got MTPMessageMediaDocument "
				"without document and without ttl_seconds."));
		}
	} break;
	case mtpc_messageMediaWebPage: {
		const auto &data = media.c_messageMediaWebPage().vwebpage;
		switch (data.type()) {
		case mtpc_webPageEmpty: break;
		case mtpc_webPagePending:
			return std::make_unique<Data::MediaWebPage>(
				item,
				Auth().data().webpage(data.c_webPagePending()));
			break;
		case mtpc_webPage:
			return std::make_unique<Data::MediaWebPage>(
				item,
				Auth().data().webpage(data.c_webPage()));
			break;
		case mtpc_webPageNotModified:
			LOG(("API Error: "
				"webPageNotModified is unexpected in message media."));
			break;
		}
	} break;
	case mtpc_messageMediaGame: {
		const auto &data = media.c_messageMediaGame().vgame;
		if (data.type() == mtpc_game) {
			return std::make_unique<Data::MediaGame>(
				item,
				Auth().data().game(data.c_game()));
		}
	} break;
	case mtpc_messageMediaInvoice: {
		return std::make_unique<Data::MediaInvoice>(
			item,
			media.c_messageMediaInvoice());
	} break;
	};

	return nullptr;
}
コード例 #2
0
ファイル: cursor.cpp プロジェクト: basisbit/neogfx
	i_document& cursor::document() const
	{
		if (!has_document())
			throw no_document();
		return *iDocument;
	}