1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 #include "window/section_widget.h"
11 #include "window/section_memento.h"
12 #include "history/view/history_view_list_widget.h"
13 #include "data/data_messages.h"
14 
15 class History;
16 enum class SendMediaType;
17 struct SendingAlbum;
18 
19 namespace SendMenu {
20 enum class Type;
21 } // namespace SendMenu
22 
23 namespace Api {
24 struct SendOptions;
25 } // namespace Api
26 
27 namespace Ui {
28 class ScrollArea;
29 class PlainShadow;
30 class FlatButton;
31 class HistoryDownButton;
32 struct PreparedList;
33 class SendFilesWay;
34 } // namespace Ui
35 
36 namespace Profile {
37 class BackButton;
38 } // namespace Profile
39 
40 namespace InlineBots {
41 class Result;
42 } // namespace InlineBots
43 
44 namespace HistoryView {
45 
46 class Element;
47 class TopBarWidget;
48 class ScheduledMemento;
49 class ComposeControls;
50 
51 class ScheduledWidget final
52 	: public Window::SectionWidget
53 	, private ListDelegate {
54 public:
55 	ScheduledWidget(
56 		QWidget *parent,
57 		not_null<Window::SessionController*> controller,
58 		not_null<History*> history);
59 	~ScheduledWidget();
60 
61 	not_null<History*> history() const;
62 	Dialogs::RowDescriptor activeChat() const override;
63 	bool preventsClose(Fn<void()> &&continueCallback) const override;
64 
hasTopBarShadow()65 	bool hasTopBarShadow() const override {
66 		return true;
67 	}
68 
69 	QPixmap grabForShowAnimation(
70 		const Window::SectionSlideParams &params) override;
71 
72 	bool showInternal(
73 		not_null<Window::SectionMemento*> memento,
74 		const Window::SectionShow &params) override;
75 	std::shared_ptr<Window::SectionMemento> createMemento() override;
76 
77 	Window::SectionActionResult sendBotCommand(
78 		Bot::SendCommandRequest request) override;
79 
80 	void setInternalState(
81 		const QRect &geometry,
82 		not_null<ScheduledMemento*> memento);
83 
84 	// Tabbed selector management.
85 	bool pushTabbedSelectorToThirdSection(
86 		not_null<PeerData*> peer,
87 		const Window::SectionShow &params) override;
88 	bool returnTabbedSelector() override;
89 
90 	// Float player interface.
91 	bool floatPlayerHandleWheelEvent(QEvent *e) override;
92 	QRect floatPlayerAvailableRect() override;
93 
94 	// ListDelegate interface.
95 	Context listContext() override;
96 	void listScrollTo(int top) override;
97 	void listCancelRequest() override;
98 	void listDeleteRequest() override;
99 	rpl::producer<Data::MessagesSlice> listSource(
100 		Data::MessagePosition aroundId,
101 		int limitBefore,
102 		int limitAfter) override;
103 	bool listAllowsMultiSelect() override;
104 	bool listIsItemGoodForSelection(not_null<HistoryItem*> item) override;
105 	bool listIsLessInOrder(
106 		not_null<HistoryItem*> first,
107 		not_null<HistoryItem*> second) override;
108 	void listSelectionChanged(SelectedItems &&items) override;
109 	void listVisibleItemsChanged(HistoryItemsList &&items) override;
110 	MessagesBarData listMessagesBar(
111 		const std::vector<not_null<Element*>> &elements) override;
112 	void listContentRefreshed() override;
113 	ClickHandlerPtr listDateLink(not_null<Element*> view) override;
114 	bool listElementHideReply(not_null<const Element*> view) override;
115 	bool listElementShownUnread(not_null<const Element*> view) override;
116 	bool listIsGoodForAroundPosition(not_null<const Element *> view) override;
117 	void listSendBotCommand(
118 		const QString &command,
119 		const FullMsgId &context) override;
120 	void listHandleViaClick(not_null<UserData*> bot) override;
121 	not_null<Ui::ChatTheme*> listChatTheme() override;
122 
123 protected:
124 	void resizeEvent(QResizeEvent *e) override;
125 	void paintEvent(QPaintEvent *e) override;
126 
127 	void showAnimatedHook(
128 		const Window::SectionSlideParams &params) override;
129 	void showFinishedHook() override;
130 	void doSetInnerFocus() override;
131 
132 private:
133 	void onScroll();
134 	void updateInnerVisibleArea();
135 	void updateControlsGeometry();
136 	void updateAdaptiveLayout();
137 	void saveState(not_null<ScheduledMemento*> memento);
138 	void restoreState(not_null<ScheduledMemento*> memento);
139 	void showAtPosition(Data::MessagePosition position);
140 	bool showAtPositionNow(Data::MessagePosition position);
141 
142 	void setupComposeControls();
143 
144 	void setupDragArea();
145 
146 	void setupScrollDownButton();
147 	void scrollDownClicked();
148 	void scrollDownAnimationFinish();
149 	void updateScrollDownVisibility();
150 	void updateScrollDownPosition();
151 
152 	void confirmSendNowSelected();
153 	void confirmDeleteSelected();
154 	void clearSelected();
155 
156 	void send();
157 	void send(Api::SendOptions options);
158 	void sendVoice(QByteArray bytes, VoiceWaveform waveform, int duration);
159 	void sendVoice(
160 		QByteArray bytes,
161 		VoiceWaveform waveform,
162 		int duration,
163 		Api::SendOptions options);
164 	void edit(
165 		not_null<HistoryItem*> item,
166 		Api::SendOptions options,
167 		mtpRequestId *const saveEditMsgRequestId);
168 	void highlightSingleNewMessage(const Data::MessagesSlice &slice);
169 	void chooseAttach();
170 	[[nodiscard]] SendMenu::Type sendMenuType() const;
171 
172 	void uploadFile(const QByteArray &fileContent, SendMediaType type);
173 	bool confirmSendingFiles(
174 		QImage &&image,
175 		QByteArray &&content,
176 		std::optional<bool> overrideSendImagesAsPhotos = std::nullopt,
177 		const QString &insertTextOnCancel = QString());
178 	bool confirmSendingFiles(
179 		Ui::PreparedList &&list,
180 		const QString &insertTextOnCancel = QString());
181 	bool confirmSendingFiles(
182 		not_null<const QMimeData*> data,
183 		std::optional<bool> overrideSendImagesAsPhotos = std::nullopt,
184 		const QString &insertTextOnCancel = QString());
185 	bool showSendingFilesError(const Ui::PreparedList &list) const;
186 	void sendingFilesConfirmed(
187 		Ui::PreparedList &&list,
188 		Ui::SendFilesWay way,
189 		TextWithTags &&caption,
190 		Api::SendOptions options,
191 		bool ctrlShiftEnter);
192 
193 	void sendExistingDocument(not_null<DocumentData*> document);
194 	bool sendExistingDocument(
195 		not_null<DocumentData*> document,
196 		Api::SendOptions options);
197 	void sendExistingPhoto(not_null<PhotoData*> photo);
198 	bool sendExistingPhoto(
199 		not_null<PhotoData*> photo,
200 		Api::SendOptions options);
201 	void sendInlineResult(
202 		not_null<InlineBots::Result*> result,
203 		not_null<UserData*> bot);
204 	void sendInlineResult(
205 		not_null<InlineBots::Result*> result,
206 		not_null<UserData*> bot,
207 		Api::SendOptions options);
208 
209 	const not_null<History*> _history;
210 	std::shared_ptr<Ui::ChatTheme> _theme;
211 	object_ptr<Ui::ScrollArea> _scroll;
212 	QPointer<ListWidget> _inner;
213 	object_ptr<TopBarWidget> _topBar;
214 	object_ptr<Ui::PlainShadow> _topBarShadow;
215 	std::unique_ptr<ComposeControls> _composeControls;
216 	bool _skipScrollEvent = false;
217 
218 	FullMsgId _highlightMessageId;
219 	std::optional<Data::MessagePosition> _nextAnimatedScrollPosition;
220 	int _nextAnimatedScrollDelta = 0;
221 
222 	Ui::Animations::Simple _scrollDownShown;
223 	bool _scrollDownIsShown = false;
224 	object_ptr<Ui::HistoryDownButton> _scrollDown;
225 
226 	Data::MessagesSlice _lastSlice;
227 	bool _choosingAttach = false;
228 
229 };
230 
231 class ScheduledMemento : public Window::SectionMemento {
232 public:
ScheduledMemento(not_null<History * > history)233 	ScheduledMemento(not_null<History*> history)
234 	: _history(history) {
235 	}
236 
237 	object_ptr<Window::SectionWidget> createWidget(
238 		QWidget *parent,
239 		not_null<Window::SessionController*> controller,
240 		Window::Column column,
241 		const QRect &geometry) override;
242 
getHistory()243 	not_null<History*> getHistory() const {
244 		return _history;
245 	}
246 
list()247 	not_null<ListMemento*> list() {
248 		return &_list;
249 	}
250 
251 private:
252 	const not_null<History*> _history;
253 	ListMemento _list;
254 
255 };
256 
257 } // namespace HistoryView
258