2016-09-06 12:28:37 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-06 12:28:37 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/share_box.h"
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2022-02-23 07:25:46 +00:00
|
|
|
#include "base/random.h"
|
2016-09-06 12:28:37 +00:00
|
|
|
#include "dialogs/dialogs_indexed_list.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/qthelp_url.h"
|
2020-06-09 16:57:05 +00:00
|
|
|
#include "storage/storage_account.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2016-09-07 09:04:57 +00:00
|
|
|
#include "apiwrap.h"
|
2022-02-02 21:58:21 +00:00
|
|
|
#include "ui/chat/forward_options_box.h"
|
2016-09-19 10:18:21 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2022-02-02 21:58:21 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2016-10-22 13:03:20 +00:00
|
|
|
#include "ui/widgets/multi_select.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2018-11-04 07:32:26 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2022-02-02 21:58:21 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2018-11-04 07:32:26 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2022-02-23 07:25:46 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2018-11-04 07:32:26 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
2022-03-27 12:46:27 +00:00
|
|
|
#include "menu/menu_check_item.h"
|
2022-03-27 10:01:34 +00:00
|
|
|
#include "menu/menu_send.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "history/history_message.h"
|
2022-02-23 07:25:46 +00:00
|
|
|
#include "history/view/history_view_element.h" // HistoryView::Context.
|
|
|
|
#include "history/view/history_view_context_menu.h" // CopyPostLink.
|
2019-08-13 15:35:49 +00:00
|
|
|
#include "history/view/history_view_schedule_box.h"
|
2019-07-25 18:55:11 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
2018-11-21 10:09:46 +00:00
|
|
|
#include "chat_helpers/emoji_suggestions_widget.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2022-02-23 07:25:46 +00:00
|
|
|
#include "data/data_game.h"
|
|
|
|
#include "data/data_histories.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2019-01-18 12:27:37 +00:00
|
|
|
#include "data/data_session.h"
|
2019-04-22 18:18:57 +00:00
|
|
|
#include "data/data_folder.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2022-06-11 00:07:22 +00:00
|
|
|
#include "core/core_settings.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2018-11-04 07:32:26 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2022-02-02 21:58:21 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
|
|
|
|
2022-02-23 07:25:46 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
class ShareBox::Inner final : public Ui::RpWidget {
|
2018-11-04 07:32:26 +00:00
|
|
|
public:
|
2021-03-10 17:36:21 +00:00
|
|
|
Inner(QWidget *parent, const Descriptor &descriptor);
|
2018-11-04 07:32:26 +00:00
|
|
|
|
|
|
|
void setPeerSelectedChangedCallback(
|
|
|
|
Fn<void(PeerData *peer, bool selected)> callback);
|
|
|
|
void peerUnselected(not_null<PeerData*> peer);
|
|
|
|
|
2019-09-13 06:06:02 +00:00
|
|
|
std::vector<not_null<PeerData*>> selected() const;
|
2018-11-04 07:32:26 +00:00
|
|
|
bool hasSelected() const;
|
|
|
|
|
|
|
|
void peopleReceived(
|
|
|
|
const QString &query,
|
|
|
|
const QVector<MTPPeer> &my,
|
|
|
|
const QVector<MTPPeer> &people);
|
|
|
|
|
|
|
|
void activateSkipRow(int direction);
|
|
|
|
void activateSkipColumn(int direction);
|
|
|
|
void activateSkipPage(int pageHeight, int direction);
|
|
|
|
void updateFilter(QString filter = QString());
|
|
|
|
void selectActive();
|
|
|
|
|
|
|
|
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
|
|
|
|
rpl::producer<> searchRequests() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2021-10-19 13:00:21 +00:00
|
|
|
void enterEventHook(QEnterEvent *e) override;
|
2018-11-04 07:32:26 +00:00
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Chat {
|
2021-03-10 17:36:21 +00:00
|
|
|
Chat(
|
|
|
|
PeerData *peer,
|
|
|
|
const style::PeerListItem &st,
|
|
|
|
Fn<void()> updateCallback);
|
2018-11-04 07:32:26 +00:00
|
|
|
|
|
|
|
PeerData *peer;
|
|
|
|
Ui::RoundImageCheckbox checkbox;
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String name;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple nameActive;
|
2018-11-04 07:32:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void invalidateCache();
|
|
|
|
|
|
|
|
int displayedChatsCount() const;
|
2016-10-20 11:34:48 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void paintChat(Painter &p, not_null<Chat*> chat, int index);
|
2018-11-04 07:32:26 +00:00
|
|
|
void updateChat(not_null<PeerData*> peer);
|
|
|
|
void updateChatName(not_null<Chat*> chat, not_null<PeerData*> peer);
|
|
|
|
void repaintChat(not_null<PeerData*> peer);
|
|
|
|
int chatIndex(not_null<PeerData*> peer) const;
|
|
|
|
void repaintChatAtIndex(int index);
|
|
|
|
Chat *getChatAtIndex(int index);
|
|
|
|
|
|
|
|
void loadProfilePhotos(int yFrom);
|
|
|
|
void changeCheckState(Chat *chat);
|
|
|
|
enum class ChangeStateWay {
|
|
|
|
Default,
|
|
|
|
SkipCallback,
|
|
|
|
};
|
|
|
|
void changePeerCheckState(
|
|
|
|
not_null<Chat*> chat,
|
|
|
|
bool checked,
|
|
|
|
ChangeStateWay useCallback = ChangeStateWay::Default);
|
|
|
|
|
|
|
|
not_null<Chat*> getChat(not_null<Dialogs::Row*> row);
|
|
|
|
void setActive(int active);
|
|
|
|
void updateUpon(const QPoint &pos);
|
|
|
|
|
|
|
|
void refresh();
|
|
|
|
|
2021-03-10 17:36:21 +00:00
|
|
|
const Descriptor &_descriptor;
|
|
|
|
const style::PeerList &_st;
|
2019-07-25 18:55:11 +00:00
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
float64 _columnSkip = 0.;
|
|
|
|
float64 _rowWidthReal = 0.;
|
|
|
|
int _rowsLeft = 0;
|
|
|
|
int _rowsTop = 0;
|
|
|
|
int _rowWidth = 0;
|
|
|
|
int _rowHeight = 0;
|
|
|
|
int _columnCount = 4;
|
|
|
|
int _active = -1;
|
|
|
|
int _upon = -1;
|
|
|
|
|
|
|
|
std::unique_ptr<Dialogs::IndexedList> _chatsIndexed;
|
|
|
|
QString _filter;
|
2019-04-22 18:18:57 +00:00
|
|
|
std::vector<not_null<Dialogs::Row*>> _filtered;
|
2018-11-04 07:32:26 +00:00
|
|
|
|
|
|
|
std::map<not_null<PeerData*>, std::unique_ptr<Chat>> _dataMap;
|
|
|
|
base::flat_set<not_null<PeerData*>> _selected;
|
|
|
|
|
|
|
|
Fn<void(PeerData *peer, bool selected)> _peerSelectedChangedCallback;
|
|
|
|
|
|
|
|
bool _searching = false;
|
|
|
|
QString _lastQuery;
|
|
|
|
std::vector<PeerData*> _byUsernameFiltered;
|
|
|
|
std::vector<std::unique_ptr<Chat>> d_byUsernameFiltered;
|
|
|
|
|
|
|
|
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
|
|
|
rpl::event_stream<> _searchRequests;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-03-10 16:38:15 +00:00
|
|
|
ShareBox::ShareBox(QWidget*, Descriptor &&descriptor)
|
|
|
|
: _descriptor(std::move(descriptor))
|
|
|
|
, _api(&_descriptor.session->mtp())
|
2022-03-06 13:27:04 +00:00
|
|
|
, _show(std::make_shared<Ui::BoxShow>(this))
|
2018-11-04 07:32:26 +00:00
|
|
|
, _select(
|
|
|
|
this,
|
2021-03-10 17:36:21 +00:00
|
|
|
(_descriptor.stMultiSelect
|
|
|
|
? *_descriptor.stMultiSelect
|
|
|
|
: st::defaultMultiSelect),
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_participant_filter())
|
2018-11-04 07:32:26 +00:00
|
|
|
, _comment(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::InputField>(
|
|
|
|
this,
|
2021-03-10 17:36:21 +00:00
|
|
|
(_descriptor.stComment
|
|
|
|
? *_descriptor.stComment
|
|
|
|
: st::shareComment),
|
2018-11-04 07:32:26 +00:00
|
|
|
Ui::InputField::Mode::MultiLine,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_photos_comment()),
|
2018-11-04 07:32:26 +00:00
|
|
|
st::shareCommentPadding)
|
2021-03-10 17:06:34 +00:00
|
|
|
, _bottomWidget(std::move(_descriptor.bottomWidget))
|
2021-03-12 18:22:19 +00:00
|
|
|
, _copyLinkText(_descriptor.copyLinkText
|
|
|
|
? std::move(_descriptor.copyLinkText)
|
|
|
|
: tr::lng_share_copy_link())
|
2018-11-04 07:32:26 +00:00
|
|
|
, _searchTimer([=] { searchByUsername(); }) {
|
2021-03-10 17:06:34 +00:00
|
|
|
if (_bottomWidget) {
|
|
|
|
_bottomWidget->setParent(this);
|
|
|
|
_bottomWidget->resizeToWidth(st::boxWideWidth);
|
|
|
|
_bottomWidget->show();
|
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareBox::prepareCommentField() {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
_comment->hide(anim::type::instant);
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
heightValue(),
|
|
|
|
_comment->heightValue(),
|
2021-03-10 17:06:34 +00:00
|
|
|
(_bottomWidget
|
|
|
|
? _bottomWidget->heightValue()
|
|
|
|
: (rpl::single(0) | rpl::type_erased()))
|
|
|
|
) | rpl::start_with_next([=](int height, int comment, int bottom) {
|
|
|
|
_comment->moveToLeft(0, height - bottom - comment);
|
|
|
|
if (_bottomWidget) {
|
|
|
|
_bottomWidget->moveToLeft(0, height - bottom);
|
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
}, _comment->lifetime());
|
|
|
|
|
|
|
|
const auto field = _comment->entity();
|
|
|
|
|
|
|
|
connect(field, &Ui::InputField::submitted, [=] {
|
2019-08-12 12:11:34 +00:00
|
|
|
submit({});
|
2018-11-04 07:32:26 +00:00
|
|
|
});
|
2022-07-01 13:36:58 +00:00
|
|
|
if (_show->valid()) {
|
|
|
|
InitMessageFieldHandlers(
|
|
|
|
_descriptor.session,
|
|
|
|
_show,
|
|
|
|
field,
|
|
|
|
nullptr,
|
2022-07-15 14:52:36 +00:00
|
|
|
nullptr,
|
2022-07-01 13:36:58 +00:00
|
|
|
_descriptor.stLabel);
|
2021-03-10 16:38:15 +00:00
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
field->setSubmitSettings(Core::App().settings().sendSubmitWay());
|
2018-11-04 07:32:26 +00:00
|
|
|
|
|
|
|
Ui::SendPendingMoveResizeEvents(_comment);
|
2021-03-10 17:06:34 +00:00
|
|
|
if (_bottomWidget) {
|
|
|
|
Ui::SendPendingMoveResizeEvents(_bottomWidget);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareBox::prepare() {
|
2018-11-04 07:32:26 +00:00
|
|
|
prepareCommentField();
|
|
|
|
|
2016-10-22 13:03:20 +00:00
|
|
|
_select->resizeToWidth(st::boxWideWidth);
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(_select);
|
2016-10-22 13:03:20 +00:00
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_share_title());
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
_inner = setInnerWidget(
|
2021-03-10 17:36:21 +00:00
|
|
|
object_ptr<Inner>(this, _descriptor),
|
2018-11-04 07:32:26 +00:00
|
|
|
getTopScrollSkip(),
|
|
|
|
getBottomScrollSkip());
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
createButtons();
|
|
|
|
|
|
|
|
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
_select->setQueryChangedCallback([=](const QString &query) {
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate(query);
|
2018-11-04 07:32:26 +00:00
|
|
|
});
|
|
|
|
_select->setItemRemovedCallback([=](uint64 itemId) {
|
2021-04-01 21:04:10 +00:00
|
|
|
if (const auto peer = _descriptor.session->data().peerLoaded(PeerId(itemId))) {
|
2016-10-22 13:03:20 +00:00
|
|
|
_inner->peerUnselected(peer);
|
2018-11-04 07:32:26 +00:00
|
|
|
selectedChanged();
|
2016-10-22 13:03:20 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
});
|
2018-11-04 07:32:26 +00:00
|
|
|
_select->setResizedCallback([=] { updateScrollSkips(); });
|
|
|
|
_select->setSubmittedCallback([=](Qt::KeyboardModifiers modifiers) {
|
2018-05-31 12:20:28 +00:00
|
|
|
if (modifiers.testFlag(Qt::ControlModifier)
|
|
|
|
|| modifiers.testFlag(Qt::MetaModifier)) {
|
2019-08-12 12:11:34 +00:00
|
|
|
submit({});
|
2018-05-31 12:20:28 +00:00
|
|
|
} else {
|
2018-11-04 07:32:26 +00:00
|
|
|
_inner->selectActive();
|
2018-05-31 12:20:28 +00:00
|
|
|
}
|
|
|
|
});
|
2021-03-10 17:06:34 +00:00
|
|
|
rpl::combine(
|
|
|
|
_comment->heightValue(),
|
|
|
|
(_bottomWidget
|
|
|
|
? _bottomWidget->heightValue()
|
|
|
|
: rpl::single(0) | rpl::type_erased())
|
2018-11-04 07:32:26 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateScrollSkips();
|
|
|
|
}, _comment->lifetime());
|
|
|
|
|
|
|
|
_inner->searchRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
needSearchByUsername();
|
|
|
|
}, _inner->lifetime());
|
|
|
|
|
|
|
|
_inner->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([=](const Ui::ScrollToRequest &request) {
|
|
|
|
scrollTo(request);
|
|
|
|
}, _inner->lifetime());
|
|
|
|
|
|
|
|
_inner->setPeerSelectedChangedCallback([=](PeerData *peer, bool checked) {
|
|
|
|
innerSelectedChanged(peer, checked);
|
2016-10-22 13:03:20 +00:00
|
|
|
});
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
Ui::Emoji::SuggestionsController::Init(
|
|
|
|
getDelegate()->outerContainer(),
|
2019-08-02 10:40:35 +00:00
|
|
|
_comment->entity(),
|
2021-03-10 16:38:15 +00:00
|
|
|
_descriptor.session);
|
2018-11-21 10:09:46 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_select->raise();
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-22 13:03:20 +00:00
|
|
|
int ShareBox::getTopScrollSkip() const {
|
2018-11-04 07:32:26 +00:00
|
|
|
return _select->isHidden() ? 0 : _select->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ShareBox::getBottomScrollSkip() const {
|
2021-03-10 17:06:34 +00:00
|
|
|
return (_comment->isHidden() ? 0 : _comment->height())
|
|
|
|
+ (_bottomWidget ? _bottomWidget->height() : 0);
|
2018-11-04 07:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ShareBox::contentHeight() const {
|
|
|
|
return height() - getTopScrollSkip() - getBottomScrollSkip();
|
2016-10-22 13:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareBox::updateScrollSkips() {
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerTopSkip(getTopScrollSkip(), true);
|
2018-11-04 07:32:26 +00:00
|
|
|
setInnerBottomSkip(getBottomScrollSkip());
|
2016-10-22 13:03:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
bool ShareBox::searchByUsername(bool searchCache) {
|
2016-10-22 13:03:20 +00:00
|
|
|
auto query = _select->getQuery();
|
2016-09-06 12:28:37 +00:00
|
|
|
if (query.isEmpty()) {
|
|
|
|
if (_peopleRequest) {
|
|
|
|
_peopleRequest = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-22 10:58:11 +00:00
|
|
|
if (!query.isEmpty()) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (searchCache) {
|
|
|
|
auto i = _peopleCache.constFind(query);
|
|
|
|
if (i != _peopleCache.cend()) {
|
|
|
|
_peopleQuery = query;
|
|
|
|
_peopleRequest = 0;
|
2020-06-11 16:09:46 +00:00
|
|
|
peopleDone(i.value(), 0);
|
2016-09-06 12:28:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (_peopleQuery != query) {
|
|
|
|
_peopleQuery = query;
|
|
|
|
_peopleFull = false;
|
2020-06-11 16:09:46 +00:00
|
|
|
_peopleRequest = _api.request(MTPcontacts_Search(
|
|
|
|
MTP_string(_peopleQuery),
|
|
|
|
MTP_int(SearchPeopleLimit)
|
|
|
|
)).done([=](const MTPcontacts_Found &result, mtpRequestId requestId) {
|
|
|
|
peopleDone(result, requestId);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error, mtpRequestId requestId) {
|
2020-06-11 16:09:46 +00:00
|
|
|
peopleFail(error, requestId);
|
|
|
|
}).send();
|
2016-09-06 12:28:37 +00:00
|
|
|
_peopleQueries.insert(_peopleRequest, _peopleQuery);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::needSearchByUsername() {
|
|
|
|
if (!searchByUsername(true)) {
|
|
|
|
_searchTimer.callOnce(AutoSearchTimeout);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
void ShareBox::peopleDone(
|
2018-01-22 10:58:11 +00:00
|
|
|
const MTPcontacts_Found &result,
|
|
|
|
mtpRequestId requestId) {
|
|
|
|
Expects(result.type() == mtpc_contacts_found);
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
auto query = _peopleQuery;
|
|
|
|
|
|
|
|
auto i = _peopleQueries.find(requestId);
|
|
|
|
if (i != _peopleQueries.cend()) {
|
|
|
|
query = i.value();
|
|
|
|
_peopleCache[query] = result;
|
|
|
|
_peopleQueries.erase(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_peopleRequest == requestId) {
|
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_contacts_found: {
|
|
|
|
auto &found = result.c_contacts_found();
|
2021-03-10 16:38:15 +00:00
|
|
|
_descriptor.session->data().processUsers(found.vusers());
|
|
|
|
_descriptor.session->data().processChats(found.vchats());
|
2018-01-22 10:58:11 +00:00
|
|
|
_inner->peopleReceived(
|
|
|
|
query,
|
2019-07-05 13:38:38 +00:00
|
|
|
found.vmy_results().v,
|
|
|
|
found.vresults().v);
|
2016-09-06 12:28:37 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_peopleRequest = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void ShareBox::peopleFail(const MTP::Error &error, mtpRequestId requestId) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (_peopleRequest == requestId) {
|
|
|
|
_peopleRequest = 0;
|
|
|
|
_peopleFull = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ShareBox::setInnerFocus() {
|
2018-11-04 07:32:26 +00:00
|
|
|
if (_comment->isHidden()) {
|
|
|
|
_select->setInnerFocus();
|
|
|
|
} else {
|
|
|
|
_comment->entity()->setFocusFast();
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2016-10-22 13:03:20 +00:00
|
|
|
|
|
|
|
_select->resizeToWidth(width());
|
2016-12-13 17:07:56 +00:00
|
|
|
_select->moveToLeft(0, 0);
|
2016-10-22 13:03:20 +00:00
|
|
|
|
|
|
|
updateScrollSkips();
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
_inner->resizeToWidth(width());
|
|
|
|
}
|
|
|
|
|
2016-09-06 14:45:10 +00:00
|
|
|
void ShareBox::keyPressEvent(QKeyEvent *e) {
|
2016-10-22 13:03:20 +00:00
|
|
|
auto focused = focusWidget();
|
|
|
|
if (_select == focused || _select->isAncestorOf(focusWidget())) {
|
2016-09-06 14:45:10 +00:00
|
|
|
if (e->key() == Qt::Key_Up) {
|
|
|
|
_inner->activateSkipColumn(-1);
|
|
|
|
} else if (e->key() == Qt::Key_Down) {
|
|
|
|
_inner->activateSkipColumn(1);
|
|
|
|
} else if (e->key() == Qt::Key_PageUp) {
|
2018-11-04 07:32:26 +00:00
|
|
|
_inner->activateSkipPage(contentHeight(), -1);
|
2016-09-06 14:45:10 +00:00
|
|
|
} else if (e->key() == Qt::Key_PageDown) {
|
2018-11-04 07:32:26 +00:00
|
|
|
_inner->activateSkipPage(contentHeight(), 1);
|
2016-09-06 14:45:10 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-10 12:22:54 +00:00
|
|
|
SendMenu::Type ShareBox::sendMenuType() const {
|
2019-08-28 16:46:47 +00:00
|
|
|
const auto selected = _inner->selected();
|
2020-01-15 02:31:28 +00:00
|
|
|
return ranges::all_of(selected, HistoryView::CanScheduleUntilOnline)
|
2020-08-10 12:22:54 +00:00
|
|
|
? SendMenu::Type::ScheduledToUser
|
2020-01-15 02:31:28 +00:00
|
|
|
: (selected.size() == 1 && selected.front()->isSelf())
|
2020-08-10 12:22:54 +00:00
|
|
|
? SendMenu::Type::Reminder
|
|
|
|
: SendMenu::Type::Scheduled;
|
2019-08-28 16:46:47 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 21:58:21 +00:00
|
|
|
void ShareBox::showMenu(not_null<Ui::RpWidget*> parent) {
|
|
|
|
if (_menu) {
|
|
|
|
_menu = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_menu.emplace(parent, st::popupMenuWithIcons);
|
|
|
|
|
|
|
|
if (_descriptor.forwardOptions.show) {
|
|
|
|
auto createView = [&](rpl::producer<QString> &&text, bool checked) {
|
2022-03-27 12:46:27 +00:00
|
|
|
auto item = base::make_unique_q<Menu::ItemWithCheck>(
|
2022-02-02 21:58:21 +00:00
|
|
|
_menu->menu(),
|
|
|
|
st::popupMenuWithIcons.menu,
|
|
|
|
new QAction(QString(), _menu->menu()),
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
std::move(
|
|
|
|
text
|
|
|
|
) | rpl::start_with_next([action = item->action()](QString text) {
|
|
|
|
action->setText(text);
|
|
|
|
}, item->lifetime());
|
|
|
|
item->init(checked);
|
|
|
|
const auto view = item->checkView();
|
|
|
|
_menu->addAction(std::move(item));
|
|
|
|
return view;
|
|
|
|
};
|
|
|
|
Ui::FillForwardOptions(
|
|
|
|
std::move(createView),
|
|
|
|
_descriptor.forwardOptions.messagesCount,
|
|
|
|
_forwardOptions,
|
|
|
|
[=](Ui::ForwardOptions value) { _forwardOptions = value; },
|
|
|
|
_menu->lifetime());
|
|
|
|
|
|
|
|
_menu->addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto result = SendMenu::FillSendMenu(
|
|
|
|
_menu.get(),
|
|
|
|
sendMenuType(),
|
|
|
|
[=] { submitSilent(); },
|
|
|
|
[=] { submitScheduled(); });
|
|
|
|
const auto success = (result == SendMenu::FillMenuResult::Success);
|
|
|
|
if (_descriptor.forwardOptions.show || success) {
|
2022-03-16 06:29:48 +00:00
|
|
|
_menu->setForcedVerticalOrigin(Ui::PopupMenu::VerticalOrigin::Bottom);
|
2022-02-02 21:58:21 +00:00
|
|
|
_menu->popup(QCursor::pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ShareBox::createButtons() {
|
|
|
|
clearButtons();
|
|
|
|
if (_hasSelected) {
|
2019-07-26 16:06:22 +00:00
|
|
|
const auto send = addButton(tr::lng_share_confirm(), [=] {
|
2019-08-12 12:11:34 +00:00
|
|
|
submit({});
|
2019-07-26 16:06:22 +00:00
|
|
|
});
|
2022-02-02 21:58:21 +00:00
|
|
|
_forwardOptions.hasCaptions = _descriptor.forwardOptions.hasCaptions;
|
|
|
|
|
|
|
|
send->setAcceptBoth();
|
|
|
|
send->clicks(
|
|
|
|
) | rpl::start_with_next([=](Qt::MouseButton button) {
|
|
|
|
if (button == Qt::RightButton) {
|
|
|
|
showMenu(send);
|
|
|
|
}
|
|
|
|
}, send->lifetime());
|
2021-03-10 16:38:15 +00:00
|
|
|
} else if (_descriptor.copyCallback) {
|
2021-03-12 18:22:19 +00:00
|
|
|
addButton(_copyLinkText.value(), [=] { copyLink(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-29 08:11:54 +00:00
|
|
|
void ShareBox::applyFilterUpdate(const QString &query) {
|
2022-02-23 01:11:34 +00:00
|
|
|
scrollToY(0);
|
2016-10-22 13:03:20 +00:00
|
|
|
_inner->updateFilter(query);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-22 13:03:20 +00:00
|
|
|
void ShareBox::addPeerToMultiSelect(PeerData *peer, bool skipAnimation) {
|
|
|
|
using AddItemWay = Ui::MultiSelect::AddItemWay;
|
|
|
|
auto addItemWay = skipAnimation ? AddItemWay::SkipAnimation : AddItemWay::Default;
|
2017-12-05 14:07:01 +00:00
|
|
|
_select->addItem(
|
2021-04-01 21:04:10 +00:00
|
|
|
peer->id.value,
|
2019-06-19 15:09:03 +00:00
|
|
|
peer->isSelf() ? tr::lng_saved_short(tr::now) : peer->shortName(),
|
2017-12-05 14:07:01 +00:00
|
|
|
st::activeButtonBg,
|
|
|
|
PaintUserpicCallback(peer, true),
|
|
|
|
addItemWay);
|
2016-10-22 13:03:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::innerSelectedChanged(PeerData *peer, bool checked) {
|
2016-10-22 13:03:20 +00:00
|
|
|
if (checked) {
|
|
|
|
addPeerToMultiSelect(peer);
|
|
|
|
_select->clearQuery();
|
|
|
|
} else {
|
2021-04-01 21:04:10 +00:00
|
|
|
_select->removeItem(peer->id.value);
|
2016-10-22 13:03:20 +00:00
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
selectedChanged();
|
2016-10-22 13:03:20 +00:00
|
|
|
update();
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 12:11:34 +00:00
|
|
|
void ShareBox::submit(Api::SendOptions options) {
|
2021-03-10 16:38:15 +00:00
|
|
|
if (const auto onstack = _descriptor.submitCallback) {
|
2022-02-02 21:58:21 +00:00
|
|
|
const auto forwardOptions = (_forwardOptions.hasCaptions
|
|
|
|
&& _forwardOptions.dropCaptions)
|
|
|
|
? Data::ForwardOptions::NoNamesAndCaptions
|
|
|
|
: _forwardOptions.dropNames
|
|
|
|
? Data::ForwardOptions::NoSenderNames
|
|
|
|
: Data::ForwardOptions::PreserveInfo;
|
2021-03-10 16:38:15 +00:00
|
|
|
onstack(
|
2018-11-04 07:32:26 +00:00
|
|
|
_inner->selected(),
|
2019-07-26 16:06:22 +00:00
|
|
|
_comment->entity()->getTextWithAppliedMarkdown(),
|
2022-02-02 21:58:21 +00:00
|
|
|
options,
|
|
|
|
forwardOptions);
|
2016-09-19 10:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 12:11:34 +00:00
|
|
|
void ShareBox::submitSilent() {
|
2021-11-09 15:24:13 +00:00
|
|
|
submit({ .silent = true });
|
2019-08-12 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareBox::submitScheduled() {
|
2019-08-20 13:21:10 +00:00
|
|
|
const auto callback = [=](Api::SendOptions options) { submit(options); };
|
2022-03-06 13:27:04 +00:00
|
|
|
_show->showBox(
|
2022-03-06 09:40:51 +00:00
|
|
|
HistoryView::PrepareScheduleBox(
|
|
|
|
this,
|
|
|
|
sendMenuType(),
|
|
|
|
callback,
|
|
|
|
HistoryView::DefaultScheduleTime(),
|
|
|
|
_descriptor.scheduleBoxStyle),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2019-08-12 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::copyLink() {
|
2021-03-10 16:38:15 +00:00
|
|
|
if (const auto onstack = _descriptor.copyCallback) {
|
|
|
|
onstack();
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::selectedChanged() {
|
|
|
|
auto hasSelected = _inner->hasSelected();
|
|
|
|
if (_hasSelected != hasSelected) {
|
|
|
|
_hasSelected = hasSelected;
|
|
|
|
createButtons();
|
|
|
|
_comment->toggle(_hasSelected, anim::type::normal);
|
|
|
|
_comment->resizeToWidth(st::boxWideWidth);
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::scrollTo(Ui::ScrollToRequest request) {
|
2022-02-23 01:11:34 +00:00
|
|
|
scrollToY(request.ymin, request.ymax);
|
2016-12-13 17:07:56 +00:00
|
|
|
//auto scrollTop = scrollArea()->scrollTop(), scrollBottom = scrollTop + scrollArea()->height();
|
|
|
|
//auto from = scrollTop, to = scrollTop;
|
|
|
|
//if (scrollTop > top) {
|
|
|
|
// to = top;
|
|
|
|
//} else if (scrollBottom < bottom) {
|
|
|
|
// to = bottom - (scrollBottom - scrollTop);
|
|
|
|
//}
|
|
|
|
//if (from != to) {
|
|
|
|
// _scrollAnimation.start([this]() { scrollAnimationCallback(); }, from, to, st::shareScrollDuration, anim::sineInOut);
|
|
|
|
//}
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
void ShareBox::scrollAnimationCallback() {
|
2016-12-13 17:07:56 +00:00
|
|
|
//auto scrollTop = qRound(_scrollAnimation.current(scrollArea()->scrollTop()));
|
|
|
|
//scrollArea()->scrollToY(scrollTop);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 17:36:21 +00:00
|
|
|
ShareBox::Inner::Inner(QWidget *parent, const Descriptor &descriptor)
|
2018-11-04 07:32:26 +00:00
|
|
|
: RpWidget(parent)
|
2021-03-10 17:36:21 +00:00
|
|
|
, _descriptor(descriptor)
|
|
|
|
, _st(_descriptor.st ? *_descriptor.st : st::shareBoxList)
|
2018-11-04 07:32:26 +00:00
|
|
|
, _chatsIndexed(
|
|
|
|
std::make_unique<Dialogs::IndexedList>(
|
|
|
|
Dialogs::SortMode::Add)) {
|
2016-09-06 12:28:37 +00:00
|
|
|
_rowsTop = st::shareRowsTop;
|
|
|
|
_rowHeight = st::shareRowHeight;
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
|
2021-03-10 17:36:21 +00:00
|
|
|
const auto self = _descriptor.session->user();
|
|
|
|
if (_descriptor.filterCallback(self)) {
|
2019-01-18 12:27:37 +00:00
|
|
|
_chatsIndexed->addToEnd(self->owner().history(self));
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2019-04-22 18:18:57 +00:00
|
|
|
const auto addList = [&](not_null<Dialogs::IndexedList*> list) {
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &row : list->all()) {
|
2019-04-22 18:18:57 +00:00
|
|
|
if (const auto history = row->history()) {
|
|
|
|
if (!history->peer->isSelf()
|
2021-03-10 17:36:21 +00:00
|
|
|
&& _descriptor.filterCallback(history->peer)) {
|
2019-04-22 18:18:57 +00:00
|
|
|
_chatsIndexed->addToEnd(history);
|
|
|
|
}
|
2018-01-04 09:40:58 +00:00
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2019-04-22 18:18:57 +00:00
|
|
|
};
|
2021-03-10 17:36:21 +00:00
|
|
|
addList(_descriptor.session->data().chatsList()->indexed());
|
2019-04-22 18:18:57 +00:00
|
|
|
const auto id = Data::Folder::kId;
|
2021-03-10 17:36:21 +00:00
|
|
|
if (const auto folder = _descriptor.session->data().folderLoaded(id)) {
|
2019-04-22 18:18:57 +00:00
|
|
|
addList(folder->chatsList()->indexed());
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2021-03-10 17:36:21 +00:00
|
|
|
addList(_descriptor.session->data().contactsNoChatsList());
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
_filter = qsl("a");
|
|
|
|
updateFilter();
|
|
|
|
|
2021-03-10 17:36:21 +00:00
|
|
|
_descriptor.session->changes().peerUpdates(
|
2020-06-12 12:12:34 +00:00
|
|
|
Data::PeerUpdate::Flag::Photo
|
|
|
|
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
|
|
|
updateChat(update.peer);
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-03-10 17:36:21 +00:00
|
|
|
_descriptor.session->changes().realtimeNameUpdates(
|
2020-06-12 12:12:34 +00:00
|
|
|
) | rpl::start_with_next([=](const Data::NameUpdate &update) {
|
|
|
|
_chatsIndexed->peerNameChanged(
|
|
|
|
update.peer,
|
|
|
|
update.oldFirstLetters);
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-03-10 17:36:21 +00:00
|
|
|
_descriptor.session->downloaderTaskFinished(
|
2020-07-01 08:03:34 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2019-07-25 18:55:11 +00:00
|
|
|
update();
|
2020-07-01 08:03:34 +00:00
|
|
|
}, lifetime());
|
2016-12-20 13:03:51 +00:00
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
style::PaletteChanged(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
invalidateCache();
|
|
|
|
}, lifetime());
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareBox::Inner::invalidateCache() {
|
2018-11-04 07:32:26 +00:00
|
|
|
for (const auto &[peer, data] : _dataMap) {
|
2016-12-20 13:03:51 +00:00
|
|
|
data->checkbox.invalidateCache();
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
void ShareBox::Inner::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
2016-09-06 12:28:37 +00:00
|
|
|
loadProfilePhotos(visibleTop);
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::activateSkipRow(int direction) {
|
2016-09-06 14:45:10 +00:00
|
|
|
activateSkipColumn(direction * _columnCount);
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
int ShareBox::Inner::displayedChatsCount() const {
|
2016-09-06 14:45:10 +00:00
|
|
|
return _filter.isEmpty() ? _chatsIndexed->size() : (_filtered.size() + d_byUsernameFiltered.size());
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::activateSkipColumn(int direction) {
|
2016-09-06 14:45:10 +00:00
|
|
|
if (_active < 0) {
|
|
|
|
if (direction > 0) {
|
|
|
|
setActive(0);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto count = displayedChatsCount();
|
|
|
|
auto active = _active + direction;
|
|
|
|
if (active < 0) {
|
|
|
|
active = (_active > 0) ? 0 : -1;
|
|
|
|
}
|
|
|
|
if (active >= count) {
|
|
|
|
active = count - 1;
|
|
|
|
}
|
|
|
|
setActive(active);
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::activateSkipPage(int pageHeight, int direction) {
|
2016-09-06 14:45:10 +00:00
|
|
|
activateSkipRow(direction * (pageHeight / _rowHeight));
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void ShareBox::Inner::updateChat(not_null<PeerData*> peer) {
|
2018-11-04 07:32:26 +00:00
|
|
|
if (const auto i = _dataMap.find(peer); i != end(_dataMap)) {
|
|
|
|
updateChatName(i->second.get(), peer);
|
2016-09-06 12:28:37 +00:00
|
|
|
repaintChat(peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void ShareBox::Inner::updateChatName(
|
|
|
|
not_null<Chat*> chat,
|
|
|
|
not_null<PeerData*> peer) {
|
2020-09-11 15:33:26 +00:00
|
|
|
const auto text = peer->isSelf()
|
|
|
|
? tr::lng_saved_messages(tr::now)
|
|
|
|
: peer->isRepliesChat()
|
|
|
|
? tr::lng_replies_messages(tr::now)
|
|
|
|
: peer->name;
|
2021-03-10 17:36:21 +00:00
|
|
|
chat->name.setText(_st.item.nameStyle, text, Ui::NameTextOptions());
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::repaintChatAtIndex(int index) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (index < 0) return;
|
|
|
|
|
|
|
|
auto row = index / _columnCount;
|
|
|
|
auto column = index % _columnCount;
|
2019-09-13 12:22:54 +00:00
|
|
|
update(style::rtlrect(_rowsLeft + qFloor(column * _rowWidthReal), row * _rowHeight, _rowWidth, _rowHeight, width()));
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
ShareBox::Inner::Chat *ShareBox::Inner::getChatAtIndex(int index) {
|
2018-11-04 07:32:26 +00:00
|
|
|
if (index < 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto row = [=] {
|
|
|
|
if (_filter.isEmpty()) {
|
|
|
|
return _chatsIndexed->rowAtY(index, 1);
|
|
|
|
}
|
|
|
|
return (index < _filtered.size())
|
2019-04-22 18:18:57 +00:00
|
|
|
? _filtered[index].get()
|
2018-11-04 07:32:26 +00:00
|
|
|
: nullptr;
|
|
|
|
}();
|
2016-09-06 14:45:10 +00:00
|
|
|
if (row) {
|
|
|
|
return static_cast<Chat*>(row->attached);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_filter.isEmpty()) {
|
|
|
|
index -= _filtered.size();
|
|
|
|
if (index >= 0 && index < d_byUsernameFiltered.size()) {
|
2018-11-04 07:32:26 +00:00
|
|
|
return d_byUsernameFiltered[index].get();
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void ShareBox::Inner::repaintChat(not_null<PeerData*> peer) {
|
2016-09-06 12:28:37 +00:00
|
|
|
repaintChatAtIndex(chatIndex(peer));
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
int ShareBox::Inner::chatIndex(not_null<PeerData*> peer) const {
|
2016-09-06 12:28:37 +00:00
|
|
|
int index = 0;
|
|
|
|
if (_filter.isEmpty()) {
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &row : _chatsIndexed->all()) {
|
2018-01-22 09:33:09 +00:00
|
|
|
if (const auto history = row->history()) {
|
|
|
|
if (history->peer == peer) {
|
|
|
|
return index;
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
} else {
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &row : _filtered) {
|
2018-01-22 09:33:09 +00:00
|
|
|
if (const auto history = row->history()) {
|
|
|
|
if (history->peer == peer) {
|
|
|
|
return index;
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
++index;
|
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
for (const auto &row : d_byUsernameFiltered) {
|
2016-09-06 14:45:10 +00:00
|
|
|
if (row->peer == peer) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
++index;
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::loadProfilePhotos(int yFrom) {
|
2016-11-05 08:36:24 +00:00
|
|
|
if (!parentWidget()) return;
|
2016-09-06 12:28:37 +00:00
|
|
|
if (yFrom < 0) {
|
|
|
|
yFrom = 0;
|
|
|
|
}
|
|
|
|
if (auto part = (yFrom % _rowHeight)) {
|
|
|
|
yFrom -= part;
|
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
int yTo = yFrom + parentWidget()->height() * 5 * _columnCount;
|
2016-09-06 12:28:37 +00:00
|
|
|
if (!yTo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
yFrom *= _columnCount;
|
|
|
|
yTo *= _columnCount;
|
|
|
|
|
|
|
|
if (_filter.isEmpty()) {
|
2019-04-16 14:05:56 +00:00
|
|
|
if (!_chatsIndexed->empty()) {
|
2016-09-06 12:28:37 +00:00
|
|
|
auto i = _chatsIndexed->cfind(yFrom, _rowHeight);
|
|
|
|
for (auto end = _chatsIndexed->cend(); i != end; ++i) {
|
|
|
|
if (((*i)->pos() * _rowHeight) >= yTo) {
|
|
|
|
break;
|
|
|
|
}
|
2018-01-22 09:33:09 +00:00
|
|
|
(*i)->entry()->loadUserpic();
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
} else if (!_filtered.empty()) {
|
2016-09-06 12:28:37 +00:00
|
|
|
int from = yFrom / _rowHeight;
|
|
|
|
if (from < 0) from = 0;
|
|
|
|
if (from < _filtered.size()) {
|
|
|
|
int to = (yTo / _rowHeight) + 1;
|
|
|
|
if (to > _filtered.size()) to = _filtered.size();
|
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
2018-01-22 09:33:09 +00:00
|
|
|
_filtered[from]->entry()->loadUserpic();
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
auto ShareBox::Inner::getChat(not_null<Dialogs::Row*> row)
|
|
|
|
-> not_null<Chat*> {
|
2018-01-22 09:33:09 +00:00
|
|
|
Expects(row->history() != nullptr);
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
if (const auto data = static_cast<Chat*>(row->attached)) {
|
|
|
|
return data;
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
const auto peer = row->history()->peer;
|
|
|
|
if (const auto i = _dataMap.find(peer); i != end(_dataMap)) {
|
|
|
|
row->attached = i->second.get();
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
const auto [i, ok] = _dataMap.emplace(
|
|
|
|
peer,
|
2021-03-10 17:36:21 +00:00
|
|
|
std::make_unique<Chat>(peer, _st.item, [=] { repaintChat(peer); }));
|
2018-11-04 07:32:26 +00:00
|
|
|
updateChatName(i->second.get(), peer);
|
|
|
|
row->attached = i->second.get();
|
|
|
|
return i->second.get();
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::setActive(int active) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (active != _active) {
|
2016-11-07 11:24:19 +00:00
|
|
|
auto changeNameFg = [this](int index, float64 from, float64 to) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (auto chat = getChatAtIndex(index)) {
|
2016-11-07 11:24:19 +00:00
|
|
|
chat->nameActive.start([this, peer = chat->peer] {
|
2016-10-20 11:34:48 +00:00
|
|
|
repaintChat(peer);
|
2016-11-07 11:24:19 +00:00
|
|
|
}, from, to, st::shareActivateDuration);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
};
|
2016-11-07 11:24:19 +00:00
|
|
|
changeNameFg(_active, 1., 0.);
|
2016-09-06 12:28:37 +00:00
|
|
|
_active = active;
|
2016-11-07 11:24:19 +00:00
|
|
|
changeNameFg(_active, 0., 1.);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2016-09-06 14:45:10 +00:00
|
|
|
auto y = (_active < _columnCount) ? 0 : (_rowsTop + ((_active / _columnCount) * _rowHeight));
|
2018-11-04 07:32:26 +00:00
|
|
|
_scrollToRequests.fire({ y, y + _rowHeight });
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void ShareBox::Inner::paintChat(
|
|
|
|
Painter &p,
|
|
|
|
not_null<Chat*> chat,
|
|
|
|
int index) {
|
2016-09-06 12:28:37 +00:00
|
|
|
auto x = _rowsLeft + qFloor((index % _columnCount) * _rowWidthReal);
|
|
|
|
auto y = _rowsTop + (index / _columnCount) * _rowHeight;
|
|
|
|
|
2016-10-20 11:34:48 +00:00
|
|
|
auto outerWidth = width();
|
2021-03-10 17:36:21 +00:00
|
|
|
auto photoLeft = (_rowWidth - (_st.item.checkbox.imageRadius * 2)) / 2;
|
2016-09-06 12:28:37 +00:00
|
|
|
auto photoTop = st::sharePhotoTop;
|
2019-04-02 09:13:30 +00:00
|
|
|
chat->checkbox.paint(p, x + photoLeft, y + photoTop, outerWidth);
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
auto nameActive = chat->nameActive.value((index == _active) ? 1. : 0.);
|
2021-03-10 17:36:21 +00:00
|
|
|
p.setPen(anim::pen(_st.item.nameFg, _st.item.nameFgChecked, nameActive));
|
2016-09-26 12:09:59 +00:00
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
auto nameWidth = (_rowWidth - st::shareColumnSkip);
|
|
|
|
auto nameLeft = st::shareColumnSkip / 2;
|
2021-03-10 17:36:21 +00:00
|
|
|
auto nameTop = photoTop + _st.item.checkbox.imageRadius * 2 + st::shareNameTop;
|
2016-10-20 11:34:48 +00:00
|
|
|
chat->name.drawLeftElided(p, x + nameLeft, y + nameTop, nameWidth, outerWidth, 2, style::al_top, 0, -1, 0, true);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 17:36:21 +00:00
|
|
|
ShareBox::Inner::Chat::Chat(
|
|
|
|
PeerData *peer,
|
|
|
|
const style::PeerListItem &st,
|
|
|
|
Fn<void()> updateCallback)
|
2016-10-20 11:34:48 +00:00
|
|
|
: peer(peer)
|
2021-03-10 17:36:21 +00:00
|
|
|
, checkbox(st.checkbox, updateCallback, PaintUserpicCallback(peer, true))
|
|
|
|
, name(st.checkbox.imageRadius * 2) {
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::paintEvent(QPaintEvent *e) {
|
2016-09-06 12:28:37 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
auto r = e->rect();
|
|
|
|
p.setClipRect(r);
|
2021-03-10 17:36:21 +00:00
|
|
|
p.fillRect(r, _st.bg);
|
2016-09-06 12:28:37 +00:00
|
|
|
auto yFrom = r.y(), yTo = r.y() + r.height();
|
|
|
|
auto rowFrom = yFrom / _rowHeight;
|
|
|
|
auto rowTo = (yTo + _rowHeight - 1) / _rowHeight;
|
|
|
|
auto indexFrom = rowFrom * _columnCount;
|
|
|
|
auto indexTo = rowTo * _columnCount;
|
|
|
|
if (_filter.isEmpty()) {
|
2019-04-16 14:05:56 +00:00
|
|
|
if (!_chatsIndexed->empty()) {
|
2016-09-06 14:45:10 +00:00
|
|
|
auto i = _chatsIndexed->cfind(indexFrom, 1);
|
|
|
|
for (auto end = _chatsIndexed->cend(); i != end; ++i) {
|
|
|
|
if (indexFrom >= indexTo) {
|
|
|
|
break;
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2019-04-02 09:13:30 +00:00
|
|
|
paintChat(p, getChat(*i), indexFrom);
|
2016-09-06 14:45:10 +00:00
|
|
|
++indexFrom;
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.setFont(st::noContactsFont);
|
2021-03-10 17:36:21 +00:00
|
|
|
p.setPen(_st.about.textFg);
|
2018-03-09 18:13:47 +00:00
|
|
|
p.drawText(
|
|
|
|
rect().marginsRemoved(st::boxPadding),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_bot_no_chats(tr::now),
|
2018-03-09 18:13:47 +00:00
|
|
|
style::al_center);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-11-04 07:32:26 +00:00
|
|
|
if (_filtered.empty()
|
2018-03-09 18:13:47 +00:00
|
|
|
&& _byUsernameFiltered.empty()
|
|
|
|
&& !_searching) {
|
2016-09-06 12:28:37 +00:00
|
|
|
p.setFont(st::noContactsFont);
|
2021-03-10 17:36:21 +00:00
|
|
|
p.setPen(_st.about.textFg);
|
2018-03-09 18:13:47 +00:00
|
|
|
p.drawText(
|
|
|
|
rect().marginsRemoved(st::boxPadding),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_bot_chats_not_found(tr::now),
|
2018-03-09 18:13:47 +00:00
|
|
|
style::al_center);
|
2016-09-06 12:28:37 +00:00
|
|
|
} else {
|
2016-09-06 14:45:10 +00:00
|
|
|
auto filteredSize = _filtered.size();
|
|
|
|
if (filteredSize) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (indexFrom < 0) indexFrom = 0;
|
|
|
|
while (indexFrom < indexTo) {
|
|
|
|
if (indexFrom >= _filtered.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2019-04-02 09:13:30 +00:00
|
|
|
paintChat(p, getChat(_filtered[indexFrom]), indexFrom);
|
2016-09-06 12:28:37 +00:00
|
|
|
++indexFrom;
|
|
|
|
}
|
2016-09-06 14:45:10 +00:00
|
|
|
indexFrom -= filteredSize;
|
|
|
|
indexTo -= filteredSize;
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2018-01-22 09:33:09 +00:00
|
|
|
if (!_byUsernameFiltered.empty()) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (indexFrom < 0) indexFrom = 0;
|
|
|
|
while (indexFrom < indexTo) {
|
|
|
|
if (indexFrom >= d_byUsernameFiltered.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
paintChat(
|
|
|
|
p,
|
|
|
|
d_byUsernameFiltered[indexFrom].get(),
|
|
|
|
filteredSize + indexFrom);
|
2016-09-06 12:28:37 +00:00
|
|
|
++indexFrom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:00:21 +00:00
|
|
|
void ShareBox::Inner::enterEventHook(QEnterEvent *e) {
|
2016-09-06 12:28:37 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void ShareBox::Inner::leaveEventHook(QEvent *e) {
|
2016-09-06 12:28:37 +00:00
|
|
|
setMouseTracking(false);
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::mouseMoveEvent(QMouseEvent *e) {
|
2016-09-06 12:28:37 +00:00
|
|
|
updateUpon(e->pos());
|
|
|
|
setCursor((_upon >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::updateUpon(const QPoint &pos) {
|
2016-09-06 12:28:37 +00:00
|
|
|
auto x = pos.x(), y = pos.y();
|
|
|
|
auto row = (y - _rowsTop) / _rowHeight;
|
|
|
|
auto column = qFloor((x - _rowsLeft) / _rowWidthReal);
|
|
|
|
auto left = _rowsLeft + qFloor(column * _rowWidthReal) + st::shareColumnSkip / 2;
|
|
|
|
auto top = _rowsTop + row * _rowHeight + st::sharePhotoTop;
|
|
|
|
auto xupon = (x >= left) && (x < left + (_rowWidth - st::shareColumnSkip));
|
2021-03-10 17:36:21 +00:00
|
|
|
auto yupon = (y >= top) && (y < top + _st.item.checkbox.imageRadius * 2 + st::shareNameTop + _st.item.nameStyle.font->height * 2);
|
2016-09-06 12:28:37 +00:00
|
|
|
auto upon = (xupon && yupon) ? (row * _columnCount + column) : -1;
|
2016-09-06 14:45:10 +00:00
|
|
|
if (upon >= displayedChatsCount()) {
|
2016-09-06 12:28:37 +00:00
|
|
|
upon = -1;
|
|
|
|
}
|
|
|
|
_upon = upon;
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::mousePressEvent(QMouseEvent *e) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
updateUpon(e->pos());
|
2016-09-06 14:45:10 +00:00
|
|
|
changeCheckState(getChatAtIndex(_upon));
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::Inner::selectActive() {
|
2016-09-06 14:45:10 +00:00
|
|
|
changeCheckState(getChatAtIndex(_active > 0 ? _active : 0));
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::resizeEvent(QResizeEvent *e) {
|
2021-03-10 17:36:21 +00:00
|
|
|
_columnSkip = (width() - _columnCount * _st.item.checkbox.imageRadius * 2) / float64(_columnCount + 1);
|
|
|
|
_rowWidthReal = _st.item.checkbox.imageRadius * 2 + _columnSkip;
|
2016-09-06 12:28:37 +00:00
|
|
|
_rowsLeft = qFloor(_columnSkip / 2);
|
|
|
|
_rowWidth = qFloor(_rowWidthReal);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::changeCheckState(Chat *chat) {
|
2016-09-06 14:45:10 +00:00
|
|
|
if (!chat) return;
|
|
|
|
|
|
|
|
if (!_filter.isEmpty()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
const auto history = chat->peer->owner().history(chat->peer);
|
2018-01-04 17:15:04 +00:00
|
|
|
auto row = _chatsIndexed->getRow(history);
|
2016-09-06 14:45:10 +00:00
|
|
|
if (!row) {
|
2020-02-07 09:43:12 +00:00
|
|
|
row = _chatsIndexed->addToEnd(history).main;
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
|
|
|
chat = getChat(row);
|
2016-10-20 13:41:46 +00:00
|
|
|
if (!chat->checkbox.checked()) {
|
2018-01-04 17:15:04 +00:00
|
|
|
_chatsIndexed->moveToTop(history);
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-22 13:03:20 +00:00
|
|
|
changePeerCheckState(chat, !chat->checkbox.checked());
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void ShareBox::Inner::peerUnselected(not_null<PeerData*> peer) {
|
2018-11-04 07:32:26 +00:00
|
|
|
if (const auto i = _dataMap.find(peer); i != end(_dataMap)) {
|
|
|
|
changePeerCheckState(
|
|
|
|
i->second.get(),
|
|
|
|
false,
|
|
|
|
ChangeStateWay::SkipCallback);
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2016-10-22 13:03:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::Inner::setPeerSelectedChangedCallback(
|
|
|
|
Fn<void(PeerData *peer, bool selected)> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_peerSelectedChangedCallback = std::move(callback);
|
2016-10-22 13:03:20 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void ShareBox::Inner::changePeerCheckState(
|
|
|
|
not_null<Chat*> chat,
|
|
|
|
bool checked,
|
|
|
|
ChangeStateWay useCallback) {
|
|
|
|
chat->checkbox.setChecked(checked);
|
2016-10-22 13:03:20 +00:00
|
|
|
if (checked) {
|
2016-09-06 12:28:37 +00:00
|
|
|
_selected.insert(chat->peer);
|
2016-10-20 11:34:48 +00:00
|
|
|
setActive(chatIndex(chat->peer));
|
2016-09-06 12:28:37 +00:00
|
|
|
} else {
|
|
|
|
_selected.remove(chat->peer);
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
2017-12-05 14:07:01 +00:00
|
|
|
if (useCallback != ChangeStateWay::SkipCallback
|
|
|
|
&& _peerSelectedChangedCallback) {
|
2016-10-22 13:03:20 +00:00
|
|
|
_peerSelectedChangedCallback(chat->peer, checked);
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
bool ShareBox::Inner::hasSelected() const {
|
2016-09-06 12:28:37 +00:00
|
|
|
return _selected.size();
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::updateFilter(QString filter) {
|
2016-09-06 12:28:37 +00:00
|
|
|
_lastQuery = filter.toLower().trimmed();
|
2017-07-06 11:37:42 +00:00
|
|
|
|
|
|
|
auto words = TextUtilities::PrepareSearchWords(_lastQuery);
|
|
|
|
filter = words.isEmpty() ? QString() : words.join(' ');
|
2016-09-06 12:28:37 +00:00
|
|
|
if (_filter != filter) {
|
|
|
|
_filter = filter;
|
|
|
|
|
|
|
|
_byUsernameFiltered.clear();
|
2016-09-06 14:45:10 +00:00
|
|
|
d_byUsernameFiltered.clear();
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
if (_filter.isEmpty()) {
|
|
|
|
refresh();
|
|
|
|
} else {
|
2019-04-22 18:18:57 +00:00
|
|
|
_filtered = _chatsIndexed->filtered(words);
|
2016-09-06 12:28:37 +00:00
|
|
|
refresh();
|
|
|
|
|
|
|
|
_searching = true;
|
2018-11-04 07:32:26 +00:00
|
|
|
_searchRequests.fire({});
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2016-09-06 14:45:10 +00:00
|
|
|
setActive(-1);
|
2016-09-06 12:28:37 +00:00
|
|
|
update();
|
|
|
|
loadProfilePhotos(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
rpl::producer<Ui::ScrollToRequest> ShareBox::Inner::scrollToRequests() const {
|
|
|
|
return _scrollToRequests.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ShareBox::Inner::searchRequests() const {
|
|
|
|
return _searchRequests.events();
|
|
|
|
}
|
|
|
|
|
2018-01-22 10:58:11 +00:00
|
|
|
void ShareBox::Inner::peopleReceived(
|
|
|
|
const QString &query,
|
|
|
|
const QVector<MTPPeer> &my,
|
|
|
|
const QVector<MTPPeer> &people) {
|
2016-09-06 12:28:37 +00:00
|
|
|
_lastQuery = query.toLower().trimmed();
|
2018-03-09 18:13:47 +00:00
|
|
|
if (_lastQuery.at(0) == '@') {
|
|
|
|
_lastQuery = _lastQuery.mid(1);
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
int32 already = _byUsernameFiltered.size();
|
2018-01-22 10:58:11 +00:00
|
|
|
_byUsernameFiltered.reserve(already + my.size() + people.size());
|
|
|
|
d_byUsernameFiltered.reserve(already + my.size() + people.size());
|
|
|
|
const auto feedList = [&](const QVector<MTPPeer> &list) {
|
2018-11-04 07:32:26 +00:00
|
|
|
for (const auto &data : list) {
|
2021-03-10 17:36:21 +00:00
|
|
|
if (const auto peer = _descriptor.session->data().peerLoaded(
|
|
|
|
peerFromMTP(data))) {
|
|
|
|
const auto history = _descriptor.session->data().historyLoaded(peer);
|
|
|
|
if (!_descriptor.filterCallback(peer)) {
|
2018-01-22 10:58:11 +00:00
|
|
|
continue;
|
|
|
|
} else if (history && _chatsIndexed->getRow(history)) {
|
|
|
|
continue;
|
|
|
|
} else if (base::contains(_byUsernameFiltered, peer)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_byUsernameFiltered.push_back(peer);
|
2018-11-04 07:32:26 +00:00
|
|
|
d_byUsernameFiltered.push_back(std::make_unique<Chat>(
|
|
|
|
peer,
|
2021-03-10 17:36:21 +00:00
|
|
|
_st.item,
|
2018-11-04 07:32:26 +00:00
|
|
|
[=] { repaintChat(peer); }));
|
|
|
|
updateChatName(d_byUsernameFiltered.back().get(), peer);
|
2016-09-06 14:45:10 +00:00
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2018-01-22 10:58:11 +00:00
|
|
|
};
|
|
|
|
feedList(my);
|
|
|
|
feedList(people);
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
_searching = false;
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::refresh() {
|
2016-09-06 14:45:10 +00:00
|
|
|
auto count = displayedChatsCount();
|
|
|
|
if (count) {
|
|
|
|
auto rows = (count / _columnCount) + (count % _columnCount ? 1 : 0);
|
|
|
|
resize(width(), _rowsTop + rows * _rowHeight);
|
2016-09-06 12:28:37 +00:00
|
|
|
} else {
|
2016-09-06 14:45:10 +00:00
|
|
|
resize(width(), st::noContactsHeight);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-09-13 06:06:02 +00:00
|
|
|
std::vector<not_null<PeerData*>> ShareBox::Inner::selected() const {
|
|
|
|
auto result = std::vector<not_null<PeerData*>>();
|
2016-09-06 14:45:10 +00:00
|
|
|
result.reserve(_dataMap.size());
|
2018-11-04 07:32:26 +00:00
|
|
|
for (const auto &[peer, chat] : _dataMap) {
|
2016-10-20 13:41:46 +00:00
|
|
|
if (chat->checkbox.checked()) {
|
2018-11-04 07:32:26 +00:00
|
|
|
result.push_back(peer);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
QString AppendShareGameScoreUrl(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &url,
|
|
|
|
const FullMsgId &fullId) {
|
2021-04-01 21:04:10 +00:00
|
|
|
auto shareHashData = QByteArray(0x20, Qt::Uninitialized);
|
|
|
|
auto shareHashDataInts = reinterpret_cast<uint64*>(shareHashData.data());
|
2021-12-09 07:32:54 +00:00
|
|
|
const auto peer = fullId.peer
|
|
|
|
? session->data().peerLoaded(fullId.peer)
|
|
|
|
: static_cast<PeerData*>(nullptr);
|
|
|
|
const auto channelAccessHash = uint64((peer && peer->isChannel())
|
|
|
|
? peer->asChannel()->access
|
|
|
|
: 0);
|
2021-04-01 21:04:10 +00:00
|
|
|
shareHashDataInts[0] = session->userId().bare;
|
2021-12-09 07:32:54 +00:00
|
|
|
shareHashDataInts[1] = fullId.peer.value;
|
2021-09-30 06:04:55 +00:00
|
|
|
shareHashDataInts[2] = uint64(fullId.msg.bare);
|
2021-04-01 21:04:10 +00:00
|
|
|
shareHashDataInts[3] = channelAccessHash;
|
2016-09-30 12:52:03 +00:00
|
|
|
|
|
|
|
// Count SHA1() of data.
|
2016-09-07 09:04:57 +00:00
|
|
|
auto key128Size = 0x10;
|
|
|
|
auto shareHashEncrypted = QByteArray(key128Size + shareHashData.size(), Qt::Uninitialized);
|
|
|
|
hashSha1(shareHashData.constData(), shareHashData.size(), shareHashEncrypted.data());
|
2016-09-30 12:52:03 +00:00
|
|
|
|
2021-04-01 21:04:10 +00:00
|
|
|
//// Mix in channel access hash to the first 64 bits of SHA1 of data.
|
|
|
|
//*reinterpret_cast<uint64*>(shareHashEncrypted.data()) ^= channelAccessHash;
|
2016-09-30 12:52:03 +00:00
|
|
|
|
|
|
|
// Encrypt data.
|
2020-06-09 16:57:05 +00:00
|
|
|
if (!session->local().encrypt(shareHashData.constData(), shareHashEncrypted.data() + key128Size, shareHashData.size(), shareHashEncrypted.constData())) {
|
2016-09-07 09:04:57 +00:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto shareHash = shareHashEncrypted.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
|
|
|
auto shareUrl = qsl("tg://share_game_score?hash=") + QString::fromLatin1(shareHash);
|
|
|
|
|
|
|
|
auto shareComponent = qsl("tgShareScoreUrl=") + qthelp::url_encode(shareUrl);
|
|
|
|
|
|
|
|
auto hashPosition = url.indexOf('#');
|
|
|
|
if (hashPosition < 0) {
|
|
|
|
return url + '#' + shareComponent;
|
|
|
|
}
|
|
|
|
auto hash = url.mid(hashPosition + 1);
|
|
|
|
if (hash.indexOf('=') >= 0 || hash.indexOf('?') >= 0) {
|
|
|
|
return url + '&' + shareComponent;
|
|
|
|
}
|
|
|
|
if (!hash.isEmpty()) {
|
|
|
|
return url + '?' + shareComponent;
|
|
|
|
}
|
|
|
|
return url + shareComponent;
|
|
|
|
}
|
|
|
|
|
2022-02-23 07:37:59 +00:00
|
|
|
void FastShareMessage(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<HistoryItem*> item) {
|
2022-02-23 07:25:46 +00:00
|
|
|
struct ShareData {
|
|
|
|
ShareData(not_null<PeerData*> peer, MessageIdsList &&ids)
|
|
|
|
: peer(peer)
|
|
|
|
, msgIds(std::move(ids)) {
|
|
|
|
}
|
|
|
|
not_null<PeerData*> peer;
|
|
|
|
MessageIdsList msgIds;
|
|
|
|
base::flat_set<mtpRequestId> requests;
|
|
|
|
};
|
2022-02-23 07:37:59 +00:00
|
|
|
const auto show = std::make_shared<Window::Show>(controller);
|
2022-02-23 07:25:46 +00:00
|
|
|
const auto history = item->history();
|
|
|
|
const auto owner = &history->owner();
|
|
|
|
const auto session = &history->session();
|
|
|
|
const auto data = std::make_shared<ShareData>(
|
|
|
|
history->peer,
|
|
|
|
owner->itemOrItsGroup(item));
|
|
|
|
const auto isGame = item->getMessageBot()
|
|
|
|
&& item->media()
|
|
|
|
&& (item->media()->game() != nullptr);
|
|
|
|
const auto canCopyLink = item->hasDirectLink() || isGame;
|
|
|
|
|
|
|
|
const auto items = owner->idsToItems(data->msgIds);
|
|
|
|
const auto hasCaptions = ranges::any_of(items, [](auto item) {
|
|
|
|
return item->media()
|
|
|
|
&& !item->originalText().text.isEmpty()
|
|
|
|
&& item->media()->allowsEditCaption();
|
|
|
|
});
|
|
|
|
const auto hasOnlyForcedForwardedInfo = hasCaptions
|
|
|
|
? false
|
|
|
|
: ranges::all_of(items, [](auto item) {
|
|
|
|
return item->media() && item->media()->forceForwardedInfo();
|
|
|
|
});
|
|
|
|
|
2022-02-23 07:37:59 +00:00
|
|
|
auto copyCallback = [=, toastParent = show->toastParent()] {
|
|
|
|
const auto item = owner->message(data->msgIds[0]);
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (item->hasDirectLink()) {
|
|
|
|
using namespace HistoryView;
|
2022-06-14 10:38:06 +00:00
|
|
|
CopyPostLink(controller, item->fullId(), Context::History);
|
2022-02-23 07:37:59 +00:00
|
|
|
} else if (const auto bot = item->getMessageBot()) {
|
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto game = media->game()) {
|
|
|
|
const auto link = session->createInternalLinkFull(
|
|
|
|
bot->username + qsl("?game=") + game->shortName);
|
|
|
|
|
|
|
|
QGuiApplication::clipboard()->setText(link);
|
|
|
|
|
|
|
|
Ui::Toast::Show(
|
|
|
|
toastParent,
|
|
|
|
tr::lng_share_game_link_copied(tr::now));
|
2022-02-23 07:25:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-02-23 07:37:59 +00:00
|
|
|
|
2022-02-23 07:25:46 +00:00
|
|
|
auto submitCallback = [=](
|
|
|
|
std::vector<not_null<PeerData*>> &&result,
|
|
|
|
TextWithTags &&comment,
|
|
|
|
Api::SendOptions options,
|
|
|
|
Data::ForwardOptions forwardOptions) {
|
|
|
|
if (!data->requests.empty()) {
|
|
|
|
return; // Share clicked already.
|
|
|
|
}
|
|
|
|
auto items = history->owner().idsToItems(data->msgIds);
|
|
|
|
if (items.empty() || result.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto error = [&] {
|
|
|
|
for (const auto peer : result) {
|
|
|
|
const auto error = GetErrorTextForSending(
|
|
|
|
peer,
|
|
|
|
items,
|
|
|
|
comment);
|
|
|
|
if (!error.isEmpty()) {
|
|
|
|
return std::make_pair(error, peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::make_pair(QString(), result.front());
|
|
|
|
}();
|
|
|
|
if (!error.first.isEmpty()) {
|
|
|
|
auto text = TextWithEntities();
|
|
|
|
if (result.size() > 1) {
|
|
|
|
text.append(
|
|
|
|
Ui::Text::Bold(error.second->name)
|
|
|
|
).append("\n\n");
|
|
|
|
}
|
|
|
|
text.append(error.first);
|
2022-02-23 07:37:59 +00:00
|
|
|
show->showBox(
|
2022-02-23 07:25:46 +00:00
|
|
|
Ui::MakeInformBox(text),
|
|
|
|
Ui::LayerOption::KeepOther);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto commonSendFlags = MTPmessages_ForwardMessages::Flag(0)
|
|
|
|
| MTPmessages_ForwardMessages::Flag::f_with_my_score
|
|
|
|
| (options.scheduled
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_schedule_date
|
|
|
|
: MTPmessages_ForwardMessages::Flag(0))
|
|
|
|
| ((forwardOptions != Data::ForwardOptions::PreserveInfo)
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_drop_author
|
|
|
|
: MTPmessages_ForwardMessages::Flag(0))
|
|
|
|
| ((forwardOptions == Data::ForwardOptions::NoNamesAndCaptions)
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_drop_media_captions
|
|
|
|
: MTPmessages_ForwardMessages::Flag(0));
|
|
|
|
auto msgIds = QVector<MTPint>();
|
|
|
|
msgIds.reserve(data->msgIds.size());
|
|
|
|
for (const auto &fullId : data->msgIds) {
|
|
|
|
msgIds.push_back(MTP_int(fullId.msg));
|
|
|
|
}
|
|
|
|
const auto generateRandom = [&] {
|
|
|
|
auto result = QVector<MTPlong>(data->msgIds.size());
|
|
|
|
for (auto &value : result) {
|
|
|
|
value = base::RandomValue<MTPlong>();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
auto &api = owner->session().api();
|
|
|
|
auto &histories = owner->histories();
|
|
|
|
const auto requestType = Data::Histories::RequestType::Send;
|
|
|
|
for (const auto peer : result) {
|
|
|
|
const auto history = owner->history(peer);
|
|
|
|
if (!comment.text.isEmpty()) {
|
|
|
|
auto message = Api::MessageToSend(
|
|
|
|
Api::SendAction(history, options));
|
|
|
|
message.textWithTags = comment;
|
|
|
|
message.action.clearDraft = false;
|
|
|
|
api.sendMessage(std::move(message));
|
|
|
|
}
|
|
|
|
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
|
|
|
|
auto &api = history->session().api();
|
|
|
|
const auto sendFlags = commonSendFlags
|
|
|
|
| (ShouldSendSilent(peer, options)
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_silent
|
|
|
|
: MTPmessages_ForwardMessages::Flag(0));
|
2022-02-23 07:37:59 +00:00
|
|
|
history->sendRequestId = api.request(
|
|
|
|
MTPmessages_ForwardMessages(
|
|
|
|
MTP_flags(sendFlags),
|
|
|
|
data->peer->input,
|
|
|
|
MTP_vector<MTPint>(msgIds),
|
|
|
|
MTP_vector<MTPlong>(generateRandom()),
|
|
|
|
peer->input,
|
|
|
|
MTP_int(options.scheduled),
|
|
|
|
MTP_inputPeerEmpty() // send_as
|
|
|
|
)).done([=](const MTPUpdates &updates, mtpRequestId reqId) {
|
2022-02-23 07:25:46 +00:00
|
|
|
history->session().api().applyUpdates(updates);
|
2022-02-23 07:37:59 +00:00
|
|
|
data->requests.remove(reqId);
|
2022-02-23 07:25:46 +00:00
|
|
|
if (data->requests.empty()) {
|
2022-02-23 07:37:59 +00:00
|
|
|
if (show->valid()) {
|
|
|
|
Ui::Toast::Show(
|
|
|
|
show->toastParent(),
|
|
|
|
tr::lng_share_done(tr::now));
|
|
|
|
show->hideLayer();
|
|
|
|
}
|
2022-02-23 07:25:46 +00:00
|
|
|
}
|
|
|
|
finish();
|
|
|
|
}).fail([=] {
|
|
|
|
finish();
|
|
|
|
}).afterRequest(history->sendRequestId).send();
|
|
|
|
return history->sendRequestId;
|
|
|
|
});
|
|
|
|
data->requests.insert(history->sendRequestId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto filterCallback = [isGame](PeerData *peer) {
|
|
|
|
if (peer->canWrite()) {
|
|
|
|
if (auto channel = peer->asChannel()) {
|
|
|
|
return isGame ? (!channel->isBroadcast()) : true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
auto copyLinkCallback = canCopyLink
|
|
|
|
? Fn<void()>(std::move(copyCallback))
|
|
|
|
: Fn<void()>();
|
2022-02-23 07:37:59 +00:00
|
|
|
controller->show(
|
|
|
|
Box<ShareBox>(ShareBox::Descriptor{
|
|
|
|
.session = session,
|
|
|
|
.copyCallback = std::move(copyLinkCallback),
|
|
|
|
.submitCallback = std::move(submitCallback),
|
|
|
|
.filterCallback = std::move(filterCallback),
|
|
|
|
.forwardOptions = {
|
|
|
|
.messagesCount = int(data->msgIds.size()),
|
|
|
|
.show = !hasOnlyForcedForwardedInfo,
|
|
|
|
.hasCaptions = hasCaptions,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2022-02-23 07:25:46 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
void ShareGameScoreByHash(
|
2022-02-23 06:59:51 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2019-07-25 18:55:11 +00:00
|
|
|
const QString &hash) {
|
2022-02-23 06:59:51 +00:00
|
|
|
auto &session = controller->session();
|
2016-09-07 09:04:57 +00:00
|
|
|
auto key128Size = 0x10;
|
|
|
|
|
|
|
|
auto hashEncrypted = QByteArray::fromBase64(hash.toLatin1(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
2021-04-01 21:04:10 +00:00
|
|
|
if (hashEncrypted.size() <= key128Size || (hashEncrypted.size() != key128Size + 0x20)) {
|
2022-02-23 06:59:51 +00:00
|
|
|
controller->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_confirm_phone_link_invalid()),
|
2022-02-23 06:59:51 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2016-09-07 09:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
// Decrypt data.
|
2016-09-07 09:04:57 +00:00
|
|
|
auto hashData = QByteArray(hashEncrypted.size() - key128Size, Qt::Uninitialized);
|
2022-02-23 06:59:51 +00:00
|
|
|
if (!session.local().decrypt(hashEncrypted.constData() + key128Size, hashData.data(), hashEncrypted.size() - key128Size, hashEncrypted.constData())) {
|
2016-09-07 09:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
// Count SHA1() of data.
|
|
|
|
char dataSha1[20] = { 0 };
|
|
|
|
hashSha1(hashData.constData(), hashData.size(), dataSha1);
|
|
|
|
|
2021-04-01 21:04:10 +00:00
|
|
|
//// Mix out channel access hash from the first 64 bits of SHA1 of data.
|
|
|
|
//auto channelAccessHash = *reinterpret_cast<uint64*>(hashEncrypted.data()) ^ *reinterpret_cast<uint64*>(dataSha1);
|
2016-09-30 12:52:03 +00:00
|
|
|
|
2021-04-01 21:04:10 +00:00
|
|
|
//// Check next 64 bits of SHA1() of data.
|
|
|
|
//auto skipSha1Part = sizeof(channelAccessHash);
|
|
|
|
//if (memcmp(dataSha1 + skipSha1Part, hashEncrypted.constData() + skipSha1Part, key128Size - skipSha1Part) != 0) {
|
2021-10-18 22:28:08 +00:00
|
|
|
// Ui::show(Box<Ui::InformBox>(tr::lng_share_wrong_user(tr::now)));
|
2021-04-01 21:04:10 +00:00
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
|
|
|
|
// Check 128 bits of SHA1() of data.
|
|
|
|
if (memcmp(dataSha1, hashEncrypted.constData(), key128Size) != 0) {
|
2022-02-23 06:59:51 +00:00
|
|
|
controller->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_share_wrong_user()),
|
2022-02-23 06:59:51 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2016-09-30 12:52:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-01 21:04:10 +00:00
|
|
|
auto hashDataInts = reinterpret_cast<uint64*>(hashData.data());
|
2022-02-23 06:59:51 +00:00
|
|
|
if (hashDataInts[0] != session.userId().bare) {
|
|
|
|
controller->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_share_wrong_user()),
|
2022-02-23 06:59:51 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2016-09-07 09:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
|
2021-12-09 07:32:54 +00:00
|
|
|
const auto peerId = PeerId(hashDataInts[1]);
|
|
|
|
const auto channelAccessHash = hashDataInts[3];
|
|
|
|
if (!peerIsChannel(peerId) && channelAccessHash) {
|
2016-09-30 12:52:03 +00:00
|
|
|
// If there is no channel id, there should be no channel access_hash.
|
2022-02-23 06:59:51 +00:00
|
|
|
controller->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_share_wrong_user()),
|
2022-02-23 06:59:51 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2016-09-07 09:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-09 07:32:54 +00:00
|
|
|
const auto msgId = MsgId(int64(hashDataInts[2]));
|
2022-02-23 06:59:51 +00:00
|
|
|
if (const auto item = session.data().message(peerId, msgId)) {
|
2022-02-23 07:37:59 +00:00
|
|
|
FastShareMessage(controller, item);
|
2017-08-04 14:54:32 +00:00
|
|
|
} else {
|
2022-02-23 06:59:51 +00:00
|
|
|
const auto weak = base::make_weak(controller.get());
|
|
|
|
const auto resolveMessageAndShareScore = crl::guard(weak, [=](
|
|
|
|
PeerData *peer) {
|
|
|
|
auto done = crl::guard(weak, [=] {
|
|
|
|
const auto item = weak->session().data().message(
|
|
|
|
peerId,
|
|
|
|
msgId);
|
2021-12-09 07:32:54 +00:00
|
|
|
if (item) {
|
2022-02-23 07:37:59 +00:00
|
|
|
FastShareMessage(weak.get(), item);
|
2016-09-26 12:09:59 +00:00
|
|
|
} else {
|
2022-02-23 06:59:51 +00:00
|
|
|
weak->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_edit_deleted()),
|
2022-02-23 06:59:51 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2016-09-26 12:09:59 +00:00
|
|
|
}
|
|
|
|
});
|
2022-02-23 06:59:51 +00:00
|
|
|
auto &api = weak->session().api();
|
|
|
|
api.requestMessageData(peer, msgId, std::move(done));
|
|
|
|
});
|
2016-09-30 12:52:03 +00:00
|
|
|
|
2021-12-09 07:32:54 +00:00
|
|
|
const auto peer = peerIsChannel(peerId)
|
2022-02-23 06:59:51 +00:00
|
|
|
? controller->session().data().peerLoaded(peerId)
|
2019-01-18 12:27:37 +00:00
|
|
|
: nullptr;
|
2021-12-09 07:32:54 +00:00
|
|
|
if (peer || !peerIsChannel(peerId)) {
|
|
|
|
resolveMessageAndShareScore(peer);
|
2016-09-30 12:52:03 +00:00
|
|
|
} else {
|
2022-02-23 06:59:51 +00:00
|
|
|
const auto owner = &controller->session().data();
|
|
|
|
controller->session().api().request(MTPchannels_GetChannels(
|
2019-07-25 18:55:11 +00:00
|
|
|
MTP_vector<MTPInputChannel>(
|
|
|
|
1,
|
|
|
|
MTP_inputChannel(
|
2021-12-09 07:32:54 +00:00
|
|
|
MTP_long(peerToChannel(peerId).bare),
|
2019-07-25 18:55:11 +00:00
|
|
|
MTP_long(channelAccessHash)))
|
|
|
|
)).done([=](const MTPmessages_Chats &result) {
|
|
|
|
result.match([&](const auto &data) {
|
2022-02-23 06:59:51 +00:00
|
|
|
owner->processChats(data.vchats());
|
2019-01-13 08:03:34 +00:00
|
|
|
});
|
2022-02-23 06:59:51 +00:00
|
|
|
if (const auto peer = owner->peerLoaded(peerId)) {
|
2021-12-09 07:32:54 +00:00
|
|
|
resolveMessageAndShareScore(peer);
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
2019-07-25 18:55:11 +00:00
|
|
|
}).send();
|
2016-09-07 09:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|