2022-02-26 12:47:33 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "calls/group/calls_group_rtmp.h"
|
|
|
|
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "calls/group/calls_group_common.h"
|
|
|
|
#include "data/data_peer.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "main/main_account.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "settings/settings_common.h" // AddDivider.
|
|
|
|
#include "ui/boxes/confirm_box.h"
|
|
|
|
#include "ui/layers/generic_box.h"
|
|
|
|
#include "ui/text/text_utilities.h"
|
2022-08-08 15:19:04 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2022-02-26 12:47:33 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/popup_menu.h"
|
2022-02-28 16:21:28 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2022-02-26 12:47:33 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_calls.h"
|
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_menu_icons.h"
|
2022-02-28 16:21:28 +00:00
|
|
|
#include "styles/style_settings.h"
|
2022-02-26 12:47:33 +00:00
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QStyle>
|
|
|
|
|
|
|
|
namespace Calls::Group {
|
|
|
|
namespace {
|
|
|
|
|
2022-02-28 18:13:46 +00:00
|
|
|
constexpr auto kPasswordCharAmount = 24;
|
2022-02-28 09:36:17 +00:00
|
|
|
|
2022-02-26 12:47:33 +00:00
|
|
|
void StartWithBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
Fn<void()> done,
|
|
|
|
Fn<void()> revoke,
|
2022-08-08 15:19:04 +00:00
|
|
|
std::shared_ptr<Ui::Show> show,
|
2022-03-01 05:19:00 +00:00
|
|
|
rpl::producer<RtmpInfo> &&data) {
|
2022-02-26 12:47:33 +00:00
|
|
|
struct State {
|
|
|
|
base::unique_qptr<Ui::PopupMenu> menu;
|
|
|
|
};
|
|
|
|
const auto state = box->lifetime().make_state<State>();
|
|
|
|
|
2022-02-28 16:21:28 +00:00
|
|
|
StartRtmpProcess::FillRtmpRows(
|
2022-02-26 12:47:33 +00:00
|
|
|
box->verticalLayout(),
|
2022-02-28 16:21:28 +00:00
|
|
|
true,
|
2022-08-08 15:19:04 +00:00
|
|
|
std::move(show),
|
2022-02-28 16:21:28 +00:00
|
|
|
std::move(data),
|
|
|
|
&st::boxLabel,
|
|
|
|
&st::groupCallRtmpShowButton,
|
|
|
|
&st::settingsSubsectionTitle,
|
2022-03-01 05:57:57 +00:00
|
|
|
&st::attentionBoxButton,
|
|
|
|
&st::defaultPopupMenu);
|
2022-02-26 12:47:33 +00:00
|
|
|
|
2022-02-28 16:21:28 +00:00
|
|
|
box->setTitle(tr::lng_group_call_rtmp_title());
|
2022-02-26 12:47:33 +00:00
|
|
|
|
|
|
|
Settings::AddDividerText(
|
|
|
|
box->verticalLayout(),
|
|
|
|
tr::lng_group_call_rtmp_info());
|
|
|
|
|
|
|
|
box->addButton(tr::lng_group_call_rtmp_start(), done);
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
2022-03-01 09:27:17 +00:00
|
|
|
box->setWidth(st::boxWideWidth);
|
2022-02-26 12:47:33 +00:00
|
|
|
{
|
|
|
|
const auto top = box->addTopButton(st::infoTopBarMenu);
|
|
|
|
top->setClickedCallback([=] {
|
|
|
|
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
top,
|
|
|
|
st::popupMenuWithIcons);
|
|
|
|
state->menu->addAction(
|
|
|
|
tr::lng_group_invite_context_revoke(tr::now),
|
|
|
|
revoke,
|
|
|
|
&st::menuIconRemove);
|
|
|
|
state->menu->setForcedOrigin(
|
|
|
|
Ui::PanelAnimation::Origin::TopRight);
|
2022-03-01 06:49:20 +00:00
|
|
|
top->setForceRippled(true);
|
|
|
|
const auto raw = state->menu.get();
|
|
|
|
raw->setDestroyedCallback([=] {
|
|
|
|
if ((state->menu == raw) && top) {
|
|
|
|
top->setForceRippled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
state->menu->popup(top->mapToGlobal(top->rect().center()));
|
2022-02-26 12:47:33 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
StartRtmpProcess::~StartRtmpProcess() {
|
2022-08-08 15:19:04 +00:00
|
|
|
close();
|
2022-02-26 12:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StartRtmpProcess::start(
|
|
|
|
not_null<PeerData*> peer,
|
2022-08-08 15:19:04 +00:00
|
|
|
std::shared_ptr<Ui::Show> show,
|
2022-02-26 12:47:33 +00:00
|
|
|
Fn<void(JoinInfo)> done) {
|
|
|
|
Expects(done != nullptr);
|
|
|
|
|
|
|
|
const auto session = &peer->session();
|
|
|
|
if (_request) {
|
|
|
|
if (_request->peer == peer) {
|
2022-08-08 15:19:04 +00:00
|
|
|
_request->show = std::move(show);
|
2022-02-26 12:47:33 +00:00
|
|
|
_request->done = std::move(done);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
session->api().request(_request->id).cancel();
|
|
|
|
_request = nullptr;
|
|
|
|
}
|
|
|
|
_request = std::make_unique<RtmpRequest>(
|
|
|
|
RtmpRequest{
|
|
|
|
.peer = peer,
|
2022-08-08 15:19:04 +00:00
|
|
|
.show = std::move(show),
|
|
|
|
.done = std::move(done),
|
|
|
|
});
|
2022-02-26 12:47:33 +00:00
|
|
|
session->account().sessionChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_request = nullptr;
|
|
|
|
}, _request->lifetime);
|
|
|
|
|
|
|
|
requestUrl(false);
|
|
|
|
}
|
|
|
|
|
2022-08-08 15:19:04 +00:00
|
|
|
void StartRtmpProcess::close() {
|
|
|
|
if (_request) {
|
|
|
|
_request->peer->session().api().request(_request->id).cancel();
|
|
|
|
if (const auto strong = _request->box.data()) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
_request = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-26 12:47:33 +00:00
|
|
|
void StartRtmpProcess::requestUrl(bool revoke) {
|
|
|
|
const auto session = &_request->peer->session();
|
|
|
|
_request->id = session->api().request(MTPphone_GetGroupCallStreamRtmpUrl(
|
|
|
|
_request->peer->input,
|
|
|
|
MTP_bool(revoke)
|
|
|
|
)).done([=](const MTPphone_GroupCallStreamRtmpUrl &result) {
|
|
|
|
auto data = result.match([&](
|
|
|
|
const MTPDphone_groupCallStreamRtmpUrl &data) {
|
2022-03-01 05:19:00 +00:00
|
|
|
return RtmpInfo{ .url = qs(data.vurl()), .key = qs(data.vkey()) };
|
2022-02-26 12:47:33 +00:00
|
|
|
});
|
|
|
|
processUrl(std::move(data));
|
|
|
|
}).fail([=] {
|
2022-08-08 15:19:04 +00:00
|
|
|
Ui::Toast::Show(
|
|
|
|
_request->show->toastParent(),
|
|
|
|
Lang::Hard::ServerError());
|
2022-02-26 12:47:33 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2022-03-01 05:19:00 +00:00
|
|
|
void StartRtmpProcess::processUrl(RtmpInfo data) {
|
2022-02-26 12:47:33 +00:00
|
|
|
if (!_request->box) {
|
|
|
|
createBox();
|
|
|
|
}
|
|
|
|
_request->data = std::move(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartRtmpProcess::finish(JoinInfo info) {
|
2022-08-08 15:19:04 +00:00
|
|
|
info.rtmpInfo = _request->data.current();
|
|
|
|
_request->done(std::move(info));
|
2022-02-26 12:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StartRtmpProcess::createBox() {
|
|
|
|
auto done = [=] {
|
|
|
|
const auto peer = _request->peer;
|
|
|
|
finish({ .peer = peer, .joinAs = peer, .rtmp = true });
|
|
|
|
};
|
|
|
|
auto revoke = [=] {
|
|
|
|
const auto guard = base::make_weak(&_request->guard);
|
2022-08-08 15:19:04 +00:00
|
|
|
_request->show->showBox(Ui::MakeConfirmBox({
|
2022-02-27 08:23:20 +00:00
|
|
|
.text = tr::lng_group_call_rtmp_revoke_sure(),
|
|
|
|
.confirmed = crl::guard(guard, [=](Fn<void()> &&close) {
|
2022-02-26 12:47:33 +00:00
|
|
|
requestUrl(true);
|
|
|
|
close();
|
2022-02-27 08:23:20 +00:00
|
|
|
}),
|
|
|
|
.confirmText = tr::lng_group_invite_context_revoke(),
|
|
|
|
}));
|
2022-02-26 12:47:33 +00:00
|
|
|
};
|
|
|
|
auto object = Box(
|
|
|
|
StartWithBox,
|
|
|
|
std::move(done),
|
|
|
|
std::move(revoke),
|
2022-08-08 15:19:04 +00:00
|
|
|
_request->show,
|
2022-02-26 12:47:33 +00:00
|
|
|
_request->data.value());
|
|
|
|
object->boxClosing(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_request = nullptr;
|
|
|
|
}, _request->lifetime);
|
|
|
|
_request->box = Ui::MakeWeak(object.data());
|
2022-08-08 15:19:04 +00:00
|
|
|
_request->show->showBox(std::move(object));
|
2022-02-26 12:47:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 16:21:28 +00:00
|
|
|
void StartRtmpProcess::FillRtmpRows(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
bool divider,
|
2022-08-08 15:19:04 +00:00
|
|
|
std::shared_ptr<Ui::Show> show,
|
2022-03-01 05:19:00 +00:00
|
|
|
rpl::producer<RtmpInfo> &&data,
|
2022-02-28 16:21:28 +00:00
|
|
|
const style::FlatLabel *labelStyle,
|
|
|
|
const style::IconButton *showButtonStyle,
|
|
|
|
const style::FlatLabel *subsectionTitleStyle,
|
2022-03-01 05:57:57 +00:00
|
|
|
const style::RoundButton *attentionButtonStyle,
|
|
|
|
const style::PopupMenu *popupMenuStyle) {
|
2022-02-28 16:21:28 +00:00
|
|
|
struct State {
|
|
|
|
rpl::variable<bool> hidden = true;
|
|
|
|
rpl::variable<QString> key;
|
|
|
|
rpl::variable<QString> url;
|
|
|
|
bool warned = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &rowPadding = st::boxRowPadding;
|
|
|
|
|
|
|
|
const auto passChar = QChar(container->style()->styleHint(
|
|
|
|
QStyle::SH_LineEdit_PasswordCharacter));
|
|
|
|
const auto state = container->lifetime().make_state<State>();
|
|
|
|
state->key = rpl::duplicate(
|
|
|
|
data
|
|
|
|
) | rpl::map([=](const auto &d) { return d.key; });
|
|
|
|
state->url = std::move(
|
|
|
|
data
|
|
|
|
) | rpl::map([=](const auto &d) { return d.url; });
|
|
|
|
|
2022-08-08 15:19:04 +00:00
|
|
|
const auto showToast = [=](const QString &text) {
|
|
|
|
Ui::Toast::Show(show->toastParent(), text);
|
|
|
|
};
|
2022-02-28 16:21:28 +00:00
|
|
|
const auto addButton = [&](
|
|
|
|
bool key,
|
|
|
|
rpl::producer<QString> &&text) {
|
|
|
|
auto wrap = object_ptr<Ui::RpWidget>(container);
|
|
|
|
auto button = Ui::CreateChild<Ui::RoundButton>(
|
|
|
|
wrap.data(),
|
|
|
|
rpl::duplicate(text),
|
|
|
|
st::groupCallRtmpCopyButton);
|
|
|
|
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
|
|
|
|
button->setClickedCallback(key
|
|
|
|
? Fn<void()>([=] {
|
|
|
|
QGuiApplication::clipboard()->setText(state->key.current());
|
|
|
|
showToast(tr::lng_group_call_rtmp_key_copied(tr::now));
|
|
|
|
})
|
|
|
|
: Fn<void()>([=] {
|
|
|
|
QGuiApplication::clipboard()->setText(state->url.current());
|
|
|
|
showToast(tr::lng_group_call_rtmp_url_copied(tr::now));
|
|
|
|
}));
|
2022-03-01 09:01:00 +00:00
|
|
|
Settings::AddSkip(container, st::groupCallRtmpCopyButtonTopSkip);
|
2022-02-28 16:21:28 +00:00
|
|
|
const auto weak = container->add(std::move(wrap), rowPadding);
|
2022-03-01 09:01:00 +00:00
|
|
|
Settings::AddSkip(container, st::groupCallRtmpCopyButtonBottomSkip);
|
2022-02-28 16:21:28 +00:00
|
|
|
button->heightValue(
|
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
weak->resize(weak->width(), height);
|
|
|
|
}, container->lifetime());
|
|
|
|
return weak;
|
|
|
|
};
|
|
|
|
|
2022-03-01 05:57:57 +00:00
|
|
|
const auto addLabel = [&](rpl::producer<QString> &&text) {
|
2022-02-28 16:21:28 +00:00
|
|
|
const auto label = container->add(
|
2022-03-01 05:57:57 +00:00
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
std::move(text),
|
|
|
|
*labelStyle,
|
|
|
|
*popupMenuStyle),
|
2022-02-28 18:13:46 +00:00
|
|
|
st::boxRowPadding + QMargins(0, 0, showButtonStyle->width, 0));
|
2022-02-28 16:21:28 +00:00
|
|
|
label->setSelectable(true);
|
|
|
|
label->setBreakEverywhere(true);
|
|
|
|
return label;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Server URL.
|
2022-03-01 05:22:56 +00:00
|
|
|
Settings::AddSubsectionTitle(
|
|
|
|
container,
|
|
|
|
tr::lng_group_call_rtmp_url_subtitle(),
|
|
|
|
st::groupCallRtmpSubsectionTitleAddPadding,
|
|
|
|
subsectionTitleStyle);
|
2022-02-28 16:21:28 +00:00
|
|
|
|
|
|
|
auto urlLabelContent = state->url.value();
|
2022-03-01 05:57:57 +00:00
|
|
|
addLabel(std::move(urlLabelContent));
|
2022-03-01 08:47:34 +00:00
|
|
|
Settings::AddSkip(container, st::groupCallRtmpUrlSkip);
|
2022-02-28 16:21:28 +00:00
|
|
|
addButton(false, tr::lng_group_call_rtmp_url_copy());
|
|
|
|
//
|
|
|
|
|
|
|
|
if (divider) {
|
|
|
|
Settings::AddDivider(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stream Key.
|
2022-03-01 08:47:34 +00:00
|
|
|
Settings::AddSkip(container, st::groupCallRtmpKeySubsectionTitleSkip);
|
2022-02-28 16:21:28 +00:00
|
|
|
|
2022-03-01 05:22:56 +00:00
|
|
|
Settings::AddSubsectionTitle(
|
|
|
|
container,
|
|
|
|
tr::lng_group_call_rtmp_key_subtitle(),
|
|
|
|
st::groupCallRtmpSubsectionTitleAddPadding,
|
|
|
|
subsectionTitleStyle);
|
2022-02-28 16:21:28 +00:00
|
|
|
|
|
|
|
auto keyLabelContent = rpl::combine(
|
|
|
|
state->hidden.value(),
|
|
|
|
state->key.value()
|
|
|
|
) | rpl::map([passChar](bool hidden, const QString &key) {
|
|
|
|
return key.isEmpty()
|
|
|
|
? QString()
|
|
|
|
: hidden
|
|
|
|
? QString().fill(passChar, kPasswordCharAmount)
|
|
|
|
: key;
|
2022-02-28 18:13:46 +00:00
|
|
|
}) | rpl::after_next([=] {
|
|
|
|
container->resizeToWidth(container->widthNoMargins());
|
2022-02-28 16:21:28 +00:00
|
|
|
});
|
2022-03-01 05:57:57 +00:00
|
|
|
const auto streamKeyLabel = addLabel(std::move(keyLabelContent));
|
2022-02-28 16:21:28 +00:00
|
|
|
streamKeyLabel->setSelectable(false);
|
|
|
|
const auto streamKeyButton = Ui::CreateChild<Ui::IconButton>(
|
|
|
|
container.get(),
|
|
|
|
*showButtonStyle);
|
|
|
|
|
|
|
|
streamKeyLabel->topValue(
|
|
|
|
) | rpl::start_with_next([=, right = rowPadding.right()](int top) {
|
|
|
|
streamKeyButton->moveToRight(
|
|
|
|
st::groupCallRtmpShowButtonPosition.x(),
|
|
|
|
top + st::groupCallRtmpShowButtonPosition.y());
|
|
|
|
streamKeyButton->raise();
|
|
|
|
}, container->lifetime());
|
|
|
|
streamKeyButton->addClickHandler([=] {
|
|
|
|
const auto toggle = [=] {
|
|
|
|
const auto newValue = !state->hidden.current();
|
|
|
|
state->hidden = newValue;
|
|
|
|
streamKeyLabel->setSelectable(!newValue);
|
|
|
|
streamKeyLabel->setAttribute(
|
|
|
|
Qt::WA_TransparentForMouseEvents,
|
|
|
|
newValue);
|
|
|
|
};
|
|
|
|
if (!state->warned && state->hidden.current()) {
|
2022-08-08 15:19:04 +00:00
|
|
|
show->showBox(Ui::MakeConfirmBox({
|
2022-02-28 16:21:28 +00:00
|
|
|
.text = tr::lng_group_call_rtmp_key_warning(
|
|
|
|
Ui::Text::RichLangValue),
|
|
|
|
.confirmed = [=](Fn<void()> &&close) {
|
|
|
|
state->warned = true;
|
|
|
|
toggle();
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
.confirmText = tr::lng_from_request_understand(),
|
2022-08-08 13:39:44 +00:00
|
|
|
.cancelText = tr::lng_cancel(),
|
2022-02-28 16:21:28 +00:00
|
|
|
.confirmStyle = attentionButtonStyle,
|
|
|
|
.labelStyle = labelStyle,
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
addButton(true, tr::lng_group_call_rtmp_key_copy());
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2022-02-26 12:47:33 +00:00
|
|
|
} // namespace Calls::Group
|