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
|
|
|
|
|
|
|
#include "dialogs/dialogs_indexed_list.h"
|
|
|
|
#include "observer_peer.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-09-06 12:28:37 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "mainwidget.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/qthelp_url.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2016-09-07 09:04:57 +00:00
|
|
|
#include "apiwrap.h"
|
2016-09-19 10:18:21 +00:00
|
|
|
#include "ui/toast/toast.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"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2018-11-04 07:32:26 +00:00
|
|
|
#include "chat_helpers/message_field.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"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme.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"
|
|
|
|
#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"
|
2017-02-23 09:32:28 +00:00
|
|
|
#include "auth_session.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2018-11-04 07:32:26 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_history.h"
|
|
|
|
|
|
|
|
|
|
|
|
class ShareBox::Inner
|
|
|
|
: public Ui::RpWidget
|
|
|
|
, public RPCSender
|
|
|
|
, private base::Subscriber {
|
|
|
|
public:
|
|
|
|
Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallback);
|
|
|
|
|
|
|
|
void setPeerSelectedChangedCallback(
|
|
|
|
Fn<void(PeerData *peer, bool selected)> callback);
|
|
|
|
void peerUnselected(not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
QVector<PeerData*> selected() const;
|
|
|
|
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;
|
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Chat {
|
|
|
|
Chat(PeerData *peer, Fn<void()> updateCallback);
|
|
|
|
|
|
|
|
PeerData *peer;
|
|
|
|
Ui::RoundImageCheckbox checkbox;
|
|
|
|
Text name;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple nameActive;
|
2018-11-04 07:32:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
|
|
|
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();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
ShareBox::FilterCallback _filterCallback;
|
|
|
|
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;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
ShareBox::ShareBox(
|
|
|
|
QWidget*,
|
|
|
|
CopyCallback &©Callback,
|
|
|
|
SubmitCallback &&submitCallback,
|
|
|
|
FilterCallback &&filterCallback)
|
2017-02-21 13:45:56 +00:00
|
|
|
: _copyCallback(std::move(copyCallback))
|
|
|
|
, _submitCallback(std::move(submitCallback))
|
|
|
|
, _filterCallback(std::move(filterCallback))
|
2018-11-04 07:32:26 +00:00
|
|
|
, _select(
|
|
|
|
this,
|
|
|
|
st::contactsMultiSelect,
|
|
|
|
langFactory(lng_participant_filter))
|
|
|
|
, _comment(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::InputField>(
|
|
|
|
this,
|
|
|
|
st::shareComment,
|
|
|
|
Ui::InputField::Mode::MultiLine,
|
|
|
|
langFactory(lng_photos_comment)),
|
|
|
|
st::shareCommentPadding)
|
|
|
|
, _searchTimer([=] { searchByUsername(); }) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareBox::prepareCommentField() {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
_comment->hide(anim::type::instant);
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
heightValue(),
|
|
|
|
_comment->heightValue(),
|
|
|
|
_1 - _2
|
|
|
|
) | rpl::start_with_next([=](int top) {
|
|
|
|
_comment->moveToLeft(0, top);
|
|
|
|
}, _comment->lifetime());
|
|
|
|
|
|
|
|
const auto field = _comment->entity();
|
|
|
|
|
|
|
|
connect(field, &Ui::InputField::submitted, [=] {
|
|
|
|
submit();
|
|
|
|
});
|
|
|
|
|
|
|
|
field->setInstantReplaces(Ui::InstantReplaces::Default());
|
|
|
|
field->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
|
|
|
|
field->setMarkdownReplacesEnabled(rpl::single(true));
|
|
|
|
field->setEditLinkCallback(DefaultEditLinkCallback(field));
|
|
|
|
|
|
|
|
Ui::SendPendingMoveResizeEvents(_comment);
|
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
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(lng_share_title));
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
_inner = setInnerWidget(
|
|
|
|
object_ptr<Inner>(
|
|
|
|
this,
|
|
|
|
std::move(_filterCallback)),
|
|
|
|
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) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto peer = Auth().data().peerLoaded(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)) {
|
2018-11-04 07:32:26 +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
|
|
|
}
|
|
|
|
});
|
2018-11-04 07:32:26 +00:00
|
|
|
_comment->heightValue(
|
|
|
|
) | 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(),
|
|
|
|
_comment->entity());
|
|
|
|
|
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 {
|
|
|
|
return _comment->isHidden() ? 0 : _comment->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
peopleReceived(i.value(), 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (_peopleQuery != query) {
|
|
|
|
_peopleQuery = query;
|
|
|
|
_peopleFull = false;
|
2018-01-22 10:58:11 +00:00
|
|
|
_peopleRequest = MTP::send(
|
|
|
|
MTPcontacts_Search(
|
|
|
|
MTP_string(_peopleQuery),
|
|
|
|
MTP_int(SearchPeopleLimit)),
|
|
|
|
rpcDone(&ShareBox::peopleReceived),
|
|
|
|
rpcFail(&ShareBox::peopleFailed));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 10:58:11 +00:00
|
|
|
void ShareBox::peopleReceived(
|
|
|
|
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();
|
2019-01-18 12:27:37 +00:00
|
|
|
Auth().data().processUsers(found.vusers);
|
|
|
|
Auth().data().processChats(found.vchats);
|
2018-01-22 10:58:11 +00:00
|
|
|
_inner->peopleReceived(
|
|
|
|
query,
|
|
|
|
found.vmy_results.v,
|
|
|
|
found.vresults.v);
|
2016-09-06 12:28:37 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_peopleRequest = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShareBox::peopleFailed(const RPCError &error, mtpRequestId requestId) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
|
|
|
if (_peopleRequest == requestId) {
|
|
|
|
_peopleRequest = 0;
|
|
|
|
_peopleFull = true;
|
|
|
|
}
|
|
|
|
return 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ShareBox::createButtons() {
|
|
|
|
clearButtons();
|
|
|
|
if (_hasSelected) {
|
2018-11-04 07:32:26 +00:00
|
|
|
addButton(langFactory(lng_share_confirm), [=] { submit(); });
|
2017-07-11 17:11:06 +00:00
|
|
|
} else if (_copyCallback) {
|
2018-11-04 07:32:26 +00:00
|
|
|
addButton(langFactory(lng_share_copy_link), [=] { copyLink(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2018-11-04 07:32:26 +00:00
|
|
|
addButton(langFactory(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) {
|
2016-12-13 17:07:56 +00:00
|
|
|
onScrollToY(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(
|
|
|
|
peer->id,
|
|
|
|
peer->isSelf() ? lang(lng_saved_short) : peer->shortName(),
|
|
|
|
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 {
|
|
|
|
_select->removeItem(peer->id);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::submit() {
|
2016-09-19 10:18:21 +00:00
|
|
|
if (_submitCallback) {
|
2018-11-04 07:32:26 +00:00
|
|
|
_submitCallback(
|
|
|
|
_inner->selected(),
|
|
|
|
_comment->entity()->getTextWithAppliedMarkdown());
|
2016-09-19 10:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
void ShareBox::copyLink() {
|
2016-09-19 10:18:21 +00:00
|
|
|
if (_copyCallback) {
|
|
|
|
_copyCallback();
|
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) {
|
|
|
|
onScrollToY(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
|
|
|
}
|
|
|
|
|
2018-11-04 07:32:26 +00:00
|
|
|
ShareBox::Inner::Inner(
|
|
|
|
QWidget *parent,
|
|
|
|
ShareBox::FilterCallback &&filterCallback)
|
|
|
|
: RpWidget(parent)
|
2017-02-21 13:45:56 +00:00
|
|
|
, _filterCallback(std::move(filterCallback))
|
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);
|
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
const auto self = Auth().user();
|
|
|
|
if (_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) {
|
|
|
|
for (const auto row : list->all()) {
|
|
|
|
if (const auto history = row->history()) {
|
|
|
|
if (!history->peer->isSelf()
|
|
|
|
&& _filterCallback(history->peer)) {
|
|
|
|
_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
|
|
|
};
|
|
|
|
addList(Auth().data().chatsList()->indexed());
|
|
|
|
const auto id = Data::Folder::kId;
|
|
|
|
if (const auto folder = Auth().data().folderLoaded(id)) {
|
|
|
|
addList(folder->chatsList()->indexed());
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2019-04-22 18:18:57 +00:00
|
|
|
addList(Auth().data().contactsNoChatsList());
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
_filter = qsl("a");
|
|
|
|
updateFilter();
|
|
|
|
|
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
auto observeEvents = UpdateFlag::NameChanged | UpdateFlag::PhotoChanged;
|
2016-09-26 18:33:34 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
2016-09-26 13:57:08 +00:00
|
|
|
notifyPeerUpdated(update);
|
2016-09-26 18:33:34 +00:00
|
|
|
}));
|
2017-08-04 14:54:32 +00:00
|
|
|
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
|
2016-12-20 13:03:51 +00:00
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
|
2016-12-23 13:21:01 +00:00
|
|
|
if (update.paletteChanged()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
invalidateCache();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void ShareBox::Inner::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
2016-09-06 12:28:37 +00:00
|
|
|
if (update.flags & Notify::PeerUpdate::Flag::NameChanged) {
|
2018-01-04 17:15:04 +00:00
|
|
|
_chatsIndexed->peerNameChanged(
|
|
|
|
update.peer,
|
2018-01-22 09:33:09 +00:00
|
|
|
update.oldNameFirstLetters);
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateChat(update.peer);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
const auto text = peer->isSelf() ? lang(lng_saved_messages) : peer->name;
|
2017-12-28 13:06:06 +00:00
|
|
|
chat->name.setText(st::shareNameStyle, 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;
|
|
|
|
update(rtlrect(_rowsLeft + qFloor(column * _rowWidthReal), row * _rowHeight, _rowWidth, _rowHeight, width()));
|
|
|
|
}
|
|
|
|
|
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()) {
|
2018-01-22 09:33:09 +00:00
|
|
|
for (const auto row : _chatsIndexed->all()) {
|
|
|
|
if (const auto history = row->history()) {
|
|
|
|
if (history->peer == peer) {
|
|
|
|
return index;
|
|
|
|
}
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
} else {
|
2018-01-22 09:33:09 +00:00
|
|
|
for (const auto row : _filtered) {
|
|
|
|
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;
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().downloader().clearPriorities();
|
2016-09-06 12:28:37 +00:00
|
|
|
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,
|
|
|
|
std::make_unique<Chat>(peer, [=] { repaintChat(peer); }));
|
|
|
|
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();
|
|
|
|
auto photoLeft = (_rowWidth - (st::sharePhotoCheckbox.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.);
|
2016-12-07 13:32:25 +00:00
|
|
|
p.setPen(anim::pen(st::shareNameFg, st::shareNameActiveFg, 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;
|
2016-10-20 11:34:48 +00:00
|
|
|
auto nameTop = photoTop + st::sharePhotoCheckbox.imageRadius * 2 + st::shareNameTop;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
ShareBox::Inner::Chat::Chat(PeerData *peer, Fn<void()> updateCallback)
|
2016-10-20 11:34:48 +00:00
|
|
|
: peer(peer)
|
2017-12-05 14:07:01 +00:00
|
|
|
, checkbox(st::sharePhotoCheckbox, updateCallback, PaintUserpicCallback(peer, true))
|
2016-10-20 11:34:48 +00:00
|
|
|
, name(st::sharePhotoCheckbox.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);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(r, st::boxBg);
|
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);
|
|
|
|
p.setPen(st::noContactsColor);
|
2018-03-09 18:13:47 +00:00
|
|
|
p.drawText(
|
|
|
|
rect().marginsRemoved(st::boxPadding),
|
|
|
|
lang(lng_bot_no_chats),
|
|
|
|
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);
|
|
|
|
p.setPen(st::noContactsColor);
|
2018-03-09 18:13:47 +00:00
|
|
|
p.drawText(
|
|
|
|
rect().marginsRemoved(st::boxPadding),
|
|
|
|
lang(lng_bot_chats_not_found),
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void ShareBox::Inner::enterEventHook(QEvent *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));
|
2016-12-23 13:21:01 +00:00
|
|
|
auto yupon = (y >= top) && (y < top + st::sharePhotoCheckbox.imageRadius * 2 + st::shareNameTop + st::shareNameStyle.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) {
|
2016-10-20 11:34:48 +00:00
|
|
|
_columnSkip = (width() - _columnCount * st::sharePhotoCheckbox.imageRadius * 2) / float64(_columnCount + 1);
|
|
|
|
_rowWidthReal = st::sharePhotoCheckbox.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) {
|
2018-01-04 17:15:04 +00:00
|
|
|
const auto rowsByLetter = _chatsIndexed->addToEnd(history);
|
2018-01-04 09:40:58 +00:00
|
|
|
const auto it = rowsByLetter.find(0);
|
2017-10-24 17:11:35 +00:00
|
|
|
Assert(it != rowsByLetter.cend());
|
|
|
|
row = it->second;
|
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) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(data))) {
|
|
|
|
const auto history = Auth().data().historyLoaded(peer);
|
2018-01-22 10:58:11 +00:00
|
|
|
if (!_filterCallback(peer)) {
|
|
|
|
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,
|
|
|
|
[=] { 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();
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
QVector<PeerData*> ShareBox::Inner::selected() const {
|
2018-11-04 07:32:26 +00:00
|
|
|
auto result = QVector<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;
|
|
|
|
}
|
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) {
|
2016-09-07 09:04:57 +00:00
|
|
|
auto shareHashData = QByteArray(0x10, Qt::Uninitialized);
|
2016-09-30 12:52:03 +00:00
|
|
|
auto shareHashDataInts = reinterpret_cast<int32*>(shareHashData.data());
|
2019-01-18 12:27:37 +00:00
|
|
|
auto channel = fullId.channel
|
|
|
|
? Auth().data().channelLoaded(fullId.channel)
|
|
|
|
: static_cast<ChannelData*>(nullptr);
|
2016-09-30 12:52:03 +00:00
|
|
|
auto channelAccessHash = channel ? channel->access : 0ULL;
|
|
|
|
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
|
2017-08-04 14:54:32 +00:00
|
|
|
shareHashDataInts[0] = Auth().userId();
|
2016-09-30 12:52:03 +00:00
|
|
|
shareHashDataInts[1] = fullId.channel;
|
|
|
|
shareHashDataInts[2] = fullId.msg;
|
|
|
|
shareHashDataInts[3] = channelAccessHashInts[0];
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// Mix in channel access hash to the first 64 bits of SHA1 of data.
|
|
|
|
*reinterpret_cast<uint64*>(shareHashEncrypted.data()) ^= *reinterpret_cast<uint64*>(channelAccessHashInts);
|
|
|
|
|
|
|
|
// Encrypt data.
|
2016-09-07 09:04:57 +00:00
|
|
|
if (!Local::encrypt(shareHashData.constData(), shareHashEncrypted.data() + key128Size, shareHashData.size(), shareHashEncrypted.constData())) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
void ShareGameScoreByHash(const QString &hash) {
|
2016-09-07 09:04:57 +00:00
|
|
|
auto key128Size = 0x10;
|
|
|
|
|
|
|
|
auto hashEncrypted = QByteArray::fromBase64(hash.toLatin1(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
|
|
|
if (hashEncrypted.size() <= key128Size || (hashEncrypted.size() % 0x10) != 0) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_confirm_phone_link_invalid)));
|
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);
|
|
|
|
if (!Local::decrypt(hashEncrypted.constData() + key128Size, hashData.data(), hashEncrypted.size() - key128Size, hashEncrypted.constData())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
// Count SHA1() of data.
|
|
|
|
char dataSha1[20] = { 0 };
|
|
|
|
hashSha1(hashData.constData(), hashData.size(), dataSha1);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// Check next 64 bits of SHA1() of data.
|
|
|
|
auto skipSha1Part = sizeof(channelAccessHash);
|
|
|
|
if (memcmp(dataSha1 + skipSha1Part, hashEncrypted.constData() + skipSha1Part, key128Size - skipSha1Part) != 0) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_share_wrong_user)));
|
2016-09-30 12:52:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto hashDataInts = reinterpret_cast<int32*>(hashData.data());
|
2017-08-04 14:54:32 +00:00
|
|
|
if (!AuthSession::Exists() || hashDataInts[0] != Auth().userId()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_share_wrong_user)));
|
2016-09-07 09:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
|
|
|
|
// Check first 32 bits of channel access hash.
|
|
|
|
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
|
|
|
|
if (channelAccessHashInts[0] != hashDataInts[3]) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_share_wrong_user)));
|
2016-09-30 12:52:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto channelId = hashDataInts[1];
|
|
|
|
auto msgId = hashDataInts[2];
|
|
|
|
if (!channelId && channelAccessHash) {
|
|
|
|
// If there is no channel id, there should be no channel access_hash.
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_share_wrong_user)));
|
2016-09-07 09:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto item = App::histItemById(channelId, msgId)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
FastShareMessage(item);
|
2017-08-04 14:54:32 +00:00
|
|
|
} else {
|
2016-09-30 12:52:03 +00:00
|
|
|
auto resolveMessageAndShareScore = [msgId](ChannelData *channel) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestMessageData(channel, msgId, [](ChannelData *channel, MsgId msgId) {
|
2016-09-26 12:09:59 +00:00
|
|
|
if (auto item = App::histItemById(channel, msgId)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
FastShareMessage(item);
|
2016-09-26 12:09:59 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_edit_deleted)));
|
2016-09-26 12:09:59 +00:00
|
|
|
}
|
|
|
|
});
|
2016-09-30 12:52:03 +00:00
|
|
|
};
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
const auto channel = channelId
|
|
|
|
? Auth().data().channelLoaded(channelId)
|
|
|
|
: nullptr;
|
2016-09-30 12:52:03 +00:00
|
|
|
if (channel || !channelId) {
|
|
|
|
resolveMessageAndShareScore(channel);
|
|
|
|
} else {
|
|
|
|
auto requestChannelIds = MTP_vector<MTPInputChannel>(1, MTP_inputChannel(MTP_int(channelId), MTP_long(channelAccessHash)));
|
|
|
|
auto requestChannel = MTPchannels_GetChannels(requestChannelIds);
|
2019-01-13 08:03:34 +00:00
|
|
|
MTP::send(requestChannel, rpcDone([=](const MTPmessages_Chats &result) {
|
|
|
|
result.match([](const auto &data) {
|
2019-01-18 12:27:37 +00:00
|
|
|
Auth().data().processChats(data.vchats);
|
2019-01-13 08:03:34 +00:00
|
|
|
});
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto channel = Auth().data().channelLoaded(channelId)) {
|
2016-09-30 12:52:03 +00:00
|
|
|
resolveMessageAndShareScore(channel);
|
|
|
|
}
|
|
|
|
}));
|
2016-09-07 09:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|