2023-05-03 22:30:37 +04: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 "media/stories/media_stories_reply.h"
|
|
|
|
|
2023-05-05 14:40:51 +04:00
|
|
|
#include "base/call_delayed.h"
|
2023-05-03 22:30:37 +04:00
|
|
|
#include "chat_helpers/compose/compose_show.h"
|
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2023-05-05 14:40:51 +04:00
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "history/view/controls/compose_controls_common.h"
|
2023-05-03 22:30:37 +04:00
|
|
|
#include "history/view/controls/history_view_compose_controls.h"
|
2023-05-05 14:40:51 +04:00
|
|
|
#include "inline_bots/inline_bot_result.h"
|
|
|
|
#include "media/stories/media_stories_controller.h"
|
2023-05-03 22:30:37 +04:00
|
|
|
#include "menu/menu_send.h"
|
2023-05-17 15:51:04 +04:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2023-05-05 14:40:51 +04:00
|
|
|
#include "styles/style_media_view.h"
|
2023-05-03 22:30:37 +04:00
|
|
|
|
|
|
|
namespace Media::Stories {
|
|
|
|
|
2023-05-05 14:40:51 +04:00
|
|
|
ReplyArea::ReplyArea(not_null<Controller*> controller)
|
|
|
|
: _controller(controller)
|
2023-05-03 22:30:37 +04:00
|
|
|
, _controls(std::make_unique<HistoryView::ComposeControls>(
|
2023-05-05 14:40:51 +04:00
|
|
|
_controller->wrap(),
|
2023-05-03 22:30:37 +04:00
|
|
|
HistoryView::ComposeControlsDescriptor{
|
2023-05-16 19:48:49 +04:00
|
|
|
.stOverride = &st::storiesComposeControls,
|
2023-05-05 14:40:51 +04:00
|
|
|
.show = _controller->uiShow(),
|
2023-05-03 22:30:37 +04:00
|
|
|
.unavailableEmojiPasted = [=](not_null<DocumentData*> emoji) {
|
|
|
|
showPremiumToast(emoji);
|
|
|
|
},
|
|
|
|
.mode = HistoryView::ComposeControlsMode::Normal,
|
|
|
|
.sendMenuType = SendMenu::Type::SilentOnly,
|
2023-05-05 14:40:51 +04:00
|
|
|
.stickerOrEmojiChosen = _controller->stickerOrEmojiChosen(),
|
2023-05-18 12:56:15 +04:00
|
|
|
.voiceLockFromBottom = true,
|
2023-05-16 19:48:49 +04:00
|
|
|
.features = {
|
|
|
|
.sendAs = false,
|
|
|
|
.ttlInfo = false,
|
|
|
|
.botCommandSend = false,
|
|
|
|
.silentBroadcastToggle = false,
|
|
|
|
.attachBotsMenu = false,
|
|
|
|
.inlineBots = false,
|
2023-05-17 15:51:04 +04:00
|
|
|
.megagroupSet = false,
|
|
|
|
.stickersSettings = false,
|
|
|
|
.openStickerSets = false,
|
|
|
|
.autocompleteHashtags = false,
|
|
|
|
.autocompleteMentions = false,
|
|
|
|
.autocompleteCommands = false,
|
2023-05-16 19:48:49 +04:00
|
|
|
},
|
2023-05-03 22:30:37 +04:00
|
|
|
}
|
|
|
|
)) {
|
2023-05-05 14:40:51 +04:00
|
|
|
initGeometry();
|
|
|
|
initActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyArea::~ReplyArea() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyArea::initGeometry() {
|
2023-05-17 15:51:04 +04:00
|
|
|
rpl::combine(
|
|
|
|
_controller->layoutValue(),
|
|
|
|
_controls->height()
|
|
|
|
) | rpl::start_with_next([=](const Layout &layout, int height) {
|
|
|
|
const auto content = layout.content;
|
2023-05-18 14:04:14 +04:00
|
|
|
_controls->resizeToWidth(layout.controlsWidth);
|
2023-05-17 15:51:04 +04:00
|
|
|
if (_controls->heightCurrent() == height) {
|
|
|
|
const auto position = layout.controlsBottomPosition
|
|
|
|
- QPoint(0, height);
|
|
|
|
_controls->move(position.x(), position.y());
|
|
|
|
const auto &tabbed = st::storiesComposeControls.tabbed;
|
|
|
|
const auto upper = QRect(
|
2023-05-18 14:04:14 +04:00
|
|
|
position.x(),
|
2023-05-17 15:51:04 +04:00
|
|
|
content.y(),
|
2023-05-18 14:04:14 +04:00
|
|
|
layout.controlsWidth,
|
2023-05-17 15:51:04 +04:00
|
|
|
(position.y()
|
|
|
|
+ tabbed.autocompleteBottomSkip
|
|
|
|
- content.y()));
|
|
|
|
_controls->setAutocompleteBoundingRect(
|
|
|
|
layout.autocompleteRect.intersected(upper));
|
|
|
|
}
|
2023-05-05 14:40:51 +04:00
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyArea::send(Api::SendOptions options) {
|
|
|
|
// #TODO stories
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyArea::sendVoice(VoiceToSend &&data) {
|
|
|
|
// #TODO stories
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyArea::chooseAttach(std::optional<bool> overrideCompress) {
|
|
|
|
// #TODO stories
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyArea::initActions() {
|
|
|
|
_controls->cancelRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
2023-05-10 14:33:17 +04:00
|
|
|
_controller->unfocusReply();
|
2023-05-05 14:40:51 +04:00
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->sendRequests(
|
|
|
|
) | rpl::start_with_next([=](Api::SendOptions options) {
|
|
|
|
send(options);
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->sendVoiceRequests(
|
|
|
|
) | rpl::start_with_next([=](VoiceToSend &&data) {
|
|
|
|
sendVoice(std::move(data));
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->attachRequests(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !_choosingAttach;
|
|
|
|
}) | rpl::start_with_next([=](std::optional<bool> overrideCompress) {
|
|
|
|
_choosingAttach = true;
|
|
|
|
base::call_delayed(
|
|
|
|
st::storiesAttach.ripple.hideDuration,
|
|
|
|
this,
|
|
|
|
[=] { chooseAttach(overrideCompress); });
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->fileChosen(
|
|
|
|
) | rpl::start_with_next([=](ChatHelpers::FileChosen data) {
|
|
|
|
_controller->uiShow()->hideLayer();
|
|
|
|
//controller()->sendingAnimation().appendSending(
|
|
|
|
// data.messageSendingFrom);
|
|
|
|
//const auto localId = data.messageSendingFrom.localId;
|
|
|
|
//sendExistingDocument(data.document, data.options, localId);
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->photoChosen(
|
|
|
|
) | rpl::start_with_next([=](ChatHelpers::PhotoChosen chosen) {
|
|
|
|
//sendExistingPhoto(chosen.photo, chosen.options);
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->inlineResultChosen(
|
|
|
|
) | rpl::start_with_next([=](ChatHelpers::InlineChosen chosen) {
|
|
|
|
//controller()->sendingAnimation().appendSending(
|
|
|
|
// chosen.messageSendingFrom);
|
|
|
|
//const auto localId = chosen.messageSendingFrom.localId;
|
|
|
|
//sendInlineResult(chosen.result, chosen.bot, chosen.options, localId);
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->setMimeDataHook([=](
|
|
|
|
not_null<const QMimeData*> data,
|
|
|
|
Ui::InputField::MimeAction action) {
|
|
|
|
if (action == Ui::InputField::MimeAction::Check) {
|
|
|
|
return false;// checkSendingFiles(data);
|
|
|
|
} else if (action == Ui::InputField::MimeAction::Insert) {
|
|
|
|
return false;/* confirmSendingFiles(
|
|
|
|
data,
|
|
|
|
std::nullopt,
|
|
|
|
Core::ReadMimeText(data));*/
|
|
|
|
}
|
|
|
|
Unexpected("action in MimeData hook.");
|
|
|
|
});
|
|
|
|
|
|
|
|
_controls->lockShowStarts(
|
|
|
|
) | rpl::start_with_next([=] {
|
2023-05-03 22:30:37 +04:00
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_controls->show();
|
2023-05-05 14:40:51 +04:00
|
|
|
_controls->finishAnimating();
|
2023-05-03 22:30:37 +04:00
|
|
|
_controls->showFinished();
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:40:51 +04:00
|
|
|
void ReplyArea::show(ReplyAreaData data) {
|
|
|
|
if (_data == data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto userChanged = (_data.user != data.user);
|
|
|
|
_data = data;
|
|
|
|
if (!userChanged) {
|
|
|
|
if (_data.user) {
|
|
|
|
_controls->clear();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto user = data.user;
|
|
|
|
const auto history = user ? user->owner().history(user).get() : nullptr;
|
|
|
|
_controls->setHistory({
|
|
|
|
.history = history,
|
|
|
|
});
|
|
|
|
_controls->clear();
|
2023-05-03 22:30:37 +04:00
|
|
|
}
|
|
|
|
|
2023-05-10 14:33:17 +04:00
|
|
|
rpl::producer<bool> ReplyArea::focusedValue() const {
|
|
|
|
return _controls->focusedValue();
|
|
|
|
}
|
|
|
|
|
2023-05-03 22:30:37 +04:00
|
|
|
void ReplyArea::showPremiumToast(not_null<DocumentData*> emoji) {
|
|
|
|
// #TODO stories
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Media::Stories
|