MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / createChannel

Method createChannel

Telegram/SourceFiles/boxes/add_contact_box.cpp:820–899  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818}
819
820void GroupInfoBox::createChannel(
821 const QString &title,
822 const QString &description) {
823 Expects(!_creationRequestId);
824
825 using Flag = MTPchannels_CreateChannel::Flag;
826 const auto flags = Flag()
827 | ((_type == Type::Megagroup || _type == Type::Forum)
828 ? Flag::f_megagroup
829 : Flag::f_broadcast)
830 | ((_type == Type::Forum) ? Flag::f_forum : Flag())
831 | ((_type == Type::Megagroup)
832 ? MTPchannels_CreateChannel::Flag::f_ttl_period
833 : MTPchannels_CreateChannel::Flags(0));
834 const auto ttl = ttlPeriod();
835 _creationRequestId = _api.request(MTPchannels_CreateChannel(
836 MTP_flags(flags),
837 MTP_string(title),
838 MTP_string(description),
839 MTPInputGeoPoint(), // geo_point
840 MTPstring(), // address
841 MTP_int((_type == Type::Megagroup) ? ttl : 0)
842 )).done([=](const MTPUpdates &result) {
843 _navigation->session().api().applyUpdates(result);
844
845 const auto success = base::make_optional(&result)
846 | [](auto updates) -> std::optional<const QVector<MTPChat>*> {
847 switch (updates->type()) {
848 case mtpc_updates:
849 return &updates->c_updates().vchats().v;
850 case mtpc_updatesCombined:
851 return &updates->c_updatesCombined().vchats().v;
852 }
853 LOG(("API Error: unexpected update cons %1 "
854 "(GroupInfoBox::createChannel)").arg(updates->type()));
855 return std::nullopt;
856 }
857 | [](auto chats) {
858 return (!chats->empty()
859 && chats->front().type() == mtpc_channel)
860 ? base::make_optional(chats)
861 : std::nullopt;
862 }
863 | [&](auto chats) {
864 return _navigation->session().data().channel(
865 chats->front().c_channel().vid());
866 }
867 | [&](not_null<ChannelData*> channel) {
868 auto image = _photo->takeResultImage();
869 if (!image.isNull()) {
870 channel->session().api().peerPhoto().upload(
871 channel,
872 { std::move(image) });
873 }
874 if (ttl && channel->isMegagroup()) {
875 channel->setMessagesTTL(ttl);
876 }
877 channel->session().api().requestFullPeer(channel);

Callers

nothing calls this directly

Calls 15

MTP_flagsFunction · 0.85
MTP_stringFunction · 0.85
MakeInformBoxFunction · 0.85
apiMethod · 0.80
frontMethod · 0.80
takeResultImageMethod · 0.80
setMessagesTTLMethod · 0.80
requestFullPeerMethod · 0.80
FlagEnum · 0.50
FlagsClass · 0.50
MTP_intFunction · 0.50
BoxClass · 0.50

Tested by

no test coverage detected