diff --git a/Telegram/Resources/tl/api.tl b/Telegram/Resources/tl/api.tl index 930dbf490..b7db7bb18 100644 --- a/Telegram/Resources/tl/api.tl +++ b/Telegram/Resources/tl/api.tl @@ -92,7 +92,7 @@ inputPhotoFileLocation#40181ffe id:long access_hash:long file_reference:bytes th inputPhotoLegacyFileLocation#d83466f3 id:long access_hash:long file_reference:bytes volume_id:long local_id:int secret:long = InputFileLocation; inputPeerPhotoFileLocation#27d69997 flags:# big:flags.0?true peer:InputPeer volume_id:long local_id:int = InputFileLocation; inputStickerSetThumb#dbaeae9 stickerset:InputStickerSet volume_id:long local_id:int = InputFileLocation; -inputGroupCallStream#d1cc2a5f call:InputGroupCall date:int = InputFileLocation; +inputGroupCallStream#bba51639 call:InputGroupCall time_ms:long scale:int = InputFileLocation; peerUser#9db1bc6d user_id:int = Peer; peerChat#bad0e5bb chat_id:int = Peer; @@ -1240,6 +1240,8 @@ messages.chatAdminsWithInvites#b69b72d7 admins:Vector user messages.checkedHistoryImportPeer#a24de717 confirm_text:string = messages.CheckedHistoryImportPeer; +phone.joinAsPeers#afe5623f peers:Vector chats:Vector users:Vector = phone.JoinAsPeers; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1623,6 +1625,7 @@ phone.checkGroupCall#b74a7bea call:InputGroupCall source:int = Bool; phone.toggleGroupCallRecord#c02a66d7 flags:# start:flags.0?true call:InputGroupCall title:flags.1?string = Updates; phone.editGroupCallParticipant#d975eb80 flags:# muted:flags.0?true call:InputGroupCall participant:InputPeer volume:flags.1?int raise_hand:flags.2?Bool = Updates; phone.editGroupCallTitle#1ca6ac0a call:InputGroupCall title:string = Updates; +phone.getGroupCallJoinAs#ef7c213a peer:InputPeer = phone.JoinAsPeers; langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference; langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector = Vector; diff --git a/Telegram/SourceFiles/calls/calls_choose_join_as.cpp b/Telegram/SourceFiles/calls/calls_choose_join_as.cpp index d7dba4b4b..39e4fa8f1 100644 --- a/Telegram/SourceFiles/calls/calls_choose_join_as.cpp +++ b/Telegram/SourceFiles/calls/calls_choose_join_as.cpp @@ -163,20 +163,18 @@ void ChooseJoinAsProcess::start( not_null peer, Context context, Fn)> showBox, + Fn showToast, Fn done, PeerData *currentJoinAs) { Expects(done != nullptr); const auto session = &peer->session(); if (_request) { - const auto already = _request->peer; - _request->context = context; - _request->showBox = std::move(showBox); - _request->done = std::move(done); - if (already == peer) { - return; - } else if (&already->session() == session) { - _request->peer = peer; + if (_request->peer == peer) { + _request->context = context; + _request->showBox = std::move(showBox); + _request->showToast = std::move(showToast); + _request->done = std::move(done); return; } session->api().request(_request->id).cancel(); @@ -186,6 +184,7 @@ void ChooseJoinAsProcess::start( ChannelsListRequest{ .peer = peer, .showBox = std::move(showBox), + .showToast = std::move(showToast), .done = std::move(done), .context = context }); session->account().sessionChanges( @@ -204,39 +203,52 @@ void ChooseJoinAsProcess::start( } }; using Flag = MTPchannels_GetAdminedPublicChannels::Flag; - _request->id = session->api().request( - MTPchannels_GetAdminedPublicChannels( - MTP_flags(Flag::f_for_groupcall)) - ).done([=](const MTPmessages_Chats &result) { - const auto &chats = result.match([](const auto &data) { - return data.vchats().v; - }); + _request->id = session->api().request(MTPphone_GetGroupCallJoinAs( + _request->peer->input + )).done([=](const MTPphone_JoinAsPeers &result) { const auto peer = _request->peer; const auto self = peer->session().user(); auto info = JoinInfo{ .peer = peer, .joinAs = self }; - if (chats.size() == 1) { + auto list = result.match([&](const MTPDphone_joinAsPeers &data) { + session->data().processUsers(data.vusers()); + session->data().processChats(data.vchats()); + const auto &peers = data.vpeers().v; + auto list = std::vector>(); + list.reserve(peers.size()); + for (const auto &peer : peers) { + const auto peerId = peerFromMTP(peer); + if (const auto peer = session->data().peerLoaded(peerId)) { + if (!ranges::contains(list, not_null{ peer })) { + list.push_back(peer); + } + } + } + return list; + }); + if (list.empty()) { + _request->showToast("No way to join this voice chat :("); + return; + } else if (list.size() == 1 && list.front() == self) { + info.possibleJoinAs = std::move(list); finish(info); return; } - auto list = std::vector>(); - list.reserve(chats.size() + 1); - list.push_back(self); - for (const auto &chat : chats) { - list.push_back(session->data().processChat(chat)); - } - const auto selected = [&]() -> PeerData* { + info.joinAs = [&]() -> not_null { const auto selectedId = peer->groupCallDefaultJoinAs(); if (!selectedId) { return self; } const auto loaded = session->data().peerLoaded(selectedId); - return (loaded && ranges::contains(list, not_null{ loaded })) + return (currentJoinAs && ranges::contains(list, not_null{ currentJoinAs })) + ? not_null(currentJoinAs) + : (loaded && ranges::contains(list, not_null{ loaded })) ? not_null(loaded) - : self; + : ranges::contains(list, self) + ? self + : list.front(); }(); - - info.joinAs = currentJoinAs ? currentJoinAs : selected; info.possibleJoinAs = std::move(list); + auto box = Box( ChooseJoinAsBox, context, diff --git a/Telegram/SourceFiles/calls/calls_choose_join_as.h b/Telegram/SourceFiles/calls/calls_choose_join_as.h index 2acb10857..487ef2bc1 100644 --- a/Telegram/SourceFiles/calls/calls_choose_join_as.h +++ b/Telegram/SourceFiles/calls/calls_choose_join_as.h @@ -35,6 +35,7 @@ public: not_null peer, Context context, Fn)> showBox, + Fn showToast, Fn done, PeerData *currentJoinAs = nullptr); @@ -42,6 +43,7 @@ private: struct ChannelsListRequest { not_null peer; Fn)> showBox; + Fn showToast; Fn done; base::has_weak_ptr guard; QPointer box; diff --git a/Telegram/SourceFiles/calls/calls_group_settings.cpp b/Telegram/SourceFiles/calls/calls_group_settings.cpp index 16858fa53..21168ce00 100644 --- a/Telegram/SourceFiles/calls/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/calls_group_settings.cpp @@ -164,13 +164,18 @@ void GroupCallSettingsBox( const auto callback = [=](Group::JoinInfo info) { call->rejoinAs(info); }; - auto showBox = [=](object_ptr next) { + const auto showBox = [=](object_ptr next) { box->getDelegate()->show(std::move(next)); }; + const auto showToast = [=](QString text) { + const auto container = box->getDelegate()->outerContainer(); + Ui::Toast::Show(container, text); + }; state->joinAsProcess.start( peer, context, showBox, + showToast, callback, call->joinAs()); }); diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 358efc86b..ac8036c1f 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "media/audio/media_audio_track.h" #include "platform/platform_specific.h" +#include "ui/toast/toast.h" #include "base/unixtime.h" #include "mainwidget.h" #include "mtproto/mtproto_config.h" @@ -66,6 +67,8 @@ void Instance::startOrJoinGroupCall(not_null peer) { : Group::ChooseJoinAsProcess::Context::Create; _chooseJoinAs.start(peer, context, [=](object_ptr box) { Ui::show(std::move(box), Ui::LayerOption::KeepOther); + }, [=](QString text) { + Ui::Toast::Show(text); }, [=](Group::JoinInfo info) { const auto call = info.peer->groupCall(); createGroupCall( diff --git a/Telegram/SourceFiles/ui/image/image_location.cpp b/Telegram/SourceFiles/ui/image/image_location.cpp index 3bfd5b385..608a89b8c 100644 --- a/Telegram/SourceFiles/ui/image/image_location.cpp +++ b/Telegram/SourceFiles/ui/image/image_location.cpp @@ -172,7 +172,8 @@ StorageFileLocation::StorageFileLocation( _id = data.vid().v; _accessHash = data.vaccess_hash().v; }); - _localId = data.vdate().v; + _volumeId = data.vtime_ms().v; + _localId = data.vscale().v; }); } @@ -260,6 +261,7 @@ MTPInputFileLocation StorageFileLocation::tl(int32 self) const { case Type::GroupCallStream: return MTP_inputGroupCallStream( MTP_inputGroupCall(MTP_long(_id), MTP_long(_accessHash)), + MTP_long(_volumeId), MTP_int(_localId)); } @@ -372,7 +374,7 @@ bool StorageFileLocation::valid() const { return (_dcId != 0) && (_id != 0); case Type::GroupCallStream: - return (_dcId != 0) && (_id != 0) && (_localId != 0); + return (_dcId != 0) && (_id != 0) && (_volumeId != 0); } return false; } @@ -419,7 +421,10 @@ Storage::Cache::Key StorageFileLocation::cacheKey() const { case Type::GroupCallStream: return Key{ - shifted | sliced | (uint64(uint32(_localId)) << 16), + (shifted + | sliced + | (uint32(_localId) << 16) + | (_volumeId << 20)), _id }; } return Key();